[Mapbender-commits] r4981 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Nov 13 07:59:31 EST 2009


Author: christoph
Date: 2009-11-13 07:59:30 -0500 (Fri, 13 Nov 2009)
New Revision: 4981

Modified:
   trunk/mapbender/http/classes/class_wmc.php
Log:


Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2009-11-13 11:00:28 UTC (rev 4980)
+++ trunk/mapbender/http/classes/class_wmc.php	2009-11-13 12:59:30 UTC (rev 4981)
@@ -246,11 +246,11 @@
 		$wmcArray = array();
 		
 		// get WMC ids 
-		$wmcIdArray = $user->getWmcByOwner();
+		$wmcOwnerArray = $user->getWmcByOwner();
 		
 		$publicWmcIdArray = $this->getPublicWmcIds($user->id);
 		
-		$wmcIdArray = array_keys( array_flip(array_merge($wmcIdArray, $publicWmcIdArray)));
+		$wmcIdArray = array_keys( array_flip(array_merge($wmcOwnerArray, $publicWmcIdArray)));
 
 		// get WMC data
 		$v = array();
@@ -279,7 +279,9 @@
 				$currentResult["timestamp"] = date("M d Y H:i:s", $row["wmc_timestamp"]); 
 				$currentResult["timestamp_create"] = date("M d Y H:i:s", $row["wmc_timestamp_create"]); 
 				$currentResult["isPublic"] = $row["wmc_public"] == 1? true: false;
-				$currentResult["disabled"] = (in_array($currentResult["id"], $publicWmcIdArray)) ?
+				$currentResult["disabled"] = ((
+					in_array($currentResult["id"], $publicWmcIdArray) && 
+					!in_array($currentResult["id"], $wmcOwnerArray)) || $user->isPublic()) ?
 					true : false;
 				array_push($wmcArray, $currentResult);
 			}
@@ -287,6 +289,143 @@
 		return $wmcArray;
 	}
 
