[Mapbender-commits] r5498 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Feb 11 06:29:51 EST 2010
Author: armin11
Date: 2010-02-11 06:29:50 -0500 (Thu, 11 Feb 2010)
New Revision: 5498
Modified:
trunk/mapbender/http/classes/class_metadata_new.php
Log:
new: show authorization in json metadata
Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php 2010-02-11 11:28:46 UTC (rev 5497)
+++ trunk/mapbender/http/classes/class_metadata_new.php 2010-02-11 11:29:50 UTC (rev 5498)
@@ -85,6 +85,7 @@
if ($this->outputFormat == 'json'){
$this->json = new Mapbender_JSON;
}
+ $this->accessableLayers = NULL;
//set a time to find time consumers
$this->searchStartTime = $this->microtime_float();
//Defining of the different database categories
@@ -176,7 +177,7 @@
$this->generateWFSMetadata($this->wfsDoc);
}
if (isset($this->searchResources) & strtolower($this->searchResources) === "wms") {
- $this->searchView = 'wms_search_table_test';
+ $this->searchView = 'search_wms_view';
$this->orderBy = " ORDER BY load_count DESC";
$this->resourceClasses = array(0,1,2);
$this->generateWMSMetadata($this->wmsDoc);
@@ -274,7 +275,7 @@
$this->wfsJSON->wfs->srv[$i-$j]->ftype = array();
}
//fill in featuretype infos
- $this->wfsJSON->wfs->srv[$i-$j]->ftype[$l-$m]->id = $wfsMatrix[$i]['featuretype_id'];
+ $this->wfsJSON->wfs->srv[$i-$j]->ftype[$l-$m]->id = (integer)$wfsMatrix[$i]['featuretype_id'];
$this->wfsJSON->wfs->srv[$i-$j]->ftype[$l-$m]->title = $wfsMatrix[$i]['featuretype_title'];
$this->wfsJSON->wfs->srv[$i-$j]->ftype[$l-$m]->abstract = $wfsMatrix[$i]['featuretype_abstract'];
$this->wfsJSON->wfs->srv[$i-$j]->ftype[$l-$m]->mdLink = $_SERVER['HOST']."/mapbender/x_geoportal/showWFeatureTypeMetadata.php?id=".$wfsMatrix[$i]['featuretype_id'];
@@ -353,18 +354,27 @@
//initialize root layer id;
$rootLayerId = -1;
$j = 0;
+ //get array with all available layer_id for this user:
+ $admin = new administration();
+ $this->accessableLayers = $admin->getLayersByPermission($this->userId);
+ #echo "<br>user_id: ".$this->userId."<br><br>";
+ #var_dump($this->accessableLayers);
+ #echo "<br>";
+
#$countWmsMatrix = count($wmsMatrix);
#echo $countWmsMatrix;
if ($n != 0) {
for($i=0; $i<count($wmsMatrix);$i++){
$layerID = $wmsMatrix[$i]['layer_id'];
#echo "<br>LayerID: ".$layerID."<br>";
- $wmsID = $wmsMatrix[$i]['wms_id'];
+ #$wmsID = $wmsMatrix[$i]['wms_id']; //get first wms id - in the next loop - dont get second, but some else!
if (!in_array($layerID, $layerIdArray) or !in_array($rootLayerId, $layerIdArray)) {
+ $wmsID = $wmsMatrix[$i]['wms_id']; //get first wms id - in the next loop - dont get second, but some else!
//Select all layers of with this wms_id into new array per WMS - the grouping should be done by wms!
$subLayers = $this->filter_by_value($wmsMatrix, 'wms_id', $wmsID);
- #echo "<br>Sublayers: <br>";
- #print_r($subLayers);
+ #echo "<br>wms_id: ".$wmsID."<br>";
+ #echo "<br>Number of sublayers: <br>";
+ #print(count($subLayers));
//Sort array by load_count - problem: maybe there are some groups between where count is to low (they have no load count because you cannot load them by name)? - Therefor we need some ideas - or pull them out of the database and show them greyed out. Another way will be to define a new group (or wms with the same id) for those layers which are more than one integer away from their parents
$subLayersFlip = $this->flipDiagonally($subLayers);
#var_dump($subLayers['layer_pos']);
@@ -373,10 +383,17 @@
#var_dump($subLayers['layer_id']);
#echo "<br>";
$index = array_search($layerID, $subLayersFlip['layer_id']);
- #echo "<br>found layer_id= ".$layerID." at index: ".$index." in sublayerstable<br>";
+ #echo "<br>found layer_id= ".$layerID." at index: ".$index." in sublayerstable layer_pos=".$subLayers[$index]['layer_pos']." <br>";
+
+ #echo "<br>sublayers: ";
+ #var_dump($subLayersFlip);
+ #echo "<br>";
$rootIndex = $this->getLayerParent($subLayersFlip, $index);
$rootLayerPos = $subLayers[$rootIndex]['layer_pos'];
$rootLayerId = $subLayers[$rootIndex]['layer_id'];
+ #echo "<br>root layer for this layer: <br>";
+ #echo "<br>id= "..""
+ #echo "<br>";
#echo "<br>LayerId:<br>";
#echo "<br>".$layerID."<br>";
#echo "<br>rootLayerPos:<br>";
@@ -385,19 +402,20 @@
#echo "<br>".$rootLayerId."<br>";
//push root layer id in array
array_push($layerIdArray, $rootLayerId);
+
#echo "<br>root Layer ID: ".$rootLayerId."<br>";
#array_multisort($subLayers['layer_pos'], SORT_ASC);
#print_r($subLayers);
#$subLayers = $this->flipDiagonally($subLayers);
#print_r("<br>rootIndex: ".$rootIndex."<br>");
//Create object for wms service level
- $this->wmsJSON->wms->srv[$i-$j]->id = $subLayers[$rootIndex]['wms_id'];
- $this->wmsJSON->wms->srv[$i-$j]->title = $subLayers[$rootIndex]['wms_title'];
- $this->wmsJSON->wms->srv[$i-$j]->abstract = $subLayers[$rootIndex]['wms_abstract'];
- $this->wmsJSON->wms->srv[$i-$j]->date = date("d.m.Y",$subLayers[$rootIndex]['wms_timestamp']);
- $this->wmsJSON->wms->srv[$i-$j]->respOrg = $subLayers[$rootIndex]['mb_group_name'];
- $this->wmsJSON->wms->srv[$i-$j]->loadCount = $subLayers[$rootIndex]['load_count'];
- $this->wmsJSON->wms->srv[$i-$j]->mdLink = $_SERVER['HOSTNAME']."/mapbender/x_geoportal/mod_layerMetadata.php?id=".$rootLayerId;
+ $this->wmsJSON->wms->srv[$j]->id = (integer)$subLayers[$rootIndex]['wms_id'];
+ $this->wmsJSON->wms->srv[$j]->title = $subLayers[$rootIndex]['wms_title'];
+ $this->wmsJSON->wms->srv[$j]->abstract = $subLayers[$rootIndex]['wms_abstract'];
+ $this->wmsJSON->wms->srv[$j]->date = date("d.m.Y",$subLayers[$rootIndex]['wms_timestamp']);
+ $this->wmsJSON->wms->srv[$j]->respOrg = $subLayers[$rootIndex]['mb_group_name'];
+ $this->wmsJSON->wms->srv[$j]->loadCount = (integer)$subLayers[$rootIndex]['load_count'];
+ $this->wmsJSON->wms->srv[$j]->mdLink = "http://".$_SERVER['HTTP_HOST']."/mapbender/x_geoportal/mod_layerMetadata.php?id=".$rootLayerId;
$spatialSource = "";
$stateOrProvince = $wmsMatrix[$i]['administrativearea'];
if ($stateOrProvince == "NULL" || $stateOrProvince == "") {
@@ -405,41 +423,82 @@
} else {
$spatialSource = $wmsMatrix[$i]['administrativearea'];
}
- $this->wmsJSON->wms->srv[$i-$j]->iso3166 = $spatialSource;
- $this->wmsJSON->wms->srv[$i-$j]->respOrg = $subLayers[$rootIndex]['mb_group_name'];
- $this->wmsJSON->wms->srv[$i-$j]->tou = $subLayers[$rootIndex]['termsofuse'];
+ $this->wmsJSON->wms->srv[$j]->iso3166 = $spatialSource;
+ $this->wmsJSON->wms->srv[$j]->respOrg = $subLayers[$rootIndex]['mb_group_name'];
+ $this->wmsJSON->wms->srv[$j]->tou = $subLayers[$rootIndex]['termsofuse'];
//TODO check the field accessconstraints - which should be presented?
- $this->wmsJSON->wms->srv[$i-$j]->status = $subLayers[$rootIndex]['status']; //$wmsMatrix[$i][''];
- $this->wmsJSON->wms->srv[$i-$j]->avail = $subLayers[$rootIndex]['availability']; //$wmsMatrix[$i][''];
- $this->wmsJSON->wms->srv[$i-$j]->logged = NULL; //$wmsMatrix[$i][''];
- $this->wmsJSON->wms->srv[$i-$j]->price = NULL; //$wmsMatrix[$i][''];
- $this->wmsJSON->wms->srv[$i-$j]->nwaccess = NULL; //$wmsMatrix[$i][''];
- $this->wmsJSON->wms->srv[$i-$j]->bbox = $subLayers[$rootIndex]['bbox']; //$wmsMatrix[$i][''];
+ $this->wmsJSON->wms->srv[$j]->status = $subLayers[$rootIndex]['status']; //$wmsMatrix[$i][''];
+ $this->wmsJSON->wms->srv[$j]->avail = $subLayers[$rootIndex]['availability']; //$wmsMatrix[$i][''];
+ //get info about defined price
+ if ($subLayers[$rootIndex]['wms_pricevolume'] == '' OR $subLayers[$rootIndex]['wms_pricevolume'] == 0){
+ $this->wmsJSON->wms->srv[$j]->price = NULL;
+ }
+ else {
+ $this->wmsJSON->wms->srv[$j]->price = $subLayers[$rootIndex]['wms_pricevolume'];
+ }
+ //get info about logging of resource
+ if ($subLayers[$rootIndex]['wms_proxylog'] == NULL OR $subLayers[$rootIndex]['wms_proxylog'] == 0){
+ $this->wmsJSON->wms->srv[$j]->logged = false;
+ }
+ else {
+ $this->wmsJSON->wms->srv[$j]->logged = true;
+ }
+ //get info about network_accessability
+ if ($subLayers[$rootIndex]['wms_network_access'] == NULL OR $subLayers[$rootIndex]['wms_network_access'] == 0){
+ $this->wmsJSON->wms->srv[$j]->nwaccess = false;
+ }
+ else {
+ $this->wmsJSON->wms->srv[$j]->nwaccess = true;
+ }
+
+ $this->wmsJSON->wms->srv[$j]->logged = NULL; //$wmsMatrix[$i][''];
+ $this->wmsJSON->wms->srv[$j]->price = NULL; //$wmsMatrix[$i][''];
+ $this->wmsJSON->wms->srv[$j]->nwaccess = NULL; //$wmsMatrix[$i][''];
+ $this->wmsJSON->wms->srv[$j]->bbox = $subLayers[$rootIndex]['bbox']; //$wmsMatrix[$i][''];
//Call recursively the child elements, give and pull $layerIdArray to push the done elements in the array to avoid double results
#print_r($subLayers);
- //generate the layer-entry for the so called root layer
- $this->wmsJSON->wms->srv[$i-$j]->layer = array();
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->id = $subLayers[$rootIndex]['layer_id'];
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->title = $subLayers[$rootIndex]['layer_title'];
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->abstract = $subLayers[$rootIndex]['layer_abstract'];
+ //generate the layer-entry for the so called root layer - maybe this is only a group layer if there is a gap in the layer hierachy
+ $this->wmsJSON->wms->srv[$j]->layer = array();
+ $this->wmsJSON->wms->srv[$j]->layer[0]->id = (integer)$subLayers[$rootIndex]['layer_id'];
+ $this->wmsJSON->wms->srv[$j]->layer[0]->title = $subLayers[$rootIndex]['layer_title'];
+ $this->wmsJSON->wms->srv[$j]->layer[0]->abstract = $subLayers[$rootIndex]['layer_abstract'];
if ($subLayers[$rootIndex]['layer_name'] == ''){
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->loadable = 0;
+ $this->wmsJSON->wms->srv[$j]->layer[0]->loadable = 0;
}
else {
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->loadable = 1;
+ $this->wmsJSON->wms->srv[$j]->layer[0]->loadable = 1;
}
+ //give info for inspire categories - not relevant for other services or instances of mapbender TODO: comment it if the mapbender installation is not used to generate inspire output
+ if ($subLayers[$rootIndex]['md_inspire_cats'] == ''){
+ $this->wmsJSON->wms->srv[$j]->layer[0]->inspire = 0;
+ }
+ else {
+ $this->wmsJSON->wms->srv[$j]->layer[0]->inspire = 1;
+ }
+ //get info about queryable or not
+ if ($subLayers[$rootIndex]['layer_queryable'] == 1){
+ $this->wmsJSON->wms->srv[$j]->layer[0]->queryable = 1;
+ }
+ else {
+ $this->wmsJSON->wms->srv[$j]->layer[0]->queryable = 0;
+ }
+
#if ($subLayers[$rootIndex]['layer_name'] == ''){
# $this->wmsJSON->wms->srv[$i-$j]->layer[0]->loadable = 0;
#}
#else {
# $this->wmsJSON->wms->srv[$i-$j]->layer[0]->loadable = 1;
#}
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->loadCount = $subLayers[$rootIndex]['load_count'];
+ $this->wmsJSON->wms->srv[$j]->layer[0]->loadCount = $subLayers[$rootIndex]['load_count'];
#$servObject->layer[$countsublayer]->mdLink = $_SERVER['HOST']."/mapbender/x_geoportal/showWFeatureTypeMetadata.php?id=".$wfsMatrix[$i]['featuretype_id'];
#$servObject->layer[$countsublayer]->geomtype = $wfsMatrix[$i]['element_type'];
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->bbox = $subLayers[$rootIndex]['bbox'];
- $this->wmsJSON->wms->srv[$i-$j]->layer[0]->permission = $this->getPermissionValueForLayer($subLayers[$rootIndex]['wms_id'], $subLayers[$rootIndex]['layer_id']);
- $layerIdArray = $this->writeWMSChilds($layerIdArray, $rootLayerPos, $subLayers, $i, $j, $this->wmsJSON->wms->srv[$i-$j]->layer[0]);
+ $this->wmsJSON->wms->srv[$j]->layer[0]->bbox = $subLayers[$rootIndex]['bbox'];
+ $this->wmsJSON->wms->srv[$j]->layer[0]->permission = $this->getPermissionValueForLayer($subLayers[$rootIndex]['layer_id'], $subLayers[$rootIndex]['wms_id']); //TODO: Make this much more faster
+ //when the entry for the first server has been written, the server entry is fixed and the next one will be a new server or a part of the old one.
+ //increment server (highest object id)
+
+ $layerIdArray = $this->writeWMSChilds($layerIdArray, $rootLayerPos, $subLayers, $this->wmsJSON->wms->srv[$j]->layer[0]);
+ $j++;
//generate php object - if root layer was found - > layer_parent='' give hint to visualize folder symbol.
}
}
@@ -454,6 +513,9 @@
if ($this->outputFormat == 'json'){
//generate json
$this->generateWMSMetadataJSON($res,$n);
+ $usedTime = $this->microtime_float() - $starttime;
+ //put in the time to generate the data
+ $this->wmsJSON->wms->md->genTime = $usedTime;
$this->wmsJSON = $this->json->encode($this->wmsJSON);
if ($this->resultTarget == 'file') {
if($wmsFileHandle = fopen($this->tempFolder."/".$this->searchId."_".$this->searchResources."_".$this->searchPages.".json","w")){
@@ -465,8 +527,9 @@
echo $this->wmsJSON;
}
}
- $usedTime = $this->microtime_float() - $starttime;
- $e = new mb_exception("Time to generate WMS-Metadata: ".$usedTime);
+ $usedTime2 = $this->microtime_float() - $starttime;
+ //echo "<br>used time: ".$usedTime."<br>";
+ $e = new mb_exception("Time to generate WMS-Metadata: ".$usedTime2);
$e = new mb_exception("Wrote the MD_WMS-File");
}
@@ -1001,18 +1064,23 @@
return $return_permission;
}
- private function getPermissionValueForLayer($wms_id, $layer_id){
+ private function getPermissionValueForLayer($layerId,$wmsId){
//TODO: Set Email of owner into view for ressource - so it don't have to be searched?
$return_permission="";
- $admin = new administration();
- $permission = $admin->getLayerPermission($wms_id, $layer_id, $this->userId);
- if ($permission){
+ #$admin = new administration();
+ #$permission = $admin->getLayerPermission($wms_id, $layer_name, $this->userId);
+ #echo "<br>wms_id: ".$wms_id."<br>";
+ #echo "<br>layer_name: ".$layer_name."<br>";
+ #echo "<br>user_id: ".$this->userId."<br>";
+ #echo "<br>Permission: ".$permission."<br>";
+ # var_dump($this->accessableLayers);
+ if (in_array($layerId, $this->accessableLayers)){
$return_permission = "true";
return $return_permission;
} else {
- $sql = "SELECT wms.wms_id, mb_user.mb_user_email as email FROM wms, mb_user WHERE wms.wms_owner=mb_user.mb_user_id";
+ $sql = "SELECT mb_user.mb_user_email as email FROM wms, mb_user WHERE wms.wms_owner=mb_user.mb_user_id";
$sql .= " AND wms.wms_id=$1";
- $v = array($wms_id);
+ $v = array($wmsId);
$t = array('i');
$res = db_prep_query($sql, $v, $t);
// get email
@@ -1070,7 +1138,15 @@
#var_dump($layerArray);
$layerIDKey = $layerArray['layer_id'][$index];
#echo ("layerIDKey= ".$layerIDKey."<br>");
- $layerParentPos = $layerArray['layer_parent'][$index];
+ $layerParentPos = $layerArray['layer_parent'][$index];//get first parent object position
+ #echo ("layerParentPos= ".$layerParentPos."<br>");
+ #echo("<br>number of sublayers ".count(flipDiagonally($layerArray))."<br>");
+ #echo("<br>size of layerArray['layer_pos']: ".count($layerArray['layer_pos'])."<br>");
+ #var_dump($layerArray['layer_pos']);
+ #echo "<br>flipped layerArray: <br> ";
+ #var_dump(flipDiagonally($layerArray));
+ #echo "<br>";
+
if ($layerParentPos == '') {
//root layer directly found
return $index;
@@ -1078,21 +1154,25 @@
#echo ("layerParentPos= ".$layerParentPos."<br>");
//Initialize index of layer parent - first it references the layer itself
$layerParentIndex = $index;
- for ($i=0; $i<count($layerArray);$i++) {
+ //loop to search higher parent objects - maybe this can be faster if the loop is not used over all sublayer elements! Do a while loop instead!
+ $highestParentLayerNotFound = true;
+ while ($highestParentLayerNotFound) {
#echo("<br>i= ".$i."<br>");
- #echo("<br>layerParentPos= ".$layerParentPos."<br>");
- $layerParentIndexNew = array_search($layerParentPos, $layerArray['layer_pos']);
+ #echo("<br>layerParentPosNew= ".$layerParentPos."<br>");
+ $layerParentIndexNew = array_search((string)$layerParentPos, $layerArray['layer_pos']);
#echo("<br>layerParentIndexNew= ".$layerParentIndexNew."<br>");
if ($layerParentIndexNew != false) {
- //one parent has been found
+ //some parent has been found
$layerParentIndex = $layerParentIndexNew;
$layerParentPos = $layerArray['layer_parent'][$layerParentIndex];
if ($layerParentPos == '') {
- return $layerParentIndex;
+ $highestParentLayerNotFound = false;
+ return $layerParentIndex; //a real root layer was found!
}
+
#$layerParentIndex = array_search($layerParentPos, $layerArray['layer_pos']);
} else {
- #$layerParentIndex = $index; //no parent has been found
+ $highestParentLayerNotFound = false; //no higher layer could be found
return $layerParentIndex;
}
}
@@ -1101,19 +1181,20 @@
//function to write the child elements to the resulting wms object -> object is given by reference
- private function writeWMSChilds($layerIdArray, $rootLayerPos, $subLayers, $i, $j, &$servObject) {
+ private function writeWMSChilds($layerIdArray, $rootLayerPos, $subLayers, &$servObject) {
#echo "test";
#echo "<br>subLayers:<br>";
#var_dump($subLayers);
#echo "<br>";
- $childLayers = $this->filter_by_value($subLayers, 'layer_parent', $rootLayerPos); //TODO anpassen
+ $childLayers = $this->filter_by_value($subLayers, 'layer_parent', $rootLayerPos); //the root layer position in the sublayer array was located before. In this step, all layers will be pulled out of sublayer, where root layer position is parent object
#echo "<br<childLayers:<br>";
#var_dump($childLayers);
+ #echo "<br>";
#echo "test";
#print_r($childLayers);
#print_r($childLayers);
$countsublayer = 0;
- //if child exists create a array for these
+ //if child exists create a new layer array for these
if (count($childLayers) != 0) {
$servObject->layer = array();
}
@@ -1124,18 +1205,32 @@
$servObject->layer[$countsublayer]->id = $child['layer_id'];
$servObject->layer[$countsublayer]->title = $child['layer_title'];
$servObject->layer[$countsublayer]->abstract = $child['layer_abstract'];
+ $servObject->layer[$countsublayer]->mdLink = "http://".$_SERVER['HTTP_HOST']."/mapbender/x_geoportal/mod_layerMetadata.php?id=".$child['layer_id'];
if ($child['layer_name'] == ''){
$servObject->layer[$countsublayer]->loadable = 0;
} else {
$servObject->layer[$countsublayer]->loadable = 1;
}
+ //give info for inspire categories - not relevant for other services or instances of mapbender TODO: comment it if the mapbender installation is not used to generate inspire output
+ if ($child['md_inspire_cats'] == ''){
+ $servObject->layer[$countsublayer]->inspire = 0;
+ }
+ else {
+ $servObject->layer[$countsublayer]->inspire = 1;
+ }
+ //get info about queryable or not
+ if ($child['layer_queryable'] == 1){
+ $servObject->layer[$countsublayer]->queryable = 1;
+ }
+ else {
+ $servObject->layer[$countsublayer]->queryable = 0;
+ }
+
$servObject->layer[$countsublayer]->loadCount = $child['load_count'];
- #$servObject->layer[$countsublayer]->mdLink = $_SERVER['HOST']."/mapbender/x_geoportal/showWFeatureTypeMetadata.php?id=".$wfsMatrix[$i]['featuretype_id'];
- #$servObject->layer[$countsublayer]->geomtype = $wfsMatrix[$i]['element_type'];
$servObject->layer[$countsublayer]->bbox = $child['bbox'];
- $servObject->layer[$countsublayer]->permission = $this->getPermissionValueForLayer($child['wms_id'], $$child['layer_id']);
- //call this function itself
- $layerIdArray = $this->writeWMSChilds($layerIdArray, $child['layer_pos'], $subLayers, $i, $j, $servObject->layer[$countsublayer]);//TODO create a timeout condition !
+ $servObject->layer[$countsublayer]->permission = $this->getPermissionValueForLayer($child['layer_id'],$child['wms_id']); //TODO: make this much faster!!!! - is done by collecting all accessable resources once. Maybe this has to be adopted if the count of the resources become higher
+ //call this function itself - search sublayers in the layer object.
+ $layerIdArray = $this->writeWMSChilds($layerIdArray, $child['layer_pos'], $subLayers, $servObject->layer[$countsublayer]);//TODO create a timeout condition !
array_push($layerIdArray, $child['layer_id']); //child have been identified and recursively written
#var_dump($layerIdArray);#
#echo "<br>";
More information about the Mapbender_commits
mailing list