[Mapbender-commits] r9003 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jul 28 02:26:11 PDT 2014


Author: armin11
Date: 2014-07-28 02:26:10 -0700 (Mon, 28 Jul 2014)
New Revision: 9003

Modified:
   trunk/mapbender/http/classes/class_metadata_new.php
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/php/mod_getDownloadOptions.php
Log:
Enable a list of download options for datasets  in the searchInterface for wms layers. Uses data service relation

Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php	2014-07-25 11:50:26 UTC (rev 9002)
+++ trunk/mapbender/http/classes/class_metadata_new.php	2014-07-28 09:26:10 UTC (rev 9003)
@@ -26,6 +26,7 @@
 require_once(dirname(__FILE__)."/class_administration.php");
 require_once(dirname(__FILE__)."/class_mb_exception.php");
 require_once(dirname(__FILE__)."/class_json.php");
+require_once(dirname(__FILE__) . "/../php/mod_getDownloadOptions.php");
 
 //definition for the things which are common to all kind of metadata ressources
 
@@ -752,6 +753,10 @@
 				$this->wmsJSON->wms->srv[$j]->layer[0]->legendUrl = $legendInfo['legendUrl'];
 				$this->wmsJSON->wms->srv[$j]->layer[0]->minScale = $legendInfo['minScale'];
 				$this->wmsJSON->wms->srv[$j]->layer[0]->maxScale = $legendInfo['maxScale'];
+				//pull downloadOptions as json with function from other script: php/mod_getDownloadOptions.php
+				$downloadOptionsCs = str_replace("{","",str_replace("}","",str_replace("}{",",",$legendInfo['downloadOptions'])));
+				$downloadOptions = json_decode(getDownloadOptions(explode(',',$downloadOptionsCs)));
+				$this->wmsJSON->wms->srv[$j]->layer[0]->downloadOptions = $downloadOptions;
 
 				if ($subLayers[$rootIndex]['layer_name'] == ''){
 					$this->wmsJSON->wms->srv[$j]->layer[0]->loadable = 0;
@@ -1454,7 +1459,7 @@
 	}
 
 	private function getInfofromLayerId($layerId) {
-			$sql = "SELECT layer_wms.*, layer_style.legendurl, layer_style.legendurlformat FROM (SELECT layer_id, layer_minscale, layer_maxscale, wms_getlegendurl, wms_owsproxy FROM layer INNER JOIN wms ON layer.fkey_wms_id = wms.wms_id WHERE layer.layer_id = $1) as layer_wms, layer_style where layer_style.fkey_layer_id = layer_wms.layer_id";
+			$sql = "SELECT layer_wms.*, layer_style.legendurl, layer_style.legendurlformat FROM (SELECT layer_id, f_get_download_options_for_layer(layer_id) as layer_metadata, layer_minscale, layer_maxscale, wms_getlegendurl, wms_owsproxy FROM layer INNER JOIN wms ON layer.fkey_wms_id = wms.wms_id WHERE layer.layer_id = $1) as layer_wms, layer_style where layer_style.fkey_layer_id = layer_wms.layer_id";
 			$v = array($layerId);
 			$t = array('i');
 			$res = db_prep_query($sql, $v, $t);
@@ -1465,6 +1470,7 @@
 				$owsProxy = $row['wms_owsproxy'];
 				$minScale = $row['layer_minscale'];
 				$maxScale = $row['layer_maxscale'];
+				$downloadOptions = $row['layer_metadata'];
 			}
 			//hostname does not exist! - use hostname from parameter instead
 			if ($owsProxy != null && $owsProxy != '' && $getLegendUrl != '' && $getLegendUrl != null) {
@@ -1479,6 +1485,7 @@
 			$returnArray['getLegendGraphicUrlFormat'] = $legendUrlFormat;
 			$returnArray['minScale'] = $minScale;
 			$returnArray['maxScale'] = $maxScale;
+			$returnArray['downloadOptions'] = $downloadOptions;
 			return $returnArray; 
 	}
 
@@ -1645,6 +1652,9 @@
 			$servObject->layer[$countsublayer]->legendUrl = $legendInfo['legendUrl'];
 			$servObject->layer[$countsublayer]->minScale = $legendInfo['minScale'];
 			$servObject->layer[$countsublayer]->maxScale = $legendInfo['maxScale'];
