[Mapbender-commits] r8610 - in trunk/mapbender/http: classes plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Apr 29 05:14:42 PDT 2013


Author: verenadiewald
Date: 2013-04-29 05:14:42 -0700 (Mon, 29 Apr 2013)
New Revision: 8610

Modified:
   trunk/mapbender/http/classes/class_wfsToDb.php
   trunk/mapbender/http/classes/class_wfs_factory.php
   trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
Log:
some improvements in WFS metadata editor for correct update of each featuretype's attribute data 

Modified: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php	2013-04-29 12:03:06 UTC (rev 8609)
+++ trunk/mapbender/http/classes/class_wfsToDb.php	2013-04-29 12:14:42 UTC (rev 8610)
@@ -114,15 +114,34 @@
 		return true;		
 	}
 	
-	/**
+/**
 	 * Updates an existing WFS in the database.
-	 * 
+	 *
 	 * @return Boolean
 	 * @param $aWfs Wfs
 	 */
 	public static function update ($aWfs,$updateMetadataOnly=false) {
+		//get some things out from database if not already given thru metadata editor: wfs_network_access
+		//they don't come from the capabilities!
+		if (!$updateMetadataOnly) {
+			//read network_access from database
+			$sql = "SELECT wfs_network_access, wfs_max_features from wfs WHERE wfs_id = $1 ";
+			$v = array($aWfs->id);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+			$row = db_fetch_assoc($res);
+			$aWfs->wfs_network_access = $row["wfs_network_access"];
+			$aWfs->wfs_max_features = $row["wfs_max_features"];
+			//$e = new mb_notice("class_wms.php: wfs_network_access from database: ".$aWfs->wfs_network_access);
+		}
+		//if network access is either stored in database nor given thru object, set it too a default value 0
+		if (!isset($aWfs->wfs_network_access) || ($aWfs->wfs_network_access == '')) {
+			$aWfs->wfs_network_access = intval('0');
+		}
+		
+		$admin = new administration();
 		db_begin();
-		
+	
 		// update WFS
 		$sql = "UPDATE wfs SET wfs_version = $1, wfs_name = $2, wfs_title = $3, ";
 		$sql .= "wfs_abstract = $4, wfs_getcapabilities = $5, wfs_getcapabilities_doc = $6, ";
@@ -134,65 +153,94 @@
 		$sql .= "electronicmailaddress = $22, country = $23, ";
 		$sql .= "wfs_timestamp = $24, wfs_network_access = $25, fkey_mb_group_id = $26, wfs_max_features = $28 ";
 		$sql .= "WHERE wfs_id = $27";
-
+	
 		$v = array(
-			$aWfs->getVersion(), 
-			$aWfs->name, 
-			$aWfs->title, 
-			$aWfs->summary,
-			$aWfs->getCapabilities, 
-			$aWfs->getCapabilitiesDoc, 
-			$aWfs->uploadUrl,
-			$aWfs->describeFeatureType, 
-			$aWfs->getFeature, 
-			$aWfs->transaction,
-			$aWfs->fees, 
-			$aWfs->accessconstraints,
-			$aWfs->individualName,
-			$aWfs->positionName,
-			$aWfs->providerName,
-			$aWfs->city,
-			$aWfs->deliveryPoint,
-			$aWfs->administrativeArea,
-			$aWfs->postalCode,
-			$aWfs->voice,
-			$aWfs->facsimile,
-			$aWfs->electronicMailAddress,
-			$aWfs->country, 
-			strtotime("now"),
-			$aWfs->wfs_network_access,
-			$aWfs->fkey_mb_group_id,
-			$aWfs->id,
-			$aWfs->wfs_max_features
+				$aWfs->getVersion(),
+				$aWfs->name,
+				$aWfs->title,
+				$aWfs->summary,
+				$aWfs->getCapabilities,
+				$aWfs->getCapabilitiesDoc,
+				$aWfs->uploadUrl,
+				$aWfs->describeFeatureType,
+				$aWfs->getFeature,
+				$aWfs->transaction,
+				$aWfs->fees,
+				$aWfs->accessconstraints,
+				$aWfs->individualName,
+				$aWfs->positionName,
+				$aWfs->providerName,
+				$aWfs->city,
+				$aWfs->deliveryPoint,
+				$aWfs->administrativeArea,
+				$aWfs->postalCode,
+				$aWfs->voice,
+				$aWfs->facsimile,
+				$aWfs->electronicMailAddress,
+				$aWfs->country,
+				strtotime("now"),
+				$aWfs->wfs_network_access,
+				$aWfs->fkey_mb_group_id,
+				$aWfs->id,
+				$aWfs->wfs_max_features
 		);
 			
 		$t = array('s', 's', 's', 's', 's', 's', 's', 's' ,'s' ,'s' ,'s' ,'s','s' ,'s','s','s','s','s','s','s','s','s','s','i','i','i','i','i');
-		$e = new mb_notice("UPDATING WFS " . $aWfs->id);
+		$e = new mb_notice("class_wfsToDb.php: UPDATING WFS " . $aWfs->id);
 		$res = db_prep_query($sql, $v, $t);
 		if (!$res) {
 			$e = new mb_exception("Error while updating WFS in database.");
 			db_rollback();
 			return false;
 		}
-		
+	
 		# delete and refill wfs_termsofuse
 		$sql = "DELETE FROM wfs_termsofuse WHERE fkey_wfs_id = $1 ";
 		$v = array($aWfs->id);
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
 		if(!$res){
-			db_rollback();	
+			db_rollback();
 		}
-		
+	
 		WfsToDb::insertTermsOfUse($aWfs);
-		
+	
+		# update TABLE wfs_featuretype
+		$oldFeatureTypeNameArray = array();
+		$v = array($aWfs->id);
+		$t = array('i');
+		$c = 2;
+		$sql = "SELECT featuretype_id, featuretype_name, featuretype_title, featuretype_abstract, inspire_download FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND NOT featuretype_name IN(";
+		$e = new mb_notice("class_wfsToDb.php: WFS_UPDATE: count featuretypeArray: ".count($aWfs->featureTypeArray));
+	
+		for($i=0; $i<count($aWfs->featureTypeArray); $i++){
+			if($i>0){$sql .= ',';}
+			$sql .= "$".$c;
+			array_push($v,$aWfs->featureTypeArray[$i]->name);
+			$e = new mb_notice("class_wfsToDb.php: WFS_UPDATE: old featuretype name added for read: ".$aWfs->featureTypeArray[$i]->name);
+			array_push($t,'s');
+			$c++;
+		}
+		$sql .= ")";
+		$res = db_prep_query($sql,$v,$t);
+		while ($row = db_fetch_array($res)) {
+			$oldFeatureTypeNameArray[]= array(
+				"id" => $row["featuretype_id"],
+				"name" => $row["featuretype_name"],
+				"title" => $row["featuretype_title"],
+				"abstract" => $row["featuretype_abstract"]
+				//"inspire_download" => $row["inspire_download"]
+			);
+		}
+	
 		$featureTypeNameArray = array();
+	
 		for ($i = 0; $i < count($aWfs->featureTypeArray); $i++) {
 			$currentFeatureType = $aWfs->featureTypeArray[$i];
 			array_push($featureTypeNameArray, $currentFeatureType);
 			if (WfsToDb::featureTypeExists($currentFeatureType)) {
 				// update existing WFS feature types
-				$e = new mb_notice("class_wfsToDb.php: FT exists");
+				$e = new mb_notice("class_wfsToDb.php: class_wfsToDb.php: FT exists");
 				if (!WfsToDb::updateFeatureType($currentFeatureType,$updateMetadataOnly)) {
 					db_rollback();
 					return false;
@@ -206,16 +254,16 @@
 					return false;
 				}
 			}
-		}		
-		
+		}
+	
 		// delete obsolete WFS feature types
 		$v = array($aWfs->id);
 		$t = array("i");
 		$sql = "DELETE FROM wfs_featuretype WHERE fkey_wfs_id = $1";
