[Mapbender-commits] r6192 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed May 12 05:33:13 EDT 2010


Author: verenadiewald
Date: 2010-05-12 05:33:13 -0400 (Wed, 12 May 2010)
New Revision: 6192

Modified:
   trunk/mapbender/http/plugins/mb_original_metadata_server.php
Log:
originalLayer Metadata

Modified: trunk/mapbender/http/plugins/mb_original_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_original_metadata_server.php	2010-05-12 09:32:55 UTC (rev 6191)
+++ trunk/mapbender/http/plugins/mb_original_metadata_server.php	2010-05-12 09:33:13 UTC (rev 6192)
@@ -13,7 +13,7 @@
 	die;
 };
 
-function parseCapabilitiesDoc($capabilitiesDoc) {
+function getWmsMetadataFromXml($capabilitiesDoc) {
 	$xmlDoc = new DOMDocument();
 	$xmlDoc->encoding = CHARSET;
 	$xmlDoc->preserveWhiteSpace = false;
@@ -129,9 +129,57 @@
 	return $resultObj;
 }
 
+function getLayerMetadataFromXml($capabilitiesDoc,$layerName) {
+	$xmlDoc = new DOMDocument();
+	$xmlDoc->encoding = CHARSET;
+	$xmlDoc->preserveWhiteSpace = false;
+	$xmlDoc->loadXML($capabilitiesDoc);
+	
+	//define default resultObj
+	$resultObj = array(
+		"original_layer_title" => "",
+		"original_layer_abstract" => "",
+		"original_layer_keyword" => ""
+	);
+	
+	$layer_nodes = $xmlDoc->getElementsByTagName('Layer');
+	foreach ($layer_nodes as $node) {
+		$children = $node->childNodes;
+		foreach($children as $child) {
+			if (strtoupper($child->nodeName) == "NAME"){
+				if($child->nodeValue == $layerName) {
+					$layerNode = $node;
+				}	
+			}
+		}
+	}
+	
+	$layerChildren = $layerNode->childNodes;
+	foreach($layerChildren as $layerChild) {
+		if (strtoupper($layerChild->nodeName) == "TITLE") {
+			$resultObj["original_layer_title"] = $layerChild->nodeValue;
+		}
+		if (strtoupper($layerChild->nodeName) == "ABSTRACT") {
+			$resultObj["original_layer_abstract"] = $layerChild->nodeValue;
+		}
+		//"Service"-childnode KeywordList	
+		if (strtoupper($layerChild->nodeName) == "KEYWORDLIST") {
+			$keywords_list = $layerChild->childNodes;
+			$keywords = array();
+			foreach ($keywords_list as $keywordlist_child_node) {																		
+				$keyword = $keywordlist_child_node->nodeValue;						
+				array_push($keywords, $keyword);
+			}
+			$resultObj["original_layer_keyword"] = implode(", ", $keywords); 		
+		}
+	}
+	return $resultObj;
+}
+
 switch ($ajaxResponse->getMethod()) {
 	case "getOriginalMetadata" :
 		$wmsId = $ajaxResponse->getParameter("id");
+		$layerName = $ajaxResponse->getParameter("layerName");
 		$sql = <<<SQL
 	
 SELECT wms_getcapabilities_doc FROM wms WHERE wms_id = $wmsId;
@@ -140,32 +188,17 @@
 		$res = db_query($sql);
 		$row = db_fetch_array($res);
 		$wms_getcapabilities_doc = $row["wms_getcapabilities_doc"];
-		$resultObj = parseCapabilitiesDoc($wms_getcapabilities_doc);
-
-		$ajaxResponse->setResult($resultObj);
-		$ajaxResponse->setSuccess(true);
 		
-		break;
-	case "getLayerMetadata" :
-		$layerId = $ajaxResponse->getParameter("id");
-		getLayer($layerId);
-
-		$sql = <<<SQL
-	
-SELECT layer_id, layer_title, layer_abstract, layer_searchable 
-FROM layer WHERE wms_id = $wmsId;
-
-SQL;
-		$res = db_query($sql);
-
-		$resultObj = array();
-		while ($row = db_fetch_assoc($res)) {
-			foreach ($row as $key => $value) {
-				$resultObj["layer:".$key] = $value;
-			}
+		if($layerName != "") {
+			$resultObj = getLayerMetadataFromXml($wms_getcapabilities_doc,$layerName);
 		}
+		else {
+			$resultObj = getWmsMetadataFromXml($wms_getcapabilities_doc);
+		}
+		
 		$ajaxResponse->setResult($resultObj);
 		$ajaxResponse->setSuccess(true);
+		
 		break;
 	default: 
 		$ajaxResponse->setSuccess(false);



More information about the Mapbender_commits mailing list