+    private function compareWms ($a, $b) {
+		if ($a["id"] === $b["id"]) return 0;
+        return -1;
+    }
+	public function getAllWms () {
+		$wmsArray = $this->mainMap->getWmsArray();
+		$resultObj = array();
+		$usedIds = array();
+		for ($i = 0; $i < count($wmsArray); $i++) {
+			if (in_array($wmsArray[$i]->wms_id, $usedIds)) {
+				continue;
+			}
+			$resultObj[]= array(
+				"title" => $wmsArray[$i]->wms_title, 
+				"id" => is_null($wmsArray[$i]->wms_id) ? null : intval($wmsArray[$i]->wms_id),
+				"index" => $i
+			);
+			$usedIds[]= $wmsArray[$i]->wms_id;
+		}
+		return $resultObj;	
+	}
+
+	public function getWmsWithoutId () {
+		$wmsArray = $this->getAllWms();		
+		$resultObj = array();
+		
+		for ($i = 0; $i < count($wmsArray); $i++) {
+			if (is_numeric($wmsArray[$i]["id"])) {
+				continue;
+			}
+			$resultObj[]= array(
+				"title" => $wmsArray[$i]["title"], 
+				"id" => $wmsArray[$i]["id"],
+				"index" => $i
+			);
+		}
+		return $resultObj;	
+	}
+	
+	public function getWmsWithId () {
+		return array_values(array_udiff(
+			$this->getAllWms(), 
+			$this->getWmsWithoutId(),
+			array("wmc", "compareWms")
+		));
+	}
+	
+	public function getValidWms () {
+		$inv = $this->getInvalidWms();
+		$withId = $this->getWmsWithId();
+		return array_values(array_udiff(
+			$withId, 
+			$inv,
+			array("wmc", "compareWms")
+		));
+	}
+	
+	public function getInvalidWms () {
+		$resultObj = array();
+
+		$wmsArray = $this->getWmsWithId();
+		for ($i = 0; $i < count($wmsArray); $i++) {
+			
+			$sql = "SELECT COUNT(wms_id) FROM wms WHERE wms_id = $1";
+			$v = array($wmsArray[$i]["id"]);
+			$t = array('i');
+			$res = db_prep_query($sql, $v, $t);
+			$layerRow = db_fetch_row($res);
+			if (intval($layerRow[0]) === 0) {
+				$resultObj[]= array(
+					"title" => $wmsArray[$i]["title"], 
+					"id" => intval($wmsArray[$i]["id"]),
+					"index" => $wmsArray[$i]["index"]
+				);
+			}		
+		}
+		return $resultObj;
+	}
+	
+	public function getWmsWithPermission ($user) {
+		$wmsArray = $this->getValidWms();		
+		$resultObj = array();
+
+		for ($i = 0; $i < count($wmsArray); $i++) {
+			$currentWmsId = $wmsArray[$i]["id"];
+
+			if ($user->isWmsAccessible($currentWmsId)) {
+				$resultObj[]= array(
+					"title" => $wmsArray[$i]["title"], 
+					"id" => $currentWmsId,
+					"index" => $wmsArray[$i]["index"]
+				);
+			}			
+		}
+		return $resultObj;	
+	}
+	
+	public function getWmsWithoutPermission ($user) {
+		return array_values(array_udiff(
+			$this->getValidWms(), 
+			$this->getWmsWithPermission($user),
+			array("wmc", "compareWms")
+		));
+	}
+	
+	public function getAvailableWms ($user) {
+		return array_values(array_udiff(
+			$this->getWmsWithPermission($user), 
+			$this->getUnavailableWms(),
+			array("wmc", "compareWms")
+		));
+	}
+	
+	public function getUnavailableWms ($user) {
+		$wmsArray = $this->getWmsWithPermission($user);
+		$resultObj = array();
+		
+		for ($i = 0; $i < count($wmsArray); $i++) {
+			$currentWmsId = $wmsArray[$i]["id"];
+
+			$sql = "SELECT last_status FROM mb_wms_availability WHERE fkey_wms_id = $1"; 
+			$v = array($currentWmsId);
+			$t = array("i");
+			$res = db_prep_query($sql, $v, $t);
+			$statusRow = db_fetch_row($res);
+			$status = intval($statusRow[0]);
+			if (isset($status) && $status < 0) {
+				$resultObj[]= array(
+					"title" => $wmsArray[$i]["title"], 
+					"id" => $currentWmsId,
+					"index" => $wmsArray[$i]["index"]
+				);
+			}
+		}
+		return $resultObj;		
+	}
+
 	public function updateUrlsFromDb () {
 		$query_mbWMSId = "/wmc:ViewContext/wmc:LayerList/wmc:Layer/wmc:Extension/mapbender:wms_id";
 		
@@ -688,6 +827,11 @@
 			}
 		}
 */		
+		$skipWmsArray = array();
+		if (func_num_args() === 1) {
+			$skipWmsArray = func_get_arg(0);
+		}
+
 		// will contain the JS code to create the maps
 		// representing the state stored in this WMC
 		$wmcJsArray = array();
@@ -714,7 +858,7 @@
 			$overviewWmsIndex = 0;
 			for ($i = 0; $i < count($ovWmsArray); $i++) {
 				for ($j = 0; $j < count($wmsArray); $j++) {
-					if ($ovWmsArray[$i]->equals($wmsArray[$j])) {
+					if ($ovWmsArray[$i]->equals($wmsArray[$j]) && !in_array($j, $skipWmsArray)) {
 						$overviewWmsIndex = $j;	
 						$wmsIndexOverview = $i;					
 						break;
@@ -725,6 +869,9 @@
 
 		// for all wms...
 		for ($i = 0; $i < count($wmsArray); $i++) {
+			if (in_array($i, $skipWmsArray)) {
+				continue;
+			}
 			array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
 		}
 



More information about the Mapbender_commits mailing list