[Mapbender-commits] r9069 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Sep 10 09:06:40 PDT 2014


Author: armin11
Date: 2014-09-10 09:06:40 -0700 (Wed, 10 Sep 2014)
New Revision: 9069

Modified:
   trunk/mapbender/http/classes/class_wmc.php
Log:
Exchange DataURL by loading older wmc - problem to solve - insert it at right position cause it is a sequence in xsl!

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2014-09-10 11:58:10 UTC (rev 9068)
+++ trunk/mapbender/http/classes/class_wmc.php	2014-09-10 16:06:40 UTC (rev 9069)
@@ -520,6 +520,8 @@
 
 	/*
 	* function to update the information about wms in a mapbender wmc object and stores it in the database
+	* actually layer names and getmap urls are updated by the given mapbender layer id, also the dataurl entries are created or
+	* if a layer has related metadata for which download options are available
 	* @return WMC as XML or false.
 	*/
 	public function updateUrlsFromDb() {
@@ -567,7 +569,7 @@
 		$v = array();
 		$t = array();
 		$layerIds = array();
-		$sql = "SELECT layer_id, layer_name, fkey_wms_id, wms_timestamp, wms_getmap, wms_getlegendurl, wms_owsproxy FROM layer, wms WHERE layer.fkey_wms_id = wms.wms_id and layer_id in (";
+		$sql = "SELECT layer_id, f_get_download_options_for_layer(layer_id) AS downloadoptions, layer_name, fkey_wms_id, wms_timestamp, wms_getmap, wms_getlegendurl, wms_owsproxy FROM layer, wms WHERE layer.fkey_wms_id = wms.wms_id and layer_id in (";
 		$i = 0;
 		//generate csv list of layer_ids
 		$layerList = "";
@@ -587,7 +589,7 @@
 		$res = db_prep_query($sql,$v,$t);
 		$e = new mb_notice("class_wmc: sql to pull current wms and layer information from database: ".$sql);
 		//pull all styles of layer with ids from mapbender registry
-		$sql = "SELECT * from layer_style WHERE fkey_layer_id IN (";
+		$sql = "SELECT * FROM layer_style WHERE fkey_layer_id IN (";
 		$sql .= $layerList;
 		$sql .= ")";
 		$resStyle = db_prep_query($sql,$v,$t);
@@ -602,6 +604,7 @@
 		while($row = db_fetch_array($res)){
 			$wmsId = $row["fkey_wms_id"];
 			$layerId = $row["layer_id"];
+			$e = new mb_exception("class_wmc.php - updateUrlsInDb - following layer will be processed: ".$layerId);
 			$layerName = $row["layer_name"];
 			//xpath to pull a special wmc layer object from simple xml object
 			$queryPath = "/wmc:ViewContext/wmc:LayerList/wmc:Layer[wmc:Extension/mapbender:layer_id='".(integer)$layerId."']";
@@ -626,6 +629,63 @@
   				$layer->Name = $layerName;
 				$e = new mb_notice("class_wmc: exchange old getmap url : ".$layer->Server->OnlineResource->attributes('xlink', true)->href." with new getmap url: ".$wmsGetMapUrl);
  				$layer->Server->OnlineResource->attributes('xlink', true)->href = $wmsGetMapUrl;
+				//check if layer has available download options
+				if (defined("SHOW_INSPIRE_DOWNLOAD_IN_TREE") && SHOW_INSPIRE_DOWNLOAD_IN_TREE == true && $row["downloadoptions"] != ""){
+					if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != "") {
+						$downloadOptionsUrl = MAPBENDER_PATH."/php/mod_getDownloadOptions.php?outputFormat=html&id=".str_replace('{','',str_replace('}','',str_replace('}{',',',$row["downloadoptions"])));
+					} else {
+						//relative path - it's not such a good choice ;-)
+						$downloadOptionsUrl = "../php/mod_getDownloadOptions.php?outputFormat=html&id=".str_replace('{','',str_replace('}','',str_replace('}{',',',$row["downloadoptions"])));
+					}
+					//check if layer has a DataURL element
+					if (count($layer->DataURL) > 0) {
+						//found DataURL element
+						$e = new mb_notice("class_wmc.php - updateUrlsInDb - found existing DataURL Element!");
+						//check if OnlineResource is already filled
+						if ($layer->DataURL->OnlineResource) {
+							$e = new mb_notice("class_wmc.php - updateUrlsInDb - found existing DataURL->OnlineResource Element!");
+							$e = new mb_notice("class_wmc.php - updateUrlsInDb - update existing link to DataURL->OnlineResource!");
+							$layer->DataURL->OnlineResource->attributes('xlink', true)->href = $downloadOptionsUrl;
+						}
+					} else {
+						//create dataurl and fill it - maybe with dom?
+						$e = new mb_exception("class_wmc.php - updateUrlsInDb - create new DataURL Element!");
+						//$layerXML = $layer->asXML();
+						//$dom_layer = dom_import_string($layerXML);
+						
+						/*$dom_layer = dom_import_simplexml($layer);
+						$dom = new DOMDocument('1.0');
+						$dom_layer = $dom->importNode($dom_layer, true);
+						$dom_layer = $dom->appendChild($dom_sxe);*/
+						//TODO: help http://stackoverflow.com/questions/3361036/php-simplexml-insert-node-at-certain-position
+						//cause its a f... sequence in wmc standard - DataURL is after Abstract but Abstract is optional .... if <Abstract> exists - item 5 on the other hand item 4
+						//
+						/*
+						<xs:complexType name="LayerType">
+							<xs:sequence>
+								<xs:element name="Server" type="context:ServerType" minOccurs="1" maxOccurs="1"/>
+								<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
+								<xs:element name="Title" type="xs:string" minOccurs="1" maxOccurs="1"/>
+								<xs:element name="Abstract" type="xs:string" minOccurs="0" maxOccurs="1"/>
+								<xs:element name="DataURL" type="context:URLType" minOccurs="0" maxOccurs="1"/>
+								<xs:element name="MetadataURL" type="context:URLType" minOccurs="0" maxOccurs="1"/>
+								<xs:element name="SRS" type="xs:string" minOccurs="0" maxOccurs="1"/>
+								<xs:element name="DimensionList" type="context:DimensionListType” minOccurs="0" maxOccurs="1"/>
+								<xs:element name="FormatList" type="context:FormatListType" minOccurs="0" maxOccurs="1"/>
+								<xs:element name="StyleList" type="context:StyleListType" minOccurs="0" maxOccurs="1"/>
+								<xs:element ref="sld:MinScaleDenominator" minOccurs="0" maxOccurs="1"/>
+								<xs:element ref="sld:MaxScaleDenominator" minOccurs="0" maxOccurs="1"/>
+								<xs:element name="Extension" type="context:ExtensionType" minOccurs="0" maxOccurs="1"/>
+							</xs:sequence>
+
+						*/
+						$DataURL = $layer->addChild('DataURL');
+						$OnlineResource = $DataURL->addChild('OnlineResource');
+						$DataURL->OnlineResource->addAttribute('xlink:type', 'simple','http://www.w3.org/1999/xlink');
+						$DataURL->OnlineResource->addAttribute('xlink:href', $downloadOptionsUrl,'http://www.w3.org/1999/xlink');
+						$e = new mb_notice("class_wmc.php - updateUrlsInDb new DataURL XML : ".$layer->asXML());
+					}
+				}
 				//Help for problem with xlink:href attributes: http://php.net/manual/de/class.simplexmlelement.php!!!!!
 				//exchange legend urls
 				if (isset($row["wms_owsproxy"]) && $row["wms_owsproxy"] != '' && !is_null($row["wms_owsproxy"])) {
@@ -661,7 +721,9 @@
 		}
 		$updatedWMC = $WMCDoc->saveXML();
 		$e = new mb_notice($updatedWMC);
-		$this->update_existing($updatedWMC, $this->wmc_id);
+		if (is_int($this->wmc_id)) {
+			$this->update_existing($updatedWMC, $this->wmc_id);
+		}
 		$endTime = microtime();
 		$e = new mb_notice((string)($endTime - $startTime));
 		return $updatedWMC;



More information about the Mapbender_commits mailing list