[Mapbender-commits] r7021 - in trunk/mapbender/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Oct 4 10:51:30 EDT 2010


Author: christoph
Date: 2010-10-04 14:51:29 +0000 (Mon, 04 Oct 2010)
New Revision: 7021

Modified:
   trunk/mapbender/http/classes/class_metadata_new.php
   trunk/mapbender/http/classes/class_user.php
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/javascripts/mod_initWmc.php
   trunk/mapbender/http/php/mod_loadwmc_server.php
Log:
wmc_serial_id is now the new unique column of mb_user_wmc

Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php	2010-10-04 14:23:22 UTC (rev 7020)
+++ trunk/mapbender/http/classes/class_metadata_new.php	2010-10-04 14:51:29 UTC (rev 7021)
@@ -246,10 +246,10 @@
 
 				switch ($this->orderBy) {
 					case "rank":
-						$this->orderBy = " ORDER BY wmc_id ";
+						$this->orderBy = " ORDER BY wmc_serial_id ";
 						break;
 					case "id":
-						$this->orderBy = " ORDER BY wmc_id ";
+						$this->orderBy = " ORDER BY wmc_serial_id ";
 						break;
 					case "title":
 						$this->orderBy = " ORDER BY wmc_title ";
@@ -452,13 +452,13 @@
 		$wmcMatrix = $this->flipDiagonally($wmcMatrix);
 		//read out first server entry - maybe this a little bit timeconsuming TODO
 		for($i=0; $i<count($wmcMatrix);$i++){
-			$this->wmcJSON->wmc->srv[$i]->id = $wmcMatrix[$i]['wmc_id'];
+			$this->wmcJSON->wmc->srv[$i]->id = $wmcMatrix[$i]['wmc_serial_id'];
 			$this->wmcJSON->wmc->srv[$i]->title = $wmcMatrix[$i]['wmc_title'];
 			$this->wmcJSON->wmc->srv[$i]->abstract = $wmcMatrix[$i]['abstract'];
 			$this->wmcJSON->wmc->srv[$i]->date = date("d.m.Y",$wmcMatrix[$i]['wmc_timestamp']);
 			$this->wmcJSON->wmc->srv[$i]->respOrg = $wmcMatrix[$i]['mb_group_name'];
-			$this->wmcJSON->wmc->srv[$i]->mdLink = "http://".$this->hostName."/mapbender/x_geoportal/showWMCMetadata.php?id=".$wmcMatrix[$i]['wmc_id'];
-			$this->wmcJSON->wmc->srv[$i]->previewURL = "http://".$this->hostName."/mapbender/x_geoportal/mod_wmcPreview.php?id=".$wmcMatrix[$i]['wmc_id'];
+			$this->wmcJSON->wmc->srv[$i]->mdLink = "http://".$this->hostName."/mapbender/x_geoportal/showWMCMetadata.php?id=".$wmcMatrix[$i]['wmc_serial_id'];
+			$this->wmcJSON->wmc->srv[$i]->previewURL = "http://".$this->hostName."/mapbender/x_geoportal/mod_wmcPreview.php?id=".$wmcMatrix[$i]['wmc_serial_id'];
 			$spatialSource = "";
 			$stateOrProvince = $wmcMatrix[$i]['mb_group_stateorprovince']; 
 			if ($stateOrProvince == "NULL" || $stateOrProvince == "") {

Modified: trunk/mapbender/http/classes/class_user.php
===================================================================
--- trunk/mapbender/http/classes/class_user.php	2010-10-04 14:23:22 UTC (rev 7020)
+++ trunk/mapbender/http/classes/class_user.php	2010-10-04 14:51:29 UTC (rev 7021)
@@ -660,15 +660,15 @@
 	 * @return integer[] an array of WMC ids; ids from table mb_user_wmc
 	 */
 	public function getWmcByOwner () {
-		$sql = "SELECT wmc_id FROM mb_user_wmc ";
-		$sql .= "WHERE fkey_user_id = $1 GROUP BY wmc_id";
+		$sql = "SELECT wmc_serial_id FROM mb_user_wmc ";
+		$sql .= "WHERE fkey_user_id = $1 GROUP BY wmc_serial_id";
 		$v = array($this->id);
 		$t = array("i");
 		$res_wmc = db_prep_query($sql, $v, $t);
 
   		$wmcArray = array();
 		while($row = db_fetch_array($res_wmc)){
-			array_push($wmcArray, $row["wmc_id"]);
+			array_push($wmcArray, $row["wmc_serial_id"]);
 		}
 		return $wmcArray;
 	}

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2010-10-04 14:23:22 UTC (rev 7020)
+++ trunk/mapbender/http/classes/class_wmc.php	2010-10-04 14:51:29 UTC (rev 7021)
@@ -128,7 +128,6 @@
 
 	public function __construct () {
 		$this->userId = Mapbender::session()->get("mb_user_id");
-		$this->wmc_id = time();
 		$this->timestamp = time();
 	}
 
@@ -157,7 +156,7 @@
 		}
 		$this->createObjFromWMC_xml($doc);
 		$sql = "SELECT wmc_timestamp, wmc_title, wmc_public " .
-			"FROM mb_user_wmc WHERE wmc_id = $1 AND (fkey_user_id = $2 OR wmc_public = 1)";
+			"FROM mb_user_wmc WHERE wmc_serial_id = $1 AND (fkey_user_id = $2 OR wmc_public = 1)";
 		$v = array($wmcId, Mapbender::session()->get("mb_user_id"));
 		$t = array("s", "i");
 
@@ -232,13 +231,13 @@
 	// DATABASE FUNCTIONS
 	// ---------------------------------------------------------------------------
 	public function getPublicWmcIds () {
-		$sql = "SELECT wmc_id FROM mb_user_wmc ";
-		$sql .= "WHERE wmc_public = 1 GROUP BY wmc_id";
+		$sql = "SELECT wmc_serial_id FROM mb_user_wmc ";
+		$sql .= "WHERE wmc_public = 1 GROUP BY wmc_serial_id";
 		$res_wmc = db_query($sql);
 
 		$wmcArray = array();
 		while($row = db_fetch_array($res_wmc)) {
-			array_push($wmcArray, $row["wmc_id"]);
+			array_push($wmcArray, $row["wmc_serial_id"]);
 		}
 		return $wmcArray;
 	}
@@ -281,14 +280,14 @@
 		}
 
 		if ($wmcIdList !== "") {
-			$sql = "SELECT DISTINCT wmc_id, wmc_title, wmc_timestamp, wmc_timestamp_create, wmc_public, abstract FROM mb_user_wmc ";
-			$sql .= "WHERE wmc_id IN (" . $wmcIdList . ") ";
+			$sql = "SELECT DISTINCT wmc_serial_id, wmc_title, wmc_timestamp, wmc_timestamp_create, wmc_public, abstract FROM mb_user_wmc ";
+			$sql .= "WHERE wmc_serial_id IN (" . $wmcIdList . ") ";
 			$sql .=	"ORDER BY wmc_timestamp DESC";
 
 			$res = db_prep_query($sql, $v, $t);
 			while($row = db_fetch_assoc($res)) {
 				$currentResult = array();
-				$currentResult["id"] = $row["wmc_id"];
+				$currentResult["id"] = $row["wmc_serial_id"];
 				$currentResult["abstract"] = $row["abstract"];
 				$currentResult["title"] = administration::convertIncomingString($row["wmc_title"]);
 				$currentResult["timestamp"] = date("M d Y H:i:s", $row["wmc_timestamp"]);
@@ -317,7 +316,7 @@
 		$keywordArray = array();
 
 		$sql = "SELECT DISTINCT k.keyword FROM keyword AS k, wmc_keyword AS w " .
-			"WHERE w.fkey_keyword_id = k.keyword_id AND w.fkey_wmc_id = $1";
+			"WHERE w.fkey_keyword_id = k.keyword_id AND w.fkey_wmc_serial_id = $1";
 		$v = array($id);
 		$t = array("s");
 		$res = db_prep_query($sql, $v, $t);
@@ -338,7 +337,7 @@
 		$sql = "SELECT DISTINCT t.md_topic_category_id FROM " .
 			"md_topic_category AS t, wmc_md_topic_category AS w " .
 			"WHERE w.fkey_md_topic_category_id = t.md_topic_category_id " .
-			"AND w.fkey_wmc_id = $1";
+			"AND w.fkey_wmc_serial_id = $1";
 		$v = array($id);
 		$t = array("s");
 		$res = db_prep_query($sql, $v, $t);
@@ -604,7 +603,7 @@
 
 			if($overwrite) {
 
-				$findsql = "SELECT fkey_user_id,wmc_title,wmc_timestamp, wmc_id FROM mb_user_wmc WHERE fkey_user_id = $1 AND wmc_id = $2 ORDER BY wmc_timestamp DESC LIMIT 1;";
+				$findsql = "SELECT fkey_user_id,wmc_title,wmc_timestamp, wmc_serial_id FROM mb_user_wmc WHERE fkey_user_id = $1 AND wmc_serial_id = $2 ORDER BY wmc_timestamp DESC LIMIT 1;";
 				$v = array($this->userId, $this->wmc_id);
 				$t = array("i","i");
 
@@ -619,18 +618,18 @@
 
 				if($row = db_fetch_row($res)) {
 					$sql = "UPDATE mb_user_wmc SET wmc = $1, wmc_timestamp = $2, abstract = $3, srs = $4, minx = $5, miny = $6,".
-						" maxx = $7, maxy = $8, wmc_title = $9 WHERE fkey_user_id = $10 AND wmc_id=$11 AND wmc_timestamp = $12;";
+						" maxx = $7, maxy = $8, wmc_title = $9 WHERE fkey_user_id = $10 AND wmc_serial_id=$11 AND wmc_timestamp = $12;";
 					$v = array($this->xml, time(), $this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx, $this->wmc_extent->minx,
 						$this->wmc_extent->maxx, $this->wmc_extent->maxy ,administration::convertOutgoingString($this->wmc_title), $this->userId, $this->wmc_id,$row[2]);
 					$t = array("s", "s","s","s","i","i","i","i", "s", "i", "i","s");
 					// need the database Id
 					$wmc_DB_ID = $row[3];
-					$delsql = "DELETE FROM wmc_md_topic_category WHERE fkey_wmc_id = $1;";
+					$delsql = "DELETE FROM wmc_md_topic_category WHERE fkey_wmc_serial_id = $1;";
 					$delv = array($wmc_DB_ID);
 					$delt = array("s");
 					db_prep_query($delsql, $delv,$delt);
 
-					$delkwsql = "DELETE FROM wmc_keyword WHERE fkey_wmc_id = $1;";
+					$delkwsql = "DELETE FROM wmc_keyword WHERE fkey_wmc_serial_id = $1;";
 					$delkwv = array($wmc_DB_ID);
 					$delkwt = array("s");
 					db_prep_query($delkwsql, $delkwv,$delkwt);
@@ -643,7 +642,7 @@
 						"wmc_id, fkey_user_id, wmc, wmc_title, wmc_public, wmc_timestamp, wmc_timestamp_create, " .
 						"abstract, srs, minx, miny, maxx, maxy ".
 						") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);";
-					$v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0,time(),time(),
+					$v = array(time(), $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0,time(),time(),
 						$this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx,  $this->wmc_extent->miny, $this->wmc_extent->maxx, $this->wmc_extent->maxy);
 					$t = array("s", "i", "s", "s", "i", "s","s", "s","s","i","i","i", "i");
 				}
@@ -654,7 +653,7 @@
 					"wmc_id, fkey_user_id, wmc, wmc_title, wmc_public, wmc_timestamp, wmc_timestamp_create, " .
 					"abstract, srs, minx, miny, maxx, maxy ".
 					") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);";
-				$v = array($this->wmc_id, $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0, time(),time(),
+				$v = array(time(), $this->userId, $this->xml, administration::convertOutgoingString($this->wmc_title), $user->isPublic()?1:0, time(),time(),
 					$this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx,  $this->wmc_extent->miny, $this->wmc_extent->maxx, $this->wmc_extent->maxy);
 				$t = array("s", "i", "s", "s", "i", "s","s", "s","s","i","i","i", "i");
 
@@ -669,7 +668,6 @@
 				$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
 			}
 			else {
-
 			// because the wmc id is created each time a wmc is instantiated $this->wmc_id has nothing to do with the database wmc_id
 			// this is some duct tape to fix it :-(
 			// see also above where wmc_DB_ID is defined if we need to update
@@ -690,9 +688,18 @@
 						}
 					}
 
+					$sql = "SELECT max(wmc_serial_id) AS i FROM mb_user_wmc";
+					$res = db_query($sql);
+					$row = db_fetch_assoc($res);
+					$wmc_DB_ID = intval($row["i"]);
 
-
-					$keywordsql = "INSERT INTO wmc_keyword (fkey_keyword_id,fkey_wmc_id) SELECT keyword.keyword_id,$1 FROM keyword WHERE keyword = $2 AND NOT EXISTS (SELECT fkey_wmc_id FROM wmc_keyword	WHERE fkey_wmc_id = $3 );";
+					$keywordsql = <<<SQL
+INSERT INTO wmc_keyword (fkey_keyword_id,fkey_wmc_serial_id)
+	SELECT keyword.keyword_id,$1 FROM keyword
+	WHERE keyword = $2 AND NOT EXISTS (
+		SELECT fkey_wmc_serial_id FROM wmc_keyword	WHERE fkey_wmc_serial_id = $3
+	)
+SQL;
 					$v = array($wmc_DB_ID, $keyword,$wmc_DB_ID);
 					$t = array("s","s","s");
 					$res = db_prep_query($keywordsql, $v, $t);
@@ -704,7 +711,7 @@
 				$this->inspireCats = $this->inspireCats? $this->inspireCats: array();
 				foreach($this->inspireCats as $catId) {
 
-					$catSql = "INSERT INTO wmc_md_topic_category (fkey_wmc_id, fkey_md_topic_category_id) VALUES ($1,$2)";
+					$catSql = "INSERT INTO wmc_md_topic_category (fkey_wmc_serial_id, fkey_md_topic_category_id) VALUES ($1,$2)";
 					$v = array($wmc_DB_ID, $catId);
 					$t = array("s","s");
 					$res = db_prep_query($catSql, $v, $t);
@@ -732,7 +739,7 @@
     * overwrites an exact version of a wmc in the database
     */
 	public function update_existing($xml,$id) {
-		$sql = "UPDATE mb_user_wmc SET wmc = $1 WHERE wmc_id = $2";
+		$sql = "UPDATE mb_user_wmc SET wmc = $1 WHERE wmc_serial_id = $2";
 		$v = array($xml,$id);
 		$t = array("s","i");
 		$res = db_prep_query($sql,$v,$t);
@@ -763,7 +770,7 @@
 		}
 
 		$sql = "DELETE FROM mb_user_wmc ";
-		$sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
+		$sql .= "WHERE fkey_user_id = $1 AND wmc_serial_id = $2";
 		$v = array($userId, $wmcId);
 		$t = array('i', 's');
 		$res = db_prep_query($sql, $v, $t);
@@ -779,7 +786,7 @@
 	 * @param $id String the WMC id
 	 */
 	public static function getDocument ($id) {
-		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 AND " .
+		$sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_serial_id = $1 AND " .
 			"(fkey_user_id = $2 OR wmc_public = 1)";
 		$v = array($id, Mapbender::session()->get("mb_user_id"));
 		$t = array('s', 'i');
@@ -820,7 +827,7 @@
 		}
 		$wmcId = $this->wmc_Id;
 		$public = $public ? 1 :0;
-		$sql = "UPDATE mb_user_wmc SET wmc_public = $1 WHERE wmc_id = $2 AND fkey_user_id = $3;";
+		$sql = "UPDATE mb_user_wmc SET wmc_public = $1 WHERE wmc_serial_id = $2 AND fkey_user_id = $3;";
 		$v = array($public,$wmcId, $currentUser->id);
 		$t = array("i","s","i");
 		$res = db_prep_query($sql,$v,$t);

Modified: trunk/mapbender/http/javascripts/mod_initWmc.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_initWmc.php	2010-10-04 14:23:22 UTC (rev 7020)
+++ trunk/mapbender/http/javascripts/mod_initWmc.php	2010-10-04 14:51:29 UTC (rev 7021)
@@ -32,7 +32,7 @@
 		$user = $row['fkey_mb_user_id'];
 		$password = $row['mb_user_password'];
 		$gui = $row['fkey_gui_id'];
-		$wmc_id = $row['fkey_wmc_id'];
+		$wmc_id = $row['fkey_wmc_serial_id'];
 		$kml_doc = $row['kml'];
 		
 		$kml = new kml("", "", 0, 0, "");

Modified: trunk/mapbender/http/php/mod_loadwmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwmc_server.php	2010-10-04 14:23:22 UTC (rev 7020)
+++ trunk/mapbender/http/php/mod_loadwmc_server.php	2010-10-04 14:51:29 UTC (rev 7021)
@@ -56,9 +56,6 @@
 	case 'loadWmc':
 		$wmcId = $ajaxResponse->getParameter("id");
 		if ($wmc->createFromDb($wmcId)) {
-			new mb_exception("-------------------------------");
-			new mb_exception(serialize($wmc->mainMap->getWmsArray()));
-			new mb_exception("===============================");
 			$updatedWMC = $wmc->updateUrlsFromDb();
 	        $wmc->createFromXml($updatedWMC);
 			



More information about the Mapbender_commits mailing list