-		$sql_in = "";
-		for ($i = 0; $i < count($featureTypeNameArray); $i++) {
-			if ($i > 0) {
-				$sql_in .= ", ";
+			$sql_in = "";
+			for ($i = 0; $i < count($featureTypeNameArray); $i++) {
+					if ($i > 0) {
+					$sql_in .= ", ";
 			}
 			$sql_in .= "$" . ($i+2);
 			array_push($v, $featureTypeNameArray[$i]->name);
@@ -224,16 +272,16 @@
 		if ($sql_in !== "") {
 			$sql .=  " AND featuretype_name NOT IN (" . $sql_in . ")";
 		}
-		
+	
 		$res = db_prep_query($sql,$v,$t);
 		if (!$res) {
 			$e = new mb_exception("Error while deleting obsolete WFS feature types in database.");
 			db_rollback();
 			return false;
 		}
-		$e = new mb_exception("Number of featuretypes not to delete: ".count($featureTypeNameArray));
+		$e = new mb_notice("class_wfsToDb.php: Number of featuretypes not to delete: ".count($featureTypeNameArray));
 		db_commit();
-		return true;		
+		return true;
 	}
 	
 	
@@ -322,7 +370,7 @@
 			$aWfsFeatureTypeNamespace->value
 		);
 		$t = array("s", "s", "s", "s");
-		$e = new mb_notice("INSERTING FT NS $aWfsId, FT: $aWfsFeatureTypeId, NS: $aWfsFeatureTypeNamespace->name");
+		$e = new mb_notice("class_wfsToDb.php: INSERTING Featuretype Namespace for WFS-ID $aWfsId, FT: $aWfsFeatureTypeId, NS: $aWfsFeatureTypeNamespace->name");
 		$res = db_prep_query($sql, $v, $t);
 
 		if (!$res) {
@@ -349,7 +397,7 @@
 		);
 		$t = array("i", "s");
 		
-		$e = new mb_notice("INSERTING FT Crs (FT: $aWfsFeatureTypeId, Crs: $aWfsFeatureTypeCrsString");
+		$e = new mb_notice("class_wfsToDb.php: INSERTING Featuretype Crs (FT: $aWfsFeatureTypeId, Crs: $aWfsFeatureTypeCrsString");
 		$res = db_prep_query($sql, $v, $t);
 		
 		if (!$res) {
@@ -394,13 +442,11 @@
 			$e = new mb_exception("Problem while storing metadata url from wfs to db");
 			$e = new mb_exception($result['message']);
 		} else {
-			$e = new mb_notice("Storing of metadata url from wfs to db was successful");
+			$e = new mb_notice("class_wfsToDb.php: Storing of metadata url from wfs to db was successful");
 		}
 		return true;
 	}
 
