[Mapbender-commits] r10093 - in trunk/mapbender: conf http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Mar 27 00:21:04 PDT 2019
Author: armin11
Date: 2019-03-27 00:21:04 -0700 (Wed, 27 Mar 2019)
New Revision: 10093
Modified:
trunk/mapbender/conf/mapbender.conf-dist
trunk/mapbender/http/classes/class_wms.php
Log:
New option for wms layer object to hold layer_metadata_featuretype_wfs-conf relations while loading from db
Modified: trunk/mapbender/conf/mapbender.conf-dist
===================================================================
--- trunk/mapbender/conf/mapbender.conf-dist 2019-03-27 06:00:11 UTC (rev 10092)
+++ trunk/mapbender/conf/mapbender.conf-dist 2019-03-27 07:21:04 UTC (rev 10093)
@@ -249,6 +249,11 @@
define("SHOW_INSPIRE_DOWNLOAD_IN_TREE",true);
# --------------------------------------------
+#Add layer_metadata_featuretype_wfs-conf coupling to wms object to allow the make the layertree more useful (data-service-coupling)
+# --------------------------------------------
+#define("SHOW_COUPLED_FEATURETYPES_IN_TREE",true);
+
+# --------------------------------------------
# UPLOAD
# --------------------------------------------
define("UPLOAD_DIR", "../tmp");
Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php 2019-03-27 06:00:11 UTC (rev 10092)
+++ trunk/mapbender/http/classes/class_wms.php 2019-03-27 07:21:04 UTC (rev 10093)
@@ -106,24 +106,115 @@
$this->setGeoRss = true;
}
}
- /**
- *
- * @generate RSS formated date
- *
- * @param int $timestamp The UNIX_TIMESTAMP
- *
- * @return string
- *
- */
- private static function rssDate($timestamp=null)
- {
- /*** set the timestamp ***/
- $timestamp = ($timestamp==null) ? time() : $timestamp;
- /*** Mon, 02 Jul 2009 11:36:45 +0000 ***/
- return date(DATE_RSS, $timestamp);
- }
-
+ /**
+ *
+ * @generate RSS formated date
+ *
+ * @param int $timestamp The UNIX_TIMESTAMP
+ *
+ * @return string
+ *
+ */
+ private static function rssDate($timestamp=null) {
+ /*** set the timestamp ***/
+ $timestamp = ($timestamp==null) ? time() : $timestamp;
+
+ /*** Mon, 02 Jul 2009 11:36:45 +0000 ***/
+ return date(DATE_RSS, $timestamp);
+ }
+
+ /**
+ *
+ * @filter multidimensional array by value - https://www.w3resource.com/php-exercises/php-array-exercise-52.php TODO - push it in class_administration.php
+ *
+ * @param array $my_array
+ * @param string $index array key
+ * @param string $value value to filter for
+ *
+ * @return $array Filtered array
+ *
+ */
+ public function array_filter_by_value($my_array, $index, $value) {
+ if(is_array($my_array) && count($my_array)>0) {
+ foreach(array_keys($my_array) as $key) {
+ $temp[$key] = $my_array[$key][$index];
+ if ($temp[$key] == $value) {
+ $new_array[$key] = $my_array[$key];
+ }
+ }
+ }
+ return $new_array;
+ }
+
+ /**
+ *
+ * @normalize json array of layer_metadata_featuretype_wfs-conf relations to object
+ * json array is given as result of database procedure f_get_layer_featuretype_coupling
+ * examples (the second boolean parameter defines, if only those couplings should be pulled, that have pre-configured featuretypes!):
+ * select f_get_layer_featuretype_coupling(array[20370,20369], FALSE);
+ * select f_get_layer_featuretype_coupling(ARRAY(select layer_id from layer), TRUE);
+ *
+ * @param string $jsonTable
+ *
+ *
+ * @return string normalized json object: layer->metadata->featuretype->wfs_conf
+ *
+ */
+ public function normalizeLayerFeaturetypeCoupling($jsonTable) {
+ $originalJsonArray = json_decode($jsonTable, TRUE); //!array - not object!
+ //initialize temp arrays
+ $layerIdArray = array();
+ $metadataIdArray = array();
+ $featuretypeIdArray = array();
+ $wfsconfIdArray = array();
+ //$returnObject = new StdClass();
+ $layerCount = 0;
+ $metadataCount = 0;
+ $featuretypeCount = 0;
+ $wfsconfCount = 0;
+ foreach ($originalJsonArray as $layerRecord) {
+ if (!in_array($layerRecord['layerId'], $layerIdArray)) {
+ //get all entries for metadataId
+ $returnObject->layer[$layerCount]->id = $layerRecord['layerId'];
+ $reducedLayerArray = $this->array_filter_by_value($originalJsonArray, 'layerId', $layerRecord['layerId']);
+ foreach ($reducedLayerArray as $metadataRecord) {
+ if (!in_array($metadataRecord['metadataId'], $metadataIdArray) && $metadataRecord['$metadataId'] !== 0) {
+ $returnObject->layer[$layerCount]->metadata[$metadataCount]->id = $metadataRecord['metadataId'];
+ $reducedMetadataArray = $this->array_filter_by_value($reducedLayerArray, 'metadataId', $metadataRecord['metadataId']);
+ if ($reducedMetadataArray !== null) {
+ foreach ($reducedMetadataArray as $featuretypeRecord) {
+ if ($featuretypeRecord['$featuretypeId'] !== 0) {
+ $returnObject->layer[$layerCount]->metadata[$metadataCount]->featuretype[$featuretypeCount]->id = $featuretypeRecord['featuretypeId'];
+ $reducedFeaturetypeArray = $this->array_filter_by_value($reducedMetadataArray, 'featuretypeId', $featuretypeRecord['featuretypeId']);
+ if ($reducedFeaturetypeArray !== null) {
+ foreach ($reducedFeaturetypeArray as $wfsConfRecord) {
+ if (!in_array($wfsConfIdArray, $wfsConfRecord['wfsConfId']) && $wfsConfRecord['wfsConfId'] !== 0) {
+ $returnObject->layer[$layerCount]->metadata[$metadataCount]->featuretype[$featuretypeCount]->wfsConf[$wfsConfCount]->id = $wfsConfRecord['wfsConfId'];
+ }
+ $wfsConfIdArray[] = $wfsConfRecord['wfsConfId'];
+ $wfsConfCount++;
+ }
+ $wfsConfCount = 0;
+ $featuretypeIdArray[] = $featuretypeRecord['featuretypeId'];
+ $featuretypeCount++;
+ }
+ }
+ }
+ $featuretypeCount = 0;
+ $metadataIdArray[] = $metadataRecord['metadataId'];
+ $metadataCount++;
+ }
+ }
+ }
+ $metadataCount = 0;
+ $layerIdArray[] = $layerRecord['layerId'];
+ $layerCount++;
+ }
+ }
+ return json_encode($returnObject);
+ }
+
public static function getWmsMetadataUrl ($wmsId) {
#return preg_replace(
# "/(.*)frames\/login.php/",
@@ -1125,7 +1216,6 @@
}
}
}
-
}
else {
continue;
@@ -2199,8 +2289,7 @@
}
if(!$res){
db_rollback();
- }
- else {
+ } else {
if ($this->overwriteCategories == true) {
$e = new mb_notice("class_wms.php - overwrite categories has been activated");
}
@@ -2305,35 +2394,32 @@
}
function isSupportedSRS($epsg,$layerId) {
//request the original capabilities from service
- $sql = "SELECT layer.layer_name AS layer_name, wms.wms_getcapabilities_doc AS cap from layer,wms WHERE layer.layer_id=".$layerId." AND layer.fkey_wms_id=wms.wms_id";
- $res = db_query($sql);
- $row = db_fetch_array($res);
+ $sql = "SELECT layer.layer_name AS layer_name, wms.wms_getcapabilities_doc AS cap from layer,wms WHERE layer.layer_id=".$layerId." AND layer.fkey_wms_id=wms.wms_id";
+ $res = db_query($sql);
+ $row = db_fetch_array($res);
//parse capabilities to php object - check if it is still loaded to db
if ($row['cap'] == '') {
$wmsCapXml=simplexml_load_string($this->wms_getcapabilities_doc);
- }
- else {
+ } else {
$wmsCapXml=simplexml_load_string($row['cap']);
}
-
if(!isset($wmsCapXml)) {
$n = new mb_exception("Problem while parsing capabilities document with simplexml");
echo "Problem while parsing capabilities document with simplexml<br>";
return false;
- }
-
+ }
//layer name from DB
$layerName=$row['layer_name'];
//defining the xpath for getting all Layer-tags
$xpathLayerName="//Layer[./Name =\"".$layerName."\"]";
- $layerObject=$wmsCapXml->xpath($xpathLayerName);
+ $layerObject=$wmsCapXml->xpath($xpathLayerName);
- //for none named layer (only title is set)
- if (empty($layerObject)){
- $xpathLayerName="//Layer[./Title =\"".$layerName."\"]";
- $layerObject=$wmsCapXml->xpath($xpathLayerName);
- }
+ //for none named layer (only title is set)
+ if (empty($layerObject)){
+ $xpathLayerName="//Layer[./Title =\"".$layerName."\"]";
+ $layerObject=$wmsCapXml->xpath($xpathLayerName);
+ }
if(!isset($layerObject[0])) {
$n = new mb_notice("Layer has no name and title, BBOX will not be generated for ".$epsg);
@@ -2969,24 +3055,24 @@
}
//NEW 2012-11: Check for changed layer names with options $changedLayersObj
- for($i=0; $i<count($changedLayers); $i++){
- if(trim($changedLayers[$i]["oldLayerName"]) != trim($changedLayers[$i]["newLayerName"])) {
- $sql = "UPDATE layer SET layer_name = $1 WHERE fkey_wms_id = $2 AND layer_name = $3";
- $v = array(trim($changedLayers[$i]["newLayerName"]), $myWMS, trim($changedLayers[$i]["oldLayerName"]));
- $t = array('s','i','s');
- $res = db_prep_query($sql,$v,$t);
- new mb_notice("update oldLayerName to newLayerName :". $changedLayers[$i]["oldLayerName"]."----->".$changedLayers[$i]["newLayerName"]);
- if(!$res){
- db_rollback();
- }
- }
- #new mb_notice("oldLayerName ==================". $changedLayers[$i]["oldLayerName"]);
- #new mb_notice("newLayerName ==================". $changedLayers[$i]["newLayerName"]);
- }
+ for($i=0; $i<count($changedLayers); $i++){
+ if(trim($changedLayers[$i]["oldLayerName"]) != trim($changedLayers[$i]["newLayerName"])) {
+ $sql = "UPDATE layer SET layer_name = $1 WHERE fkey_wms_id = $2 AND layer_name = $3";
+ $v = array(trim($changedLayers[$i]["newLayerName"]), $myWMS, trim($changedLayers[$i]["oldLayerName"]));
+ $t = array('s','i','s');
+ $res = db_prep_query($sql,$v,$t);
+ new mb_notice("update oldLayerName to newLayerName :". $changedLayers[$i]["oldLayerName"]."----->".$changedLayers[$i]["newLayerName"]);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ #new mb_notice("oldLayerName ==================". $changedLayers[$i]["oldLayerName"]);
+ #new mb_notice("newLayerName ==================". $changedLayers[$i]["newLayerName"]);
+ }
- ######## NEW 2013-07: split off the check routine to insert and update layers to one section for root layer and one for all child layers
- ######## reason: If root layer and child layer have same name, it crashes here!!!
- ################################ start section for root-layer
+ ######## NEW 2013-07: split off the check routine to insert and update layers to one section for root layer and one for all child layers
+ ######## reason: If root layer and child layer have same name, it crashes here!!!
+ ################################ start section for root-layer
# update TABLE layer
$oldLayerNameArray = array();
@@ -3440,8 +3526,6 @@
//$e = new mb_exception("class_wms.php - invoke createObjFromDB - for gui ".$gui_id);
$count=0;
#$res_count=db_num_rows($res);
-
-
while($row = db_fetch_array($res)){
$this->gui_wms_mapformat=$row["gui_wms_mapformat"];
$this->gui_wms_featureinfoformat=$row["gui_wms_featureinfoformat"];
@@ -3470,8 +3554,7 @@
$this->wms_getcapabilities = $owsproxyurl;
$this->wms_getfeatureinfo = $owsproxyurl;
$this->wms_getlegendurl = $owsproxyurl;
- }
- else{
+ } else {
$this->wms_getmap = $row2["wms_getmap"];
$this->wms_getcapabilities = $row2["wms_getcapabilities"];
$this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
@@ -3541,8 +3624,13 @@
$count=0;
while($row = db_fetch_array($res)){
- $layer_id = $row["fkey_layer_id"];
- $sql = "SELECT *, f_get_download_options_for_layer(layer_id) as downloadoptions FROM layer WHERE layer_id = $1";
+ $layer_id = $row["fkey_layer_id"];
+ if (defined("SHOW_COUPLED_FEATURETYPES_IN_TREE") && SHOW_COUPLED_FEATURETYPES_IN_TREE == true) {
+ $sql = "SELECT *, f_get_download_options_for_layer(layer_id) as downloadoptions, f_get_layer_featuretype_coupling(array[ layer_id ], FALSE) as featuretypecoupling FROM layer WHERE layer_id = $1";
+//$e = new mb_exception("show coupling!");
+ } else {
+ $sql = "SELECT *, f_get_download_options_for_layer(layer_id) as downloadoptions FROM layer WHERE layer_id = $1";
+ }
$v = array($layer_id);
$t = array('i');
$res_layer = db_prep_query($sql,$v,$t);
@@ -3588,6 +3676,36 @@
$count_metadataUrl++;
}
+ //new in 2019 - possibility to show symbol for accessing datatable - one url for each entry in json string $row2['featuretypecoupling']
+ //link to be invoked
+ if (defined("SHOW_COUPLED_FEATURETYPES_IN_TREE") && SHOW_COUPLED_FEATURETYPES_IN_TREE == true && $row2["featuretypecoupling"] != "[]") {
+ //parse json and built following tree
+ /*TODO - alter json object to following struct: {"layerId": 1234,
+ "datasetMetadata":
+ ["metadataId": 12334,
+ "fileIdentifier": "ded3dsd3e...",
+ "featurtypes":
+ ["featurtypeId": 123456,
+ "wfsConfs":
+ ["wfsConfId": 1234,
+ "wfsConfType": 0
+ ]
+ ]
+ ]
+ }
+ */
+
+ //built url for webservice
+ /*if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != "") {
+ $featuretypeMetadataUrl = MAPBENDER_PATH."/php/mod_showLayerToFeaturetypeCoupling.php?outputFormat=html&struct=";
+ } else {
+ $featuretypeMetadataUrl = "../php/mod_showLayerToFeaturetypeCoupling.php?outputFormat=html&struct=";
+ }*/
+ $this->objLayer[$layer_cnt]->layer_featuretype_coupling = $this->normalizeLayerFeaturetypeCoupling($row2["featuretypecoupling"]);
+//$e = new mb_exception("coupling json: ".$this->normalizeLayerFeaturetypeCoupling($row2["featuretypecoupling"]));
+ }
+ //add to layer object
+ //$this->objLayer[$layer_cnt]->layer_featuretype_coupling = $jsonObject;
//old one:
//$this->objLayer[$layer_cnt]->layer_metadataurl[0]->href = $row2["layer_metadataurl"];
$this->objLayer[$layer_cnt]->layer_searchable =$row2["layer_searchable"];
@@ -3776,8 +3894,13 @@
$count_format++;
}
-
- $sql = "SELECT *, f_get_download_options_for_layer(layer_id) as downloadoptions from layer where fkey_wms_id = $1 ORDER BY layer_pos";
+ if (defined("SHOW_COUPLED_FEATURETYPES_IN_TREE") && SHOW_COUPLED_FEATURETYPES_IN_TREE == true) {
+ $sql = "SELECT *, f_get_download_options_for_layer(layer_id) as downloadoptions, f_get_layer_featuretype_coupling(array[ layer_id ], FALSE) as featuretypecoupling FROM layer WHERE fkey_wms_id = $1 ORDER BY layer_pos";
+//$e = new mb_exception("show coupling!");
+ } else {
+ $sql = "SELECT *, f_get_download_options_for_layer(layer_id) as downloadoptions FROM layer WHERE fkey_wms_id = $1 ORDER BY layer_pos";
+ }
+ //$sql = "SELECT *, f_get_download_options_for_layer(layer_id) as downloadoptions from layer where fkey_wms_id = $1 ORDER BY layer_pos";
$v = array($wms_id);
$t = array('i');
$res_layer = db_prep_query($sql,$v,$t);
@@ -3827,6 +3950,35 @@
$this->objLayer[$layer_cnt]->layer_metadataurl[$count_metadataUrl]->format = $row4["md_format"];
$count_metadataUrl++;
}
+ //new in 2019 - possibility to show symbol for accessing datatable - one url for each entry in json string $row2['featuretypecoupling']
+ //link to be invoked
+//$e = new mb_exception("row2 featuretypecoupling:".$row2["featuretypecoupling"]);
+ if (defined("SHOW_COUPLED_FEATURETYPES_IN_TREE") && SHOW_COUPLED_FEATURETYPES_IN_TREE == true && $row2["featuretypecoupling"] != "[]") {
+ //parse json and built following tree
+ /*TODO - alter json object to following struct: {"layerId": 1234,
+ "datasetMetadata":
+ ["metadataId": 12334,
+ "fileIdentifier": "ded3dsd3e...",
+ "featurtypes":
+ ["featurtypeId": 123456,
+ "wfsConfs":
+ ["wfsConfId": 1234,
+ "wfsConfType": 0
+ ]
+ ]
+ ]
+ }
+ */
+
+ //built url for webservice
+ /*if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != "") {
+ $featuretypeMetadataUrl = MAPBENDER_PATH."/php/mod_showLayerToFeaturetypeCoupling.php?outputFormat=html&struct=";
+ } else {
+ $featuretypeMetadataUrl = "../php/mod_showLayerToFeaturetypeCoupling.php?outputFormat=html&struct=";
+ }*/
+ $this->objLayer[$layer_cnt]->layer_featuretype_coupling = $this->normalizeLayerFeaturetypeCoupling($row2["featuretypecoupling"]);
+//$e = new mb_exception("coupling json: ".$this->normalizeLayerFeaturetypeCoupling($row2["featuretypecoupling"]));
+ }
$this->objLayer[$layer_cnt]->layer_searchable =$row2["layer_searchable"];
$this->objLayer[$layer_cnt]->inspire_download =$row2["inspire_download"];
$this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];
More information about the Mapbender_commits
mailing list