+			$downloadOptionsCs = str_replace("{","",str_replace("}","",str_replace("}{",",",$legendInfo['downloadOptions'])));
+			$downloadOptions = json_decode(getDownloadOptions(explode(',',$downloadOptionsCs)));
+			$servObject->layer[$countsublayer]->downloadOptions = $downloadOptions;
 			$servObject->layer[$countsublayer]->mdLink = "http://".$this->hostName."/mapbender/php/mod_showMetadata.php?languageCode=".$this->languageCode."&resource=layer&layout=tabs&id=".$child['layer_id'];
 			if ($child['layer_name'] == ''){
 				$servObject->layer[$countsublayer]->loadable = 0;

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2014-07-25 11:50:26 UTC (rev 9002)
+++ trunk/mapbender/http/classes/class_wmc.php	2014-07-28 09:26:10 UTC (rev 9003)
@@ -648,7 +648,7 @@
 							} else {
 								$mimeType = 'image/png';
 							}
-							$e = new mb_exception("class_wmc: mimetype for legendurl: ".$mimeType);
+							$e = new mb_notice("class_wmc: mimetype for legendurl: ".$mimeType);
 							if (isset($style[(integer)$layerId][(string)$styleObject->Name][$mimeType]) && $style[(integer)$layerId][(string)$styleObject->Name][$mimeType] != '') {
 								$e = new mb_notice("class_wmc: exchange old legendurl url : ".$layer->StyleList->Style->LegendURL->OnlineResource->attributes('xlink', true)->href." with new legendurl: ".$style[(integer)$layerId][(string)$styleObject->Name][$mimeType]);
 								$layer->StyleList->Style->LegendURL->OnlineResource->attributes('xlink', true)->href = $style[(integer)$layerId][(string)$styleObject->Name][$mimeType];

Modified: trunk/mapbender/http/php/mod_getDownloadOptions.php
===================================================================
--- trunk/mapbender/http/php/mod_getDownloadOptions.php	2014-07-25 11:50:26 UTC (rev 9002)
+++ trunk/mapbender/http/php/mod_getDownloadOptions.php	2014-07-28 09:26:10 UTC (rev 9003)
@@ -37,7 +37,6 @@
 	}
 }
 
-
 //make all parameters available as upper case
 foreach($_REQUEST as $key => $val) {
 	$_REQUEST[strtoupper($key)] = $val;
@@ -55,125 +54,131 @@
 		$isUuid = $uuid->isValid();
 		if (!$isUuid) {
 			//echo 'Id: <b>'.$testMatch.'</b> is not a valid uuid (12-4-4-4-8)!<br/>'; 
-			echo 'Parameter <b>Id</b> is not a valid uuid (12-4-4-4-8)!<br/>'; 
+			echo 'Parameter <b>Id</b> is not a valid uuid (12-4-4-4-8) or a list of uuids!<br/>'; 
 			die(); 		
 		}
 	}
 	$testMatch = NULL;
 }
 