-
-
 	/**
 	 * Inserts a new WFS feature type element into the database.
 	 * 
@@ -419,7 +465,7 @@
 		);
 		$t = array("i", "s", "s");
 		
-		$e = new mb_notice("INSERTING FT EL (FT: $aWfsFeatureTypeId, NS: $aWfsFeatureTypeElement->name");
+		$e = new mb_notice("class_wfsToDb.php: INSERTING Featuretype Element (FT: $aWfsFeatureTypeId, NS: $aWfsFeatureTypeElement->name");
 		$res = db_prep_query($sql, $v, $t);
 		
 		if (!$res) {
@@ -442,7 +488,7 @@
 		if (!$res) {
 			// no configuration exists for this featuretype, 
 			// which is fine
-			$e = new mb_notice("No WFS conf found for this featuretype (Couldn't insert new feature type element in wfs_conf_element!)");
+			$e = new mb_notice("class_wfsToDb.php: No WFS conf found for this featuretype (Couldn't insert new feature type element in wfs_conf_element!)");
 			return true;
 		}
 		while ($row = db_fetch_array($res)) {
@@ -460,7 +506,7 @@
 			$rowConfElement = db_fetch_array($resConfElement);
 			$count = $rowConfElement["cnt"];
 			if ($count === "0") {
-				$e = new mb_notice("Inserting this feature type element (" . 
+				$e = new mb_notice("class_wfsToDb.php: Inserting this feature type element (" . 
 					$aWfsFeatureTypeElement->id . ") into WFS conf ($wfsConfId)");
 				
 				// Insert featuretype element in wfs_conf_element
@@ -483,7 +529,7 @@
 				}
 			}
 			else {
-				$e = new mb_notice("This feature type element (" . 
+				$e = new mb_notice("class_wfsToDb.php: This feature type element (" . 
 					$aWfsFeatureTypeElement->id . ") already exists in WFS conf ($wfsConfId)");
 
 			}
@@ -510,7 +556,7 @@
 		);
 		$t = array("s", "i", "i");
 
-		$e = new mb_notice("UPDATING FT EL (FT: $aWfsFeatureTypeId, NS: $aWfsFeatureTypeElement->name");
+		#$e = new mb_notice("class_wfsToDb.php: UPDATING FT EL (FT: $aWfsFeatureTypeId, NS: $aWfsFeatureTypeElement->name");
 		$res = db_prep_query($sql, $v, $t);
 
 		if (!$res) {
@@ -546,7 +592,7 @@
 		);
 		$t = array('i','s','s','s','i','s','s','s','i');
 
-		$e = new mb_notice("INSERTING FT (FT: $aWfsFeatureType->name)");
+		#$e = new mb_notice("class_wfsToDb.php: INSERTING Featuretype (FT: $aWfsFeatureType->name)");
 		$res = db_prep_query($sql,$v,$t);
 		if (!$res) {
 			$e = new mb_exception("Error while inserting WFS feature type into database.");
@@ -586,6 +632,7 @@
 				return false;
 			}
 		}
+						
 		return true;
 	}
 	
@@ -596,8 +643,20 @@
 	 * @param $aWfsFeatureType WfsFeatureType
 	 */
 	private static function updateFeatureType ($aWfsFeatureType, $updateMetadataOnly=false) {
-
 		$aWfsFeatureType->id = WfsToDb::getFeatureTypeId($aWfsFeatureType);
+		
+		$sql = "SELECT featuretype_id, featuretype_searchable, inspire_download FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND featuretype_name = $2";
+		$v = array($aWfsFeatureType->wfs->id,$aWfsFeatureType->name);
+		$t = array('i','s');
+		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+			$ft_id = $row['featuretype_id'];
+		}
+		else{
+			db_rollback();
+			$e = new mb_exception("Not found: ".$aWfsFeatureType->name);
+			return;
+		}
 
 		$sql = "UPDATE wfs_featuretype SET ";
 		$sql .= "featuretype_title = $1,";
