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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jan 6 11:07:31 EST 2011


Author: armin11
Date: 2011-01-06 08:07:31 -0800 (Thu, 06 Jan 2011)
New Revision: 7425

Modified:
   trunk/mapbender/http/classes/class_wmc.php
   trunk/mapbender/http/javascripts/initWmcObj.php
   trunk/mapbender/http/php/mod_loadwmc_server.php
Log:
New functions to count the loading of public wmc documents. The load_count is stored in the mapbender database and the counting is done, when a wmc is loaded from loadWmc and if a wmc is given thru the GET API.

Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php	2011-01-06 15:38:46 UTC (rev 7424)
+++ trunk/mapbender/http/classes/class_wmc.php	2011-01-06 16:07:31 UTC (rev 7425)
@@ -876,6 +876,64 @@
 		}
 		return true;
 	}
+    /*
+    * increments the wmc_load_count if it has been set before
+    * @param $wmc_id wmc_serial_id
+    */
+	public function incrementWmcLoadCount() {
+		$wmcId = $this->wmc_id;
+		//check for public else return false
+		if ($this->isPublic()) {
+			//check if a load_count has been set before
+			//if not been set, set it to 1
+			//else increment it
+			$sql = "SELECT load_count FROM wmc_load_count where fkey_wmc_serial_id = $1;";
+			$v = array($wmcId);
+			$t = array("i");
+			$res = db_prep_query($sql,$v,$t);
+			if(db_error()) {
+				return false;
+			}
+			$row = db_fetch_array($res);
+			if ($row) {
+				$e = new mb_exception("class_wmc: incrementWmcLoadCount found entry increment should be performed");
+				$count = $row['load_count'];
+				$count++;
+				$sql = "UPDATE wmc_load_count SET load_count = $2 WHERE fkey_wmc_serial_id = $1;";
+				$v = array($wmcId,$count);
+				$t = array("i","i");
+				$res = db_prep_query($sql,$v,$t);
+			} else {
+				$e = new mb_exception("class_wmc: incrementWmcLoadCount dont found entry - new should be set to 1");
+				$sql = "INSERT INTO wmc_load_count (fkey_wmc_serial_id,load_count) VALUES ($1, $2);";
+				$v = array($wmcId,1);
+				$t = array("i","i");
+				$res = db_prep_query($sql,$v,$t);
+			}
+			return true;
+		}
+		return false;
+	}
+    /*
+    * test if the given wmc is public
+    *
+    */
+	public function isPublic() {
+		$wmcId = $this->wmc_id;
+		$sql = "SELECT wmc_serial_id FROM mb_user_wmc ";
+		$sql .= "WHERE wmc_serial_id = $1 AND wmc_public = 1;";
+		$v = array($wmcId);
+		$t = array("i");
+		$res = db_prep_query($sql,$v,$t);
+		$row = db_fetch_array($res);
+		if (isset($row['wmc_serial_id']) && $row['wmc_serial_id'] != '') {
+			$e = new mb_exception("class_wmc: isPublic is true");
+			return true;
+		}
+		$e = new mb_exception("class_wmc: isPublic is false");
+		return false;
+	}
+
 	// ---------------------------------------------------------------------------
 	// GETTER FUNCTIONS
 	// ---------------------------------------------------------------------------

Modified: trunk/mapbender/http/javascripts/initWmcObj.php
===================================================================
--- trunk/mapbender/http/javascripts/initWmcObj.php	2011-01-06 15:38:46 UTC (rev 7424)
+++ trunk/mapbender/http/javascripts/initWmcObj.php	2011-01-06 16:07:31 UTC (rev 7425)
@@ -120,6 +120,8 @@
 	// just make it work for a single Wmc
 		try {
 			$wmcGetApi = WmcFactory::createFromDb($input["id"]);
+			//increment load count
+			$wmcGetApi->incrementWmcLoadCount();
 		}
 		catch (Exception $e) {
 			new mb_exception("Failed to load WMC from DB. Keeping original WMC.");

Modified: trunk/mapbender/http/php/mod_loadwmc_server.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwmc_server.php	2011-01-06 15:38:46 UTC (rev 7424)
+++ trunk/mapbender/http/php/mod_loadwmc_server.php	2011-01-06 16:07:31 UTC (rev 7425)
@@ -57,7 +57,7 @@
 		$wmcId = $ajaxResponse->getParameter("id");
 		if ($wmc->createFromDb($wmcId)) {
 			$updatedWMC = $wmc->updateUrlsFromDb();
-	        $wmc->createFromXml($updatedWMC);
+	        	$wmc->createFromXml($updatedWMC);
 			
 			$skipWms = $ajaxResponse->getParameter("skipWms");
 			if (is_array($skipWms)) {
@@ -68,6 +68,8 @@
 			}
 			if ($jsArray) {
 				$resultObj["javascript"] = $jsArray;
+				//increment load_count
+				$wmc->incrementWmcLoadCount();
 				$ajaxResponse->setResult($resultObj); 
 				$ajaxResponse->setSuccess(true);
 				break;
@@ -88,8 +90,8 @@
 		$wmc->createFromXml($wmcDoc);
 
 		$updatedWMC = $wmc->updateUrlsFromDb();
-        $wmc->createFromXml($updatedWMC);
-        $jsArray = $wmc->toJavaScript();
+        	$wmc->createFromXml($updatedWMC);
+        	$jsArray = $wmc->toJavaScript();
 		if ($jsArray) {
 			$resultObj["javascript"] = $jsArray;
 			$ajaxResponse->setResult($resultObj); 



More information about the Mapbender_commits mailing list