-//define query to pull all download options - actually only the inspire download services based on atom feeds
+function getDownloadOptions($idList) {
+	//define query to pull all download options - actually only the inspire download services based on atom feeds
+	$sql = "select service_id, service_uuid, resource_id, resource_type, datalink, NULL as datalink_text, title,format from (
+select service_id, resource_id, service_uuid, resource_type, fkey_datalink_id as datalink, title, format from (select fkey_wms_id as service_id, layer_id as resource_id, 'layer' as resource_type, layer.uuid as service_uuid, metadata_relation.title, format from layer inner join (select metadata_id, title, format, uuid, fkey_layer_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) ";
 
-$sql = "select service_id, service_uuid, resource_id, resource_type, datalink, NULL as datalink_text, format from (
-select service_id, resource_id, service_uuid, resource_type, fkey_datalink_id as datalink, format from (select fkey_wms_id as service_id, layer_id as resource_id, 'layer' as resource_type, layer.uuid as service_uuid, format from layer inner join (select metadata_id, format, uuid, fkey_layer_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) ";
-
-$sql .= "as metadata_relation on metadata_relation.fkey_layer_id = layer.layer_id where layer.inspire_download = 1 and metadata_relation.uuid = $1) as layer_metadata LEFT OUTER JOIN ows_relation_data ON layer_metadata.resource_id = ows_relation_data.fkey_layer_id
+	$sql .= "as metadata_relation on metadata_relation.fkey_layer_id = layer.layer_id where layer.inspire_download = 1 and metadata_relation.uuid = $1) as layer_metadata LEFT OUTER JOIN ows_relation_data ON layer_metadata.resource_id = ows_relation_data.fkey_layer_id
 ) as inspire_layer inner join wms on inspire_layer.service_id = wms.wms_id ";
 
 
-$sql .= "union select fkey_wfs_id as service_id, service_uuid, featuretype_id as resource_id, 'wfs' as resource_type, NULL ";
+	$sql .= "union select fkey_wfs_id as service_id, service_uuid, featuretype_id as resource_id, 'wfs' as resource_type, NULL ";
 
-$sql .= "as datalink, NULL as datalink_text, 'GML' as format from (select wfs_featuretype.featuretype_id ,wfs_featuretype.fkey_wfs_id, wfs.uuid as service_uuid, wfs_featuretype.inspire_download from wfs_featuretype inner join wfs on wfs_featuretype.fkey_wfs_id = wfs.wfs_id WHERE inspire_download = 1 ORDER BY featuretype_id) as featuretype_inspire inner join (select metadata_id, format, uuid, fkey_featuretype_id from mb_metadata inner join ows_relation_metadata on ";
+	$sql .= "as datalink, NULL as datalink_text, 'GML' as format, title from (select wfs_featuretype.featuretype_id ,wfs_featuretype.fkey_wfs_id, wfs.uuid as service_uuid, wfs_featuretype.inspire_download from wfs_featuretype inner join wfs on wfs_featuretype.fkey_wfs_id = wfs.wfs_id WHERE inspire_download = 1 ORDER BY featuretype_id) as featuretype_inspire inner join (select metadata_id, title, format, uuid, fkey_featuretype_id from mb_metadata inner join ows_relation_metadata on ";
 
-$sql .= "ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) as metadata_relation on metadata_relation.fkey_featuretype_id = featuretype_inspire.featuretype_id and metadata_relation.uuid = $1 ";
+	$sql .= "ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) as metadata_relation on metadata_relation.fkey_featuretype_id = featuretype_inspire.featuretype_id and metadata_relation.uuid = $1 ";
 
-$sql .= "union select NULL as service_id, NULL as service_uuid, NULL as resource_id, 'metadata' as resource_type, NULL ";
+	$sql .= "union select NULL as service_id, NULL as service_uuid, NULL as resource_id, 'metadata' as resource_type, NULL ";
 
-$sql .= "as datalink, datalinks as datalink_text, format FROM mb_metadata WHERE mb_metadata.uuid = $1 and inspire_download = 1;";
+	$sql .= "as datalink, datalinks as datalink_text, title, format FROM mb_metadata WHERE mb_metadata.uuid = $1 and inspire_download = 1;";
 
+	/*
+	$sql = "select service_id, resource_id, resource_type, fkey_datalink_id as datalink from (select fkey_wms_id as service_id, layer_id as resource_id, 'layer' as resource_type from layer inner join (select metadata_id, uuid, fkey_layer_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) ";
 
-/*
-$sql = "select service_id, resource_id, resource_type, fkey_datalink_id as datalink from (select fkey_wms_id as service_id, layer_id as resource_id, 'layer' as resource_type from layer inner join (select metadata_id, uuid, fkey_layer_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) ";
+	$sql .= "as metadata_relation on metadata_relation.fkey_layer_id = layer.layer_id where layer.inspire_download = 1 and metadata_relation.uuid = $1) as layer_metadata LEFT OUTER JOIN ows_relation_data ON layer_metadata.resource_id = ows_relation_data.fkey_layer_id union select fkey_wfs_id as service_id, featuretype_id as resource_id, 'wfs' as resource_type, NULL ";
 
-$sql .= "as metadata_relation on metadata_relation.fkey_layer_id = layer.layer_id where layer.inspire_download = 1 and metadata_relation.uuid = $1) as layer_metadata LEFT OUTER JOIN ows_relation_data ON layer_metadata.resource_id = ows_relation_data.fkey_layer_id union select fkey_wfs_id as service_id, featuretype_id as resource_id, 'wfs' as resource_type, NULL ";
+	$sql .= "as datalink from (select wfs_featuretype.featuretype_id ,wfs_featuretype.fkey_wfs_id,  wfs_featuretype.inspire_download from wfs_featuretype WHERE inspire_download = 1 ORDER BY featuretype_id) as featuretype_inspire inner join (select metadata_id, uuid, fkey_featuretype_id from mb_metadata inner join ows_relation_metadata on ";
 
-$sql .= "as datalink from (select wfs_featuretype.featuretype_id ,wfs_featuretype.fkey_wfs_id,  wfs_featuretype.inspire_download from wfs_featuretype WHERE inspire_download = 1 ORDER BY featuretype_id) as featuretype_inspire inner join (select metadata_id, uuid, fkey_featuretype_id from mb_metadata inner join ows_relation_metadata on ";
+	$sql .= "ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) as metadata_relation on metadata_relation.fkey_featuretype_id = featuretype_inspire.featuretype_id and metadata_relation.uuid = $1;";*/
 
-$sql .= "ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) as metadata_relation on metadata_relation.fkey_featuretype_id = featuretype_inspire.featuretype_id and metadata_relation.uuid = $1;";*/
-
-//initialize array for result
-
-for ($i = 0; $i < count($idList); $i++) {
-	$v = array($idList[$i]);
-	$t = array('s');
-	$res = db_prep_query($sql,$v,$t);
-	//problem, $res don't give back false if it was not successful!
-	//push rows into associative array
-	$j = 0;
-	while ($row = db_fetch_assoc($res)) {
-		//echo "j: ".$j."<br>";
-		switch ($row['resource_type']) {		
-			case "wfs":
-				$serviceIdIndex = false;
-				for ($k = 0; $k < count($downloadOptions->{$idList[$i]}->option); $k++) {
-					//echo "k: ".$k."<br>";
-					//echo "service_id: ".$row['service_id']." - searched Id: ".$downloadOptions->{$idList[$i]}->option[$k]->serviceId."<br>";
-					if ($row['service_id'] == $downloadOptions->{$idList[$i]}->option[$k]->serviceId) {
-						//service_id found at index $k
-						$serviceIdIndex = $k;
-						//echo "Service already found on index: ".$serviceIdIndex."<br>";
-					} 
-				}
-				if ($serviceIdIndex !== false) {
-					//echo "Add featuretype to given service: ".$serviceIdIndex."<br>";
-					//old wfs has been found
-					//get count of current fts
-					$m = count($downloadOptions->{$idList[$i]}->option[$serviceIdIndex]->featureType);
-					//echo "m: ".$m."<br>";
-					$downloadOptions->{$idList[$i]}->option[$serviceIdIndex]->featureType[$m] = $row['resource_id'];
-				} else {
-					$downloadOptions->{$idList[$i]}->option[$j]->type = "wfsrequest";
+	//initialize array for result
+	//$e = new mb_exception($idList);
+	for ($i = 0; $i < count($idList); $i++) {
+		$v = array($idList[$i]);
+		$t = array('s');
+		$res = db_prep_query($sql,$v,$t);
+		//problem, $res don't give back false if it was not successful!
+		//push rows into associative array
+		$j = 0;
+		while ($row = db_fetch_assoc($res)) {
+			//echo "j: ".$j."<br>";
+			switch ($row['resource_type']) {		
+				case "wfs":
+					$serviceIdIndex = false;
+					for ($k = 0; $k < count($downloadOptions->{$idList[$i]}->option); $k++) {
+						//echo "k: ".$k."<br>";
+						//echo "service_id: ".$row['service_id']." - searched Id: ".$downloadOptions->{$idList[$i]}->option[$k]->serviceId."<br>";
+						if ($row['service_id'] == $downloadOptions->{$idList[$i]}->option[$k]->serviceId) {
+							//service_id found at index $k
+							$serviceIdIndex = $k;
+							//echo "Service already found on index: ".$serviceIdIndex."<br>";
+						} 
+					}
+					if ($serviceIdIndex !== false) {
+						//echo "Add featuretype to given service: ".$serviceIdIndex."<br>";
+						//old wfs has been found
+						//get count of current fts
+						$m = count($downloadOptions->{$idList[$i]}->option[$serviceIdIndex]->featureType);
+						//echo "m: ".$m."<br>";
+						$downloadOptions->{$idList[$i]}->option[$serviceIdIndex]->featureType[$m] = $row['resource_id'];
+					} else {
+						$downloadOptions->{$idList[$i]}->option[$j]->type = "wfsrequest";
+						$downloadOptions->{$idList[$i]}->option[$j]->serviceId = $row['service_id'];
+						$downloadOptions->{$idList[$i]}->option[$j]->serviceUuid = $row['service_uuid'];
+						$downloadOptions->{$idList[$i]}->option[$j]->featureType[0] = $row['resource_id'];
+						$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
+					}
+					$downloadOptions->{$idList[$i]}->title = $row['title'];
+					$downloadOptions->{$idList[$i]}->uuid = $idList[$i];
+				break;
+				case "layer":
+					if (!isset($row['datalink'] ) || $row['datalink'] == '') {
+						$downloadOptions->{$idList[$i]}->option[$j]->type = "wmslayergetmap";
+						$row['format'] = 'GeoTIFF';
+					} else {
+						$downloadOptions->{$idList[$i]}->option[$j]->type = "wmslayerdataurl";
+						//add to array with datalink (ids)
+						//$arrayDataLinks[] = $row['datalink'];
+					}
 					$downloadOptions->{$idList[$i]}->option[$j]->serviceId = $row['service_id'];
-					$downloadOptions->{$idList[$i]}->option[$j]->serviceUuid = $row['service_uuid'];
-					$downloadOptions->{$idList[$i]}->option[$j]->featureType[0] = $row['resource_id'];
+					$downloadOptions->{$idList[$i]}->option[$j]->serviceUuid = $row['service_uuid'];//This is a layer uuid - not a service uuid!!!!
+					$downloadOptions->{$idList[$i]}->option[$j]->resourceId = $row['resource_id'];
 					$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
-				}
-			break;
-			case "layer":
-				if (!isset($row['datalink'] ) || $row['datalink'] == '') {
-					$downloadOptions->{$idList[$i]}->option[$j]->type = "wmslayergetmap";
-					$row['format'] = 'GeoTIFF';
-				} else {
-					$downloadOptions->{$idList[$i]}->option[$j]->type = "wmslayerdataurl";
-					//add to array with datalink (ids)
-					//$arrayDataLinks[] = $row['datalink'];
-				}
-				$downloadOptions->{$idList[$i]}->option[$j]->serviceId = $row['service_id'];
-				$downloadOptions->{$idList[$i]}->option[$j]->serviceUuid = $row['service_uuid'];//This is a layer uuid - not a service uuid!!!!
-				$downloadOptions->{$idList[$i]}->option[$j]->resourceId = $row['resource_id'];
-				$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
-				$downloadOptions->{$idList[$i]}->option[$j]->dataLink = $row['datalink'];
-			break;
-			case "metadata":
-				if (isset($row['datalink_text'] ) || $row['datalink_text'] != '') {
-					$downloadLinks = json_decode($row['datalink_text']);
-					$downloadOptions->{$idList[$i]}->option[$j]->type = "downloadlink";
-					//parse json and add some more info?
-					//$downloadLinks = json_decode($row['datalink_text']);
-					foreach ($downloadLinks->downloadLinks as $downloadLink) {
-						$downloadOptions->{$idList[$i]}->option[$j]->link = $downloadLink;
-						//check if 
-						$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
+					$downloadOptions->{$idList[$i]}->option[$j]->dataLink = $row['datalink'];
+					$downloadOptions->{$idList[$i]}->title = $row['title'];
+					$downloadOptions->{$idList[$i]}->uuid = $idList[$i];
+				break;
+				case "metadata":
+					if (isset($row['datalink_text'] ) || $row['datalink_text'] != '') {
+						$downloadLinks = json_decode($row['datalink_text']);
+						$downloadOptions->{$idList[$i]}->option[$j]->type = "downloadlink";
+						//parse json and add some more info?
+						//$downloadLinks = json_decode($row['datalink_text']);
+						foreach ($downloadLinks->downloadLinks as $downloadLink) {
+							$downloadOptions->{$idList[$i]}->option[$j]->link = $downloadLink;
+							//check if 
+							$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
+						}
 					}
-				}
-	
-			break;
+					$downloadOptions->{$idList[$i]}->title = $row['title'];
+					$downloadOptions->{$idList[$i]}->uuid = $idList[$i];
+				break;
+			}
+		$j++;
 		}
-	$j++;
+		//delete double entries - maybe url is given from dataurl - use this 
+		//get all dataurlids
+		//foreach($downloadOptions->{$idList[$i]}->option as $option) {
+			//$option->dataLink;
+		//}
 	}
-	//delete double entries - maybe url is given from dataurl - use this 
-	//get all dataurlids
-	//foreach($downloadOptions->{$idList[$i]}->option as $option) {
-		//$option->dataLink;
-		
-	//}
-	
+	//$e = new mb_exception(json_encode($downloadOptions));
+	//add further option from metadata itself - if 
+	$result = json_encode($downloadOptions);
+	return $result;
 }
 
-
-//add further option from metadata itself - if 
-$result = json_encode($downloadOptions);
-header('Content-Type: application/json; charset='.CHARSET);
-
-echo $result;
+$downloadOptions = getDownloadOptions($idList);
+if ($downloadOptions != "null") {
+	header('Content-Type: application/json; charset='.CHARSET);
+	echo $downloadOptions;
+}
 ?>



More information about the Mapbender_commits mailing list