@@ -607,6 +666,20 @@
 		$sql .= "featuretype_latlon_bbox = $5, ";
 		$sql .= "inspire_download = $7 ";
 		$sql .= "WHERE featuretype_id = $6";
+		
+		if (!$updateMetadataOnly) {
+			//read inspire_download and featuretype_searchable from database if update from capabilities
+			$aWfsFeatureType->inspire_download = $row["inspire_download"];
+			$aWfsFeatureType->searchable = $row["featuretype_searchable"];
+		}
+		//if inspire_download, and featuretype_searchable is neither stored in database nor given thru object, set it too a default value 0
+		if (!isset($aWfsFeatureType->inspire_download) || ($aWfsFeatureType->inspire_download =='')) {
+			$aWfsFeatureType->inspire_download = intval('0');
+		}
+		if (!isset($aWfsFeatureType->searchable) || ($aWfsFeatureType->searchable =='')) {
+			$aWfsFeatureType->searchable = intval('0');
+		}
+		
 		$v = array(
 			$aWfsFeatureType->title,
 			$aWfsFeatureType->summary,
@@ -618,11 +691,11 @@
 		);
 		$t = array('s','s','s','s','s','i','i');
 
-		$e = new mb_exception("UPDATING FT (FT: $aWfsFeatureType->id)");
+		$e = new mb_notice("class_wfsToDb.php: UPDATING Featuretype (FT: $aWfsFeatureType->id)");
 		
