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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Nov 6 10:31:07 EST 2009


Author: christoph
Date: 2009-11-06 10:31:07 -0500 (Fri, 06 Nov 2009)
New Revision: 4958

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-06 15:30:40 UTC (rev 4957)
+++ trunk/mapbender/http/classes/class_wmc.php	2009-11-06 15:31:07 UTC (rev 4958)
@@ -226,12 +226,10 @@
 	// ---------------------------------------------------------------------------
 	// DATABASE FUNCTIONS
 	// ---------------------------------------------------------------------------
-	public function getOtherUsersPublicWmcIds ($userId) {
+	public function getPublicWmcIds ($userId) {
 		$sql = "SELECT wmc_id FROM mb_user_wmc ";
-		$sql .= "WHERE fkey_user_id <> $1 AND wmc_public = 1 GROUP BY wmc_id";
-		$v = array($userId);
-		$t = array("i");
-		$res_wmc = db_prep_query($sql, $v, $t);
+		$sql .= "WHERE wmc_public = 1 GROUP BY wmc_id";
+		$res_wmc = db_query($sql);
 
   		$wmcArray = array();
 		while($row = db_fetch_array($res_wmc)){
@@ -246,9 +244,9 @@
 		// get WMC ids 
 		$wmcIdArray = $user->getWmcByOwner();
 		
-		$publicWmcIdArray = $this->getOtherUsersPublicWmcIds($user->id);
+		$publicWmcIdArray = $this->getPublicWmcIds($user->id);
 		
-		$wmcIdArray = array_merge($wmcIdArray, $publicWmcIdArray);
+		$wmcIdArray = array_keys( array_flip(array_merge($wmcIdArray, $publicWmcIdArray)));
 
 		// get WMC data
 		$v = array();
@@ -303,7 +301,9 @@
 		$WMSIdList = $xpath->query($query_mbWMSId);
 		foreach($WMSIdList as $WMSId) {
 			$id =  $WMSId->nodeValue;
-			$sql = "SELECT wms_timestamp,wms_getmap,wms_getlegendurl FROM wms WHERE wms_id = $1";
+			$sql = "SELECT wms_timestamp,wms_getmap,wms_getlegendurl " . 
+				"FROM wms WHERE wms_id = $1 AND " . 
+				"wms_owsproxy <> NULL AND wms_owsproxy <> ''";
 			$v = array($id);
 			$t = array("t");
 			
@@ -312,20 +312,20 @@
 				true; 
 			} //FIMXE: PROPER ERROR MESSAGE
 			
-			if($row = db_fetch_row($res)) {
-				$wms_timestamp = $row[0];
+			if($row = db_fetch_array($res)) {
+				$wms_timestamp = $row["wms_timestamp"];
 				if ($this->timestamp < $wms_timestamp) {
 				// wmc is fresh, life is good
 				}
 				else{
 					$MapResources = $xpath->query("../../wmc:Server/wmc:OnlineResource",$WMSId);
 					foreach($MapResources as $MapResource) {
-						$MapResource->setAttribute("xlink:href",$row[1]);
+						$MapResource->setAttribute("xlink:href",$row["wms_getmap"]);
 					}
 					
 					$LegendResources = $xpath->query("../../wmc:StyleList/wmc:Style/wmc:LegendURL/wmc:OnlineResource",$WMSId);
 					foreach ($LegendResources as $LegendResource) {
-						$base = $row[2];
+						$base = $row["wms_getlegendurl"];
 						$origurl = explode('&', $LegendResource->getAttribute("xlink:href"),2);
 						$url = $base . $origurl[1]; 
 						$LegendResource->setAttribute("xlink:href",$url);
@@ -345,62 +345,58 @@
 	 */
 	public function insert ($overwrite) {
 		$result = array();
-        
-        if ($this->userId && $this->xml && $this->wmc_title) {
-          try {
-            $user = new user($this->userId);
-          } catch (Exception $E) {
-            $errMsg = "Error while saving WMC document " . $this->wmc_title . "': Invalud UserId";
-            $result["success"] = false;
-            $result["message"] = $errMsg;
-            $e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
-            return $result;
-          }
-         
-          $overwrite  = ($user->isPublic())? false: $overwrite;
-          
-          db_begin();
-
-          if($overwrite)
-          {
-
-            $findsql = "SELECT fkey_user_id,wmc_title,wmc_timestamp FROM mb_user_wmc WHERE fkey_user_id = $1 AND wmc_title = $2 ORDER BY wmc_timestamp DESC LIMIT 1;";
-            $v = array($this->userId, administration::convertOutgoingString($this->wmc_title));
-            $t = array("i","s");
-        
-            $res = db_prep_query($findsql,$v,$t);
-			if (db_error()) {
-				$errMsg = "Error while saving WMC document '" . $this->wmc_title . "': " . db_error();
+		
+		if ($this->userId && $this->xml && $this->wmc_title) {
+			try {
+				$user = new user($this->userId);
+			} 
+			catch (Exception $E) {
+				$errMsg = "Error while saving WMC document " . $this->wmc_title . "': Invalud UserId";
 				$result["success"] = false;
 				$result["message"] = $errMsg;
 				$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
-                return $result;
+				return $result;
 			}
-
-            if($row = db_fetch_row($res))
-            {
-              $sql = "UPDATE mb_user_wmc SET wmc = $1, wmc_timestamp = $2 WHERE fkey_user_id = $3 AND wmc_title=$4 AND wmc_timestamp = $5";
-              $v = array($this->xml, time(), $this->userId, administration::convertOutgoingString($this->wmc_title),$row[2]);
-              $t = array("s", "s", "i", "s","s");
-
-
-            }else{
-              $sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5, $6)";
-              $v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), time(),time());
-              $t = array("s", "i", "s", "s", "s","s");
-            }
-
-
-          }else{
-
-              $sql = "INSERT INTO mb_user_wmc VALUES ($1, $2, $3, $4, $5, $6)";
-              $v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), time(),time());
-              $t = array("s", "i", "s", "s", "s","s");
-          
-          }
-
-
-
+		
+			$overwrite  = ($user->isPublic())? false: $overwrite;
+		
+			db_begin();
+		
+			if($overwrite) {
+		
+	            $findsql = "SELECT fkey_user_id,wmc_title,wmc_timestamp FROM mb_user_wmc WHERE fkey_user_id = $1 AND wmc_title = $2 ORDER BY wmc_timestamp DESC LIMIT 1;";
+	            $v = array($this->userId, administration::convertOutgoingString($this->wmc_title));
+	            $t = array("i","s");
+	        
+	            $res = db_prep_query($findsql,$v,$t);
+				if (db_error()) {
+					$errMsg = "Error while saving WMC document '" . $this->wmc_title . "': " . db_error();
+					$result["success"] = false;
+					$result["message"] = $errMsg;
+					$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
+	                return $result;
+				}
+	
+	            if($row = db_fetch_row($res)) {
+					$sql = "UPDATE mb_user_wmc SET wmc = $1, wmc_timestamp = $2 WHERE fkey_user_id = $3 AND wmc_title=$4 AND wmc_timestamp = $5";
+					$v = array($this->xml, time(), $this->userId, administration::convertOutgoingString($this->wmc_title),$row[2]);
+					$t = array("s", "s", "i", "s","s");
+				}
+				else{
+					$sql = "INSERT INTO mb_user_wmc (" . 
+						"wmc_id, fkey_user_id, wmc, wmc_title, wmc_public, wmc_timestamp, wmc_timestamp_create" . 
+						") VALUES ($1, $2, $3, $4, $5, $6, $7)";
+					$v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0,time(),time());
+					$t = array("s", "i", "s", "s", "i", "s","s");
+				}
+			}
+			else{
+				
+				$sql = "INSERT INTO mb_user_wmc  (wmc_id, fkey_user_id, wmc, wmc_title, wmc_public, wmc_timestamp, wmc_timestamp_create) VALUES ($1, $2, $3, $4, $5, $6, $7)";
+				$v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0, time(),time());
+				$t = array("s", "i", "s", "s", "i", "s","s");
+				
+			}
 			
 			$res = db_prep_query($sql, $v, $t);
 			if (db_error()) {



More information about the Mapbender_commits mailing list