[Mapbender-commits] r4913 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Nov 3 11:23:05 EST 2009
Author: christoph
Date: 2009-11-03 11:23:04 -0500 (Tue, 03 Nov 2009)
New Revision: 4913
Modified:
trunk/mapbender/http/classes/class_wmc.php
Log:
Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php 2009-11-03 16:22:35 UTC (rev 4912)
+++ trunk/mapbender/http/classes/class_wmc.php 2009-11-03 16:23:04 UTC (rev 4913)
@@ -224,7 +224,96 @@
// DATABASE FUNCTIONS
// ---------------------------------------------------------------------------
+ public function selectByUser ($user) {
+ $wmcArray = array();
+
+ // get WMC ids
+ $wmcIdArray = $user->getWmcByOwner();
+
+ // get WMC data
+ $v = array();
+ $t = array();
+ $wmcIdList = "";
+
+ for ($i = 0; $i < count($wmcIdArray); $i++) {
+ if ($i > 0) {
+ $wmcIdList .= ",";
+ }
+ $wmcIdList .= "$".($i+1);
+ array_push($v, $wmcIdArray[$i]);
+ array_push($t, 's');
+ }
+
+ if ($wmcIdList !== "") {
+ $sql = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp FROM mb_user_wmc ";
+ $sql .= "WHERE wmc_id IN (" . $wmcIdList . ") ";
+ $sql .= "ORDER BY wmc_timestamp DESC";
+
+ $res = db_prep_query($sql, $v, $t);
+ while($row = db_fetch_array($res)){
+ $currentResult = array();
+ $currentResult["id"] = $row["wmc_id"];
+ $currentResult["title"] = administration::convertIncomingString($row["wmc_title"]);
+ $currentResult["timestamp"] = date("M d Y H:i:s", $row["wmc_timestamp"]);
+ array_push($wmcArray, $currentResult);
+ }
+ }
+ return $wmcArray;
+ }
+ public function updateUrlsFromDb () {
+ $query_mbWMSId = "/wmc:ViewContext/wmc:LayerList/wmc:Layer/wmc:Extension/mapbender:wms_id";
+
+ try {
+ $WMCDoc = DOMDocument::loadXML($this->toXml());
+ }
+ catch (Exception $E) {
+ new mb_exception("WMC XML is broken.");
+ }
+
+ $xpath = new DOMXPath($WMCDoc);
+ $xpath->registerNamespace("wmc","http://www.opengis.net/context");
+ $xpath->registerNamespace("mapbender","http://www.mapbender.org/context");
+ $xpath->registerNamespace("xlink","http://www.w3.org/1999/xlink");
+
+ $WMSIdList = $xpath->query($query_mbWMSId);
+ foreach($WMSIdList as $WMSId) {
+ $id = $WMSId->nodeValue;
+ $sql = "SELECT wms_timestamp,wms_getmap,wms_getlegendurl FROM wms WHERE wms_id = $1";
+ $v = array($id);
+ $t = array("t");
+
+ $res = db_prep_query($sql,$v,$t);
+ if (db_error()) {
+ true;
+ } //FIMXE: PROPER ERROR MESSAGE
+
+ if($row = db_fetch_row($res)) {
+ $wms_timestamp = $row[0];
+ if ($this->timestamp < $wms_timestamp) {
+ // wmc is fresh, life is good
+ }
+ else{
+ $MapResources = $xpath->query("../../wmc:Server/wmc:OnlineResource",$WMSId);
+ foreach($MapResources as $MapResource) {
+ $MapResource->setAttribute("xlink:href",$row[1]);
+ }
+
+ $LegendResources = $xpath->query("../../wmc:StyleList/wmc:Style/wmc:LegendURL/wmc:OnlineResource",$WMSId);
+ foreach ($LegendResources as $LegendResource) {
+ $base = $row[2];
+ $origurl = explode('&', $LegendResource->getAttribute("xlink:href"),2);
+ $url = $base . $origurl[1];
+ $LegendResource->setAttribute("xlink:href",$url);
+ }
+ }
+ }
+ }
+ $updatedWMC = $WMCDoc->saveXML();
+ $this->update_existing($updatedWMC,$wmsId);
+ return $updatedWMC;
+ }
+
/**
* Stores this WMC in the database. The WMC has to be instantiated first, see above.
*
More information about the Mapbender_commits
mailing list