-		$e = new mb_exception("UPDATING FT (FT searchable: $aWfsFeatureType->searchable)");
-		$e = new mb_exception("UPDATING FT (FT inspire_download: $aWfsFeatureType->inspire_download)");
-		$e = new mb_exception("");
+		$e = new mb_notice("class_wfsToDb.php: UPDATING Featuretype (FT searchable: $aWfsFeatureType->searchable)");
+		$e = new mb_notice("class_wfsToDb.php: UPDATING Featuretype (FT inspire_download: $aWfsFeatureType->inspire_download)");
+		
 		$res = db_prep_query($sql,$v,$t);
 		if (!$res) {
 			$e = new mb_exception("Error while updating WFS feature type in database.");
@@ -775,13 +848,15 @@
 				$row = db_fetch_array($res);
 			//print_r($row);
 				if ($row) {
-					$keyword_id = $row["keyword_id"];	
+					$keyword_id = $row["keyword_id"];
+					$e = new mb_notice("class_wfsToDb.php: Keyword ".$k[$j]." already exists in table keyword in DB.");
 				}
 				else {
 					$sql_insertKeyword = "INSERT INTO keyword (keyword)";
 					$sql_insertKeyword .= "VALUES ($1)";
 					$v1 = array($k[$j]);
 					$t1 = array('s');
+					$e = new mb_notice("class_wfsToDb.php: Inserting keyword ".$k[$j]." into table keyword in DB.");
 					$res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
 					if(!$res_insertKeyword){
 						$e = new mb_exception("Error while inserting keywords into the database.");
@@ -800,6 +875,7 @@
 			if (!$row) {
 				$sql1 = "INSERT INTO wfs_featuretype_keyword (fkey_keyword_id,fkey_featuretype_id)";
 				$sql1 .= "VALUES ($1,$2)";
+				$e = new mb_notice("class_wfsToDb.php: Inserting keyword id ".$keyword_id." for featuretype id ".$aWfsFeatureType->id." into DB.");
 				$v1 = array($keyword_id,$aWfsFeatureType->id);
 				$t1 = array('i','i');
 				$res1 = db_prep_query($sql1,$v1,$t1);
@@ -840,7 +916,7 @@
 	 * @param $wfsId integer
 	 */
 	private static function deleteFeatureTypeMetadataUrls ($wfsId) {
-		$e = new mb_notice("Deleting coupled WFS MetadataURLs from database.");
+		$e = new mb_notice("class_wfsToDb.php: Deleting coupled WFS MetadataURLs from database.");
 		$sql = <<<SQL
 
 DELETE FROM mb_metadata WHERE metadata_id IN (SELECT metadata_id FROM mb_metadata INNER JOIN (SELECT * FROM ows_relation_metadata WHERE (internal IS NULL OR internal != 1) AND fkey_featuretype_id IN (SELECT fkey_featuretype_id FROM wfs_featuretype WHERE fkey_wfs_id = $1)) AS relation ON mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.origin = 'capabilities')
@@ -873,7 +949,7 @@
 			$aWfsFeatureType->name
 		);
 		$t = array("i", "s");
-		$e = new mb_notice($sql . " " . print_r($v, true));
+		#$e = new mb_notice("class_wfsToDb.php: " .$sql . " " . print_r($v, true));
 		$res = db_prep_query($sql, $v, $t);
 		if ($row = db_fetch_array($res)) {
 			return $row["featuretype_id"];

Modified: trunk/mapbender/http/classes/class_wfs_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_factory.php	2013-04-29 12:03:06 UTC (rev 8609)
+++ trunk/mapbender/http/classes/class_wfs_factory.php	2013-04-29 12:14:42 UTC (rev 8610)
@@ -50,11 +50,11 @@
 
 	protected function createFeatureTypeFromUrl () {
 	}
-		
+	
 	/**
 	 * Retrieves the data of a WFS from the database and initiates the object.
-	 * 
-	 * @return 
+	 *
+	 * @return
 	 * @param $id Integer
 	 * @param $aWfs Wfs is being created by the subclass
 	 */
@@ -80,7 +80,7 @@
 				$e = new mb_notice("class_wfs_factory: owsproxyURl: ".$owsproxyUrl);
 				$hasOwsproxyUrl = true;
 			}
-			
+	
 			$aWfs->id = db_result($res, $cnt, "wfs_id");
 			$aWfs->name = db_result($res, $cnt, "wfs_name");
 			$aWfs->title = db_result($res, $cnt, "wfs_title");
@@ -88,7 +88,7 @@
 			$aWfs->getCapabilities = db_result($res, $cnt, "wfs_getcapabilities");
 			$aWfs->getCapabilitiesDoc = db_result($res, $cnt, "wfs_getcapabilities_doc");
 			$aWfs->uploadUrl = db_result($res, $cnt, "wfs_upload_url");
-			$aWfs->describeFeatureType = db_result($res, $cnt, "wfs_describefeaturetype");			
+			$aWfs->describeFeatureType = db_result($res, $cnt, "wfs_describefeaturetype");
 			if(!$hasOwsproxyUrl || !$withProxyUrls){
 				$aWfs->getFeature = db_result($res, $cnt, "wfs_getfeature");
 			}
@@ -102,13 +102,13 @@
 			else{
 				$aWfs->transaction = $owsproxyUrl;
 			}
-						
+	
 			$aWfs->fees = db_result($res, $cnt, "fees");
 			$aWfs->accessconstraints = db_result($res, $cnt, "accessconstraints");
 			$aWfs->owner = db_result($res, $cnt, "wfs_owner");
 			$aWfs->timestamp = db_result($res, $cnt, "wfs_timestamp");
 			$aWfs->timestamp_create = db_result($res, $cnt, "wfs_timestamp_create");
-			$aWfs->network_access = db_result($res, $cnt, "wfs_network_access");
+			$aWfs->wfs_network_access = db_result($res, $cnt, "wfs_network_access");
 			$aWfs->wfs_max_features = db_result($res, $cnt, "wfs_max_features");
 			$aWfs->fkey_mb_group_id = db_result($res, $cnt, "fkey_mb_group_id");
 			$aWfs->uuid = db_result($res, $cnt, "uuid");
@@ -119,95 +119,143 @@
 			$res_fe = db_prep_query($sql_fe, $v, $t);
 			$cnt_fe = 0;
 			
-			while(db_fetch_row($res_fe)){
-
-				$ft = new WfsFeatureType($aWfs);
-				$ft->id = db_result($res_fe, $cnt_fe, "featuretype_id");
-				$ft->name = db_result($res_fe, $cnt_fe, "featuretype_name");
-				$ft->title = db_result($res_fe, $cnt_fe, "featuretype_title");
-				$ft->summary = db_result($res_fe, $cnt_fe, "featuretype_abstract");
-				$ft->searchable = db_result($res_fe, $cnt_fe, "featuretype_searchable");
-				$ft->inspire_download = db_result($res_fe, $cnt_fe, "inspire_download");
-				$e = new mb_notice("class_wfs_factory: read from db FT inspire_download: ".$ft->inspire_download);
-				$ft->srs = db_result($res_fe, $cnt_fe, "featuretype_srs");
-				$latLonBbox = db_result($res_fe, $cnt_fe, "featuretype_latlon_bbox");
+			while($row = db_fetch_array($res_fe)){
+				$this->featureTypeArray[count($this->featureTypeArray)] = new WfsFeatureType($aWfs);
+				$fe_cnt = count($this->featureTypeArray)-1;
+	
+				$this->featureTypeArray[$fe_cnt]->uuid = $row["uuid"];
+				$this->featureTypeArray[$fe_cnt]->id = $row["featuretype_id"];
+	
+				$this->featureTypeArray[$fe_cnt]->name = $row["featuretype_name"];
+				$this->featureTypeArray[$fe_cnt]->title = $row["featuretype_title"];
+				$this->featureTypeArray[$fe_cnt]->summary = $row["featuretype_abstract"];
+				$this->featureTypeArray[$fe_cnt]->searchable = $row["featuretype_searchable"];
+				$this->featureTypeArray[$fe_cnt]->inspire_download = $row["inspire_download"];
+				$e = new mb_notice("class_wfs_factory: read from db FT inspire_download: ".$this->featureTypeArray[$fe_cnt]->inspire_download);
+				$this->featureTypeArray[$fe_cnt]->srs = $row["featuretype_srs"];
+				$latLonBbox = $row["featuretype_latlon_bbox"];
 				$e = new mb_notice("class_wfs_factory: FT latlonbbox: ".$latLonBbox);
 				$latLonBboxArray = explode(",", $latLonBbox);
-				$ft->latLonBboxArray['minx'] = $latLonBboxArray[0];
-				$ft->latLonBboxArray['miny'] = $latLonBboxArray[1];
-				$ft->latLonBboxArray['maxx'] = $latLonBboxArray[2];
-				$ft->latLonBboxArray['maxy'] = $latLonBboxArray[3];
-				$ft->uuid = db_result($res_fe, $cnt_fe, "uuid");
-				
+				$this->featureTypeArray[$fe_cnt]->latLonBboxArray['minx'] = $latLonBboxArray[0];
+				$this->featureTypeArray[$fe_cnt]->latLonBboxArray['miny'] = $latLonBboxArray[1];
+				$this->featureTypeArray[$fe_cnt]->latLonBboxArray['maxx'] = $latLonBboxArray[2];
+				$this->featureTypeArray[$fe_cnt]->latLonBboxArray['maxy'] = $latLonBboxArray[3];
+	
+	
 				// Elements
 				$sql_el = "SELECT * FROM wfs_element WHERE fkey_featuretype_id = $1 ORDER BY element_id";
-				$v = array($ft->id);
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
 				$t = array("i");
 				$res_el = db_prep_query($sql_el, $v, $t);
 				$cnt_el = 0;
 				while(db_fetch_row($res_el)){
-
-					$ft->addElement(
-						db_result($res_el, $cnt_el, "element_name"), 
-						db_result($res_el, $cnt_el, "element_type"),
-						db_result($res_el, $cnt_el, "element_id")
+	
+					$this->featureTypeArray[$fe_cnt]->addElement(
+							db_result($res_el, $cnt_el, "element_name"),
+							db_result($res_el, $cnt_el, "element_type"),
+							db_result($res_el, $cnt_el, "element_id")
 					);
 					$cnt_el++;
 				}
-
+	
 				// Crs
 				$sql_crs = "SELECT epsg FROM wfs_featuretype_epsg WHERE fkey_featuretype_id = $1";
-				$v = array($ft->id);
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
 				$t = array("i");
 				$res_crs = db_prep_query($sql_crs, $v, $t);
 				$cnt_crs = 0;
 				while(db_fetch_row($res_crs)){
-
-					$ft->addCrs(
-						db_result($res_crs, $cnt_crs, "epsg") 
+	
+					$this->featureTypeArray[$fe_cnt]->addCrs(
+							db_result($res_crs, $cnt_crs, "epsg")
 					);
 					$cnt_crs++;
 				}
 				
+				### read out keywords
+				$sql = "SELECT keyword FROM keyword, wfs_featuretype_keyword WHERE keyword_id = fkey_keyword_id AND fkey_featuretype_id = $1";
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
+				$t = array('i');
+				$res_ft_keywords = db_prep_query($sql,$v,$t);
+					
+				$count_ft_keywords=0;
+				while($row2 = db_fetch_array($res_ft_keywords)){
+					$this->featureTypeArray[$fe_cnt]->featuretype_keyword[$count_ft_keywords]=$row2["keyword"];
+					$count_ft_keywords++;
+				}
+				### read out wfs_featuretype_md_topic_category
+				$sql = "SELECT fkey_md_topic_category_id FROM wfs_featuretype_md_topic_category WHERE fkey_featuretype_id =  $1";
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
+				$t = array('i');
+				$res_ft_md_topic_category = db_prep_query($sql,$v,$t);
+								
+				$count_ft_md_topic_category=0;
+				while($row2 = db_fetch_array($res_ft_md_topic_category)){
+					$this->featureTypeArray[$fe_cnt]->featuretype_md_topic_category_id[$count_ft_md_topic_category]=$row2["fkey_md_topic_category_id"];
+					$count_ft_md_topic_category++;
+				}
+				### read out wfs_featuretype_inspire_category
+				$sql = "SELECT fkey_inspire_category_id FROM wfs_featuretype_inspire_category WHERE fkey_featuretype_id =  $1";
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
+				$t = array('i');
+				$res_ft_inspire_category = db_prep_query($sql,$v,$t);
+								
+				$count_ft_inspire_category=0;
+				while($row2 = db_fetch_array($res_ft_inspire_category)){
+					$this->featureTypeArray[$fe_cnt]->featuretype_inspire_category_id[$count_ft_inspire_category]=$row2["fkey_inspire_category_id"];
+					$count_ft_inspire_category++;
+				}
+				### read out wfs_featuretype_custom_category
+				$sql = "SELECT fkey_custom_category_id FROM wfs_featuretype_custom_category WHERE fkey_featuretype_id =  $1";
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
+				$t = array('i');
+				$res_ft_custom_category = db_prep_query($sql,$v,$t);
+								
+				$count_ft_custom_category=0;
+				while($row2 = db_fetch_array($res_ft_custom_category)){
+					$this->featureTypeArray[$fe_cnt]->featuretype_custom_category_id[$count_ft_custom_category]=$row2["fkey_custom_category_id"];
+					$count_ft_custom_category++;
+				}
+				
 				// MetadataURLs
 				$sql_metadata = "SELECT link, linktype, md_format FROM mb_metadata WHERE metadata_id IN ";
 				$sql_metadata .= "(SELECT metadata_id FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE ";
 				$sql_metadata .= "fkey_featuretype_id = $1) as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND ";
 				$sql_metadata .= "mb_metadata.origin = 'capabilities')";
-				$v = array($ft->id);
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
 				$t = array("i");
 				$res_metadata = db_prep_query($sql_metadata, $v, $t);
 				$cnt_metadata = 0;
 				while(db_fetch_row($res_metadata)){
 					$metadataURL->href = db_result($res_metadata, $cnt_metadata, "link");
-					$metadataURL->type = db_result($res_metadata, $cnt_metadata, "linktype");		
-					$metadataURL->format = db_result($res_metadata, $cnt_metadata, "md_format");	
-					$ft->addMetadataUrl($metadataURL);
+					$metadataURL->type = db_result($res_metadata, $cnt_metadata, "linktype");
+					$metadataURL->format = db_result($res_metadata, $cnt_metadata, "md_format");
+					$this->featureTypeArray[$fe_cnt]->addMetadataUrl($metadataURL);
 					$cnt_metadata++;
 				}
-				
+	
 				//Namespaces
 				$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
-				$v = array($ft->id);
+				$v = array($this->featureTypeArray[$fe_cnt]->id);
 				$t = array("i");
 				$res_ns = db_prep_query($sql_ns, $v, $t);
 				$cnt_ns = 0;
 				while(db_fetch_row($res_ns)){
-
-					$ft->addNamespace(
-						db_result($res_ns, $cnt_ns, "namespace"),
-						db_result($res_ns, $cnt_ns, "namespace_location")
+	
+					$this->featureTypeArray[$fe_cnt]->addNamespace(
+							db_result($res_ns, $cnt_ns, "namespace"),
+							db_result($res_ns, $cnt_ns, "namespace_location")
 					);
 					$cnt_ns++;
 				}
-				
-				$aWfs->addFeatureType($ft);
-				
+	
+				$aWfs->addFeatureType($this->featureTypeArray[$fe_cnt]);
+	
 				$cnt_fe++;
 			}
 			$cnt++;
-	    }
-		return $aWfs;	
+		}
+		return $aWfs;
 	}
 }
 ?>

Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2013-04-29 12:03:06 UTC (rev 8609)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2013-04-29 12:14:42 UTC (rev 8610)
@@ -769,7 +769,6 @@
 		
 		$wfs = $wfsFactory->createFromDb($wfsId);
 		
-
 		if (is_null($wfs)) {
 			$ajaxResponse->setSuccess(false);
 			$ajaxResponse->setMessage(_mb("Invalid WFS ID."));
@@ -831,7 +830,6 @@
 			}
 		}
 
-
 		try {
 			$featuretypeId = intval($data->featuretype->featuretype_id);
 		}
@@ -841,64 +839,67 @@
 			$ajaxResponse->send();		
 		}
 
-
-
-
-
 		if ($featuretypeId) {
-			$e = new mb_notice("Got following featuretype id from wms metadata editor client: ".$featuretypeId);
-			$featuretype = &$wfs->findFeatureTypeReferenceById($featuretypeId);
-			if (!is_null($featuretype)) {
+			$e = new mb_notice("Got following featuretype id from wfs metadata editor client: ".$featuretypeId);
+			try {
+				$featuretype = &$wfs->findFeatureTypeReferenceById($featuretypeId);
+			}
+			catch (Exception $e) {
+				$ajaxResponse->setSuccess(false);
+				$ajaxResponse->setMessage(_mb("Could not get featuretype with ID ".$featuretypeId." from wfs object by reference!"));
+				$ajaxResponse->send();
+			}
+			
+			$columns = array(
+				"summary", 
+				"title",
+				"featuretype_keyword",
+				"inspire_download",
+				"featuretype_md_topic_category_id",
+				"featuretype_inspire_category_id",
+				"featuretype_custom_category_id"
+			);			
+			
+			//extract relevant information from json and fill them into the wfs object
+			foreach ($columns as $c) {
 				
-				$columns = array(
-					"summary", 
-					"title",
-					"featuretype_keyword",
-					"inspire_download",
-					"featuretype_md_topic_category_id",
-					"featuretype_inspire_category_id",
-					"featuretype_custom_category_id"
-				);			
-	
-				foreach ($columns as $c) {
-					if ($c === "summary") {
-						$value = $data->featuretype->featuretype_abstract;
+				if ($c === "summary") {
+					$value = $data->featuretype->featuretype_abstract;
+				}
+				elseif ($c === "title") {
+					$value = $data->featuretype->featuretype_title;
+				}
+				else {
+					$value = $data->featuretype->$c;
+				}	
+				if ($c === "featuretype_keyword") {
+					$featuretype->$c = explode(",", $value);
+					foreach ($featuretype->$c as &$val) {
+						$val = trim($val);
 					}
-					elseif ($c === "title") {
-						$value = $data->featuretype->featuretype_title;
+				}
+				elseif ($c === "featuretype_md_topic_category_id" 
+					|| $c === "featuretype_inspire_category_id"
+					|| $c === "featuretype_custom_category_id"
+				) {
+					if (!is_array($value)) {
+						$featuretype->$c = array($value);
 					}
 					else {
-						$value = $data->featuretype->$c;
-					}	
-					if ($c === "featuretype_keyword") {
-						$featuretype->$c = explode(",", $value);
-						foreach ($featuretype->$c as &$val) {
-							$val = trim($val);
-						}
+						$featuretype->$c = $value;
 					}
-					elseif ($c === "featuretype_md_topic_category_id" 
-						|| $c === "featuretype_inspire_category_id"
-						|| $c === "featuretype_custom_category_id"
-					) {
-						if (!is_array($value)) {
-							$featuretype->$c = array($value);
-						}
-						else {
-							$featuretype->$c = $value;
-						}
+				}
+				elseif ($c === "inspire_download") {
+					if ($value == "on") {
+						$featuretype->$c = intval('1');
+					} else {
+						$featuretype->$c = intval('0');
 					}
-					elseif ($c === "inspire_download") {
-						if ($value == "on") {
-							$featuretype->$c = intval('1');
-						} else {
-							$featuretype->$c = intval('0');
-						}
+				}
+				else {
+					if (!is_null($value)) {
+						$featuretype->$c = $value;
 					}
-					else {
-						if (!is_null($value)) {
-							$featuretype->$c = $value;
-						}
-					}
 				}
 			}
 		}
@@ -907,8 +908,12 @@
 		} else {
 			$wfs->wfs_network_access = intval('0');
 		}
-		$wfs->update(true); //parameter for metadata only update - some things are not pulled when creating object from database and some things need not to be updated.
+		
+		if($wfs->wfs_max_features == "") {
+			$wfs->wfs_max_features = intval('1000');
+		}
 
+		$wfs->update($wfsId, true); //parameter for metadata only update - some things are not pulled when creating object from database and some things need not to be updated.
 		
 		$ajaxResponse->setMessage("Updated WFS metadata for ID " . $wfsId);
 		$ajaxResponse->setSuccess(true);		



More information about the Mapbender_commits mailing list