[Mapbender-commits] r6994 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Oct 1 09:24:00 EDT 2010


Author: christoph
Date: 2010-10-01 13:24:00 +0000 (Fri, 01 Oct 2010)
New Revision: 6994

Modified:
   trunk/mapbender/http/javascripts/initWmcObj.php
Log:
added function removeWms

formatting

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2010-10-01 13:21:29 UTC (rev 6993)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2010-10-01 13:24:00 UTC (rev 6994)
@@ -10,14 +10,18 @@
 require_once dirname(__FILE__)."/../classes/class_elementVar.php";
 
 function getConfiguration ($key) {
-	//check if key param can be found in SESSION,
-	// otherwise take it from GET
+//check if key param can be found in SESSION,
+// otherwise take it from GET
 	if (Mapbender::session()->exists($key)) {
 		return Mapbender::session()->get($key);
 	}
 	return $_GET[$key];
 }
 
+//
+// Load WMC from session or application
+//
+
 $wmc = new wmc();
 
 $app = Mapbender::session()->get("mb_user_gui");
@@ -26,8 +30,8 @@
 try {
 	$loadFromSession = new ElementVar($app, "loadwmc", "loadFromSession");
 	if ($loadFromSession->value === "1") {
-		//check if session contains a wmc,
-		//otherwise create a new wmc from application
+	//check if session contains a wmc,
+	//otherwise create a new wmc from application
 		$e = new mb_notice("trying to load session WMC...");
 		if (!$wmc->createFromXml($wmcDocSession)) {
 			$e = new mb_notice("loading session WMC failed.");
@@ -46,6 +50,11 @@
 	$wmc->createFromApplication($app);
 }
 
+//
+// create new WMC with services from GET API
+//
+$wmcGetApi = WmcFactory::createFromXml($wmc->toXml());
+
 $options = array();
 if (Mapbender::session()->exists("addwms_showWMS")) {
 	$options["show"] = intval(Mapbender::session()->get("addwms_showWMS"));
@@ -62,13 +71,15 @@
 );
 $getApi = new GetApi($getParams);
 
-
+//
+// WMC
+//
 $inputWmcArray = $getApi->getWmc();
 if ($inputWmcArray) {
 	foreach ($inputWmcArray as $input) {
-		// just make it work for a single Wmc
+	// just make it work for a single Wmc
 		try {
-			$wmc = WmcFactory::createFromDb($input["id"]);
+			$wmcGetApi = WmcFactory::createFromDb($input["id"]);
 		}
 		catch (Exception $e) {
 			new mb_exception("Failed to load WMC from DB. Keeping original WMC.");
@@ -76,29 +87,32 @@
 	}
 }
 
+//
+// WMS
+//
 if ($getParams['WMS']) {
-	// WMS param given as array
+// WMS param given as array
 	if (is_array($getParams['WMS'])) {
 		$inputWmsArray = $getParams['WMS'];
 	}
 	// WMS param given as comma separated list
 	else {
-		$inputWmsArray = split(",",$getParams['WMS']); 
+		$inputWmsArray = split(",",$getParams['WMS']);
 	}
-	
+
 	$wmsArray = array();
 	$singleAssocArray = array();
 	$multipleAssocArray = array();
-	
+
 	foreach ($inputWmsArray as $key=>$val) {
 		if (is_array($val)) {
 			foreach ($val as $attr=>$value) {
 				$multipleAssocArray[$attr] = $value;
 			}
 			//get WMS by ID with settings of given application
-			if (array_key_exists('application', $multipleAssocArray) && 
+			if (array_key_exists('application', $multipleAssocArray) &&
 				array_key_exists('id', $multipleAssocArray)) {
-				$currentWms = new wms();	
+				$currentWms = new wms();
 				$currentWms->createObjFromDB(
 					$multipleAssocArray['application'],
 					$multipleAssocArray['id']
@@ -113,21 +127,21 @@
 				continue;
 			}
 			array_push($wmsArray, $currentWms);
-			
+
 			$options['visible'] = $multipleAssocArray['visible'] === "1" ?
 				true : false;
 
 			$options['zoom'] = $multipleAssocArray['zoom'] === "1" ?
 				true : false;
-			
-			$wmc->mergeWmsArray($wmsArray, $options);
+
+			$wmcGetApi->mergeWmsArray($wmsArray, $options);
 			$wmsArray = array();
 			$multipleAssocArray = array();
 		}
 		else {
 			$currentWms = new wms();
 			if(is_numeric($key)) {
-				//get WMS by URL
+			//get WMS by URL
 				if (is_string($val)) {
 					$currentWms->createObjFromXML($val);
 				}
@@ -136,19 +150,19 @@
 					$currentWms->createObjFromDBNoGui($val);
 				}
 				array_push($wmsArray, $currentWms);
-				$wmc->mergeWmsArray($wmsArray);
+				$wmcGetApi->mergeWmsArray($wmsArray);
 				$wmsArray = array();
-			} 
+			}
 			else {
 				$singleAssocArray[$key] = $val;
 			}
 		}
 	}
-	
+
 	//get WMS by ID with settings of given application
-	if (array_key_exists('application', $singleAssocArray) && 
+	if (array_key_exists('application', $singleAssocArray) &&
 		array_key_exists('id', $singleAssocArray)) {
-		$currentWms = new wms();	
+		$currentWms = new wms();
 		$currentWms->createObjFromDB(
 			$singleAssocArray['application'],
 			$singleAssocArray['id']
@@ -156,10 +170,10 @@
 		array_push($wmsArray, $currentWms);
 		$options['visible'] = $singleAssocArray['visible'] === "1" ?
 			true : false;
-		
+
 		$options['zoom'] = $singleAssocArray['zoom'] === "1" ? true : false;
 
-		$wmc->mergeWmsArray($wmsArray, $options);
+		$wmcGetApi->mergeWmsArray($wmsArray, $options);
 		$wmsArray = array();
 		$singleAssocArray = array();
 	}
@@ -176,16 +190,20 @@
 			$options['zoom'] = $singleAssocArray['zoom'] === "1" ?
 				true : false;
 		}
-		$wmc->mergeWmsArray($wmsArray, $options);
+		$wmcGetApi->mergeWmsArray($wmsArray, $options);
 		$wmsArray = array();
 		$singleAssocArray = array();
 	}
 }
 
+//
+// LAYER
+//
+
 $inputLayerArray = $getApi->getLayers();
 if ($inputLayerArray) {
 	foreach ($inputLayerArray as $input) {
-		// just make it work for a single layer id
+	// just make it work for a single layer id
 		$wmsFactory = new UniversalWmsFactory();
 		if (isset($input["application"])) {
 			$wms = $wmsFactory->createLayerFromDb(
@@ -197,65 +215,164 @@
 		}
 		$options = array();
 		if ($input["visible"]) {
-			// this is a hack for the time being:
-			// make WMS visible if it has less than 100000 layers
+		// this is a hack for the time being:
+		// make WMS visible if it has less than 100000 layers
 			$options["show"] = 100000;
 		}
 		if (isset($input["querylayer"])) {
 			$options["querylayer"] = $input["querylayer"];
 		}
-		$wmc->mergeWmsArray(array($wms), $options);
+		$wmcGetApi->mergeWmsArray(array($wms), $options);
 
 		// do not use "zoom" attribute of mergeWmsArray,
 		// as this would zoom to the entre WMS.
 		// Here we set extent to the layer extent only.
 		if ($input["zoom"]) {
-				$bboxArray = array();
-				try {
-					$layer = $wms->getLayerById(intval($input["id"]));
-					for ($i = 0; $i < count($layer->layer_epsg); $i++) {
-						$bboxArray[]= Mapbender_bbox::createFromLayerEpsg(
-							$layer->layer_epsg[$i]
-						);
-					}
-					$wmc->mainMap->mergeExtent($bboxArray);
+			$bboxArray = array();
+			try {
+				$layer = $wms->getLayerById(intval($input["id"]));
+				for ($i = 0; $i < count($layer->layer_epsg); $i++) {
+					$bboxArray[]= Mapbender_bbox::createFromLayerEpsg(
+						$layer->layer_epsg[$i]
+					);
 				}
-				catch (Exception $e) {
-					
-				}
+				$wmcGetApi->mainMap->mergeExtent($bboxArray);
+			}
+			catch (Exception $e) {
+
+			}
 		}
 	}
 }
 
+//
+// FEATURETYPE
+//
 $inputFeaturetypeArray = $getApi->getFeaturetypes();
 if ($inputFeaturetypeArray) {
-	$wfsConfIds = array();	
+	$wfsConfIds = array();
 	foreach ($inputFeaturetypeArray as $input) {
 		array_push($wfsConfIds, $input["id"]);
 	}
-	
-	$wmc->generalExtensionArray['WFSCONFIDSTRING'] = implode(",", array_merge(
-		$wmc->generalExtensionArray['WFSCONFIDSTRING'] ? 
-			explode(",", $wmc->generalExtensionArray['WFSCONFIDSTRING']) :
-			array(),
+
+	$wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'] = implode(",", array_merge(
+		$wmcGetApi->generalExtensionArray['WFSCONFIDSTRING'] ?
+		explode(",", $wmcGetApi->generalExtensionArray['WFSCONFIDSTRING']) :
+		array(),
 		$wfsConfIds
 	));
 }
 
 //workaround to have a fully merged WMC for loading
 
-$xml = $wmc->toXml();
+$xml = $wmcGetApi->toXml();
 
-$wmc = new wmc();
-$wmc->createFromXml($xml);
+$wmcGetApi = new wmc();
+$wmcGetApi->createFromXml($xml);
 
-$output = $wmc->wmsToJavaScript();
 
-//workaround for zoom to WMS
-$extent = $wmc->mainMap->getExtent();
-Mapbender::session()->set("mb_myBBOX", $extent->min->x . "," .
-	$extent->min->y . "," . $extent->max->x . "," . $extent->max->y);
 
+//
+// CONSTRAINTS
+//
+$resultObj = array();
+
+$currentUser = new User();
+
+// remove all WMS with no permission
+$deniedIdsArray = $wmcGetApi->getWmsWithoutPermission($currentUser);
+$deniedIdsTitles = array();
+$deniedIdsIndices = array();
+foreach ($deniedIdsArray as $i) {
+	$deniedIdsTitles[]= array(
+		"id" => $i["id"],
+		"index" => $i["index"],
+		"title" => $i["title"]
+	);
+	$deniedIdsIndices[]= $i["index"];
+}
+$resultObj["noPermission"] = array(
+	"message" => "Sie als Nutzer '" .
+	Mapbender::session()->get("mb_user_name") . "' " .
+	"haben keine Berechtigung auf folgende Layer zuzugreifen.",
+	"wms" => $deniedIdsTitles
+);
+$wmcGetApi->removeWms($deniedIdsIndices);
+
+// find WMS without ID
+$withoutIdsArray = $wmcGetApi->getWmsWithoutId();
+$withoutIdsTitles = array();
+foreach ($withoutIdsArray as $i) {
+	$withoutIdsTitles[]= array(
+		"id" => $i["id"],
+		"index" => $i["index"],
+		"title" => $i["title"]
+	);
+}
+$resultObj["withoutId"] = array(
+	"message" => "Folgende Layer stammen aus einer dem " .
+	"Geoportal.rlp unbekannten Quelle. Es kann daher nicht " .
+	"überprüft werden, ob die Links verwaist sind oder ob " .
+	"die Dienste überhaupt Daten liefern.",
+	"wms" => $withoutIdsTitles
+);
+
+// find orphaned WMS
+$invalidIdsArray = $wmcGetApi->getInvalidWms();
+$invalidIdsTitles = array();
+foreach ($invalidIdsArray as $i) {
+	$invalidIdsTitles[]= array(
+		"id" => $i["id"],
+		"index" => $i["index"],
+		"title" => $i["title"]
+	);
+}
+$resultObj["invalidId"] = array(
+	"message" => "Folgende Dienste/Layer sind aus der " .
+	"Registrierungsstelle gelöscht worden. Es kann daher nicht " .
+	"überprüft werden, ob die Links verwaist sind oder ob " .
+	"die Dienste überhaupt Daten liefern.",
+	"wms" => $invalidIdsTitles
+);
+
+// find potentially unavailable WMS
+$unavailableIdsArray = $wmcGetApi->getUnavailableWms($currentUser);
+$unavailableIdsTitles = array();
+foreach ($unavailableIdsArray as $i) {
+	$unavailableIdsTitles[]= array(
+		"id" => $i["id"],
+		"index" => $i["index"],
+		"title" => $i["title"]
+	);
+}
+$resultObj["unavailable"] = array(
+	"message" => "Bei folgenden Diensten kam es während " .
+	"des letzten Monitorings zu Problemen. Es ist möglich, dass " .
+	"diese Dienste derzeit keine Informationen zur Verfügung stellen " .
+	"können.",
+	"wms" => $unavailableIdsTitles
+);
+
+//
+// Output
+//
+
+Mapbender::session()->set("wmcGetApi", $wmcGetApi);
+if (
+	count($resultObj["withoutId"]["wms"]) === 0 &&
+	count($resultObj["invalidId"]["wms"]) === 0 &&
+	count($resultObj["unavailable"]["wms"]) === 0
+) {
+	Mapbender::session()->set("wmcConstraints", $resultObj);
+	$output = $wmcGetApi->wmsToJavaScript();
+
+}
+else {
+	Mapbender::session()->set("wmcConstraints", $resultObj);
+	$output = $wmc->wmsToJavaScript();
+}
+
+
 $outputString = "";
 for ($i = 0; $i < count($output); $i++) {
 	$outputString .= administration::convertOutgoingString($output[$i]);
@@ -275,6 +392,12 @@
 echo $outputString;
 
 
+//workaround for zoom to WMS
+//$extent = $wmc->mainMap->getExtent();
+//Mapbender::session()->set("mb_myBBOX", $extent->min->x . "," .
+//	$extent->min->y . "," . $extent->max->x . "," . $extent->max->y);
+
+
 Mapbender::session()->delete("addwms_showWMS");
 Mapbender::session()->delete("addwms_zoomToExtent");
 unset($output);



More information about the Mapbender_commits mailing list