[Mapbender-commits] r6993 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Oct 1 09:21:29 EDT 2010
Author: christoph
Date: 2010-10-01 13:21:29 +0000 (Fri, 01 Oct 2010)
New Revision: 6993
Modified:
trunk/mapbender/http/classes/class_wmc.php
Log:
added function removeWms
formatting
Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php 2010-10-01 13:19:53 UTC (rev 6992)
+++ trunk/mapbender/http/classes/class_wmc.php 2010-10-01 13:21:29 UTC (rev 6993)
@@ -30,41 +30,41 @@
/**
* Implementation of a Web Map Context Document, WMC 1.1.0
- *
+ *
* Use cases:
- *
+ *
* Instantiation (1) create a WMC object from a WMC XML document
* $myWmc = new wmc();
* $myWmc->createFromXml($xml);
- *
+ *
* If you want to create a WMC object from a WMC in the database
* $xml = wmc::getDocument($wmcId);
* $myWmc = new wmc();
* $myWmc->createFromXml($xml);
- *
- *
+ *
+ *
* Instantiation (2) create a WMC from the client side
* $myWmc = new wmc();
* $myWmc->createFromJs($mapObject, $generalTitle, $extensionData);
- *
+ *
* (creates a WMC from the JS data and then creates an object from that WMC)
- *
+ *
* Output (1) (do Instantiation first) Load a WMC into client
* This will return an array of JS statements
- *
+ *
* $myWmc->toJavaScript();
- *
+ *
* Output (2) (do Instantiation first) Merge with another WMC, then load
- *
+ *
* $myWmc->merge($anotherWmcXml);
* $myWmc->toJavaScript();
- *
+ *
*/
class wmc {
- /**
- * Representing the main map in a map application
- * @var Map
- */
+/**
+ * Representing the main map in a map application
+ * @var Map
+ */
var $mainMap;
/**
@@ -83,17 +83,17 @@
* @var String
*/
var $xml;
-
+
// constants
var $saveWmcAsFile = false;
var $extensionNamespace = "mapbender";
var $extensionNamespaceUrl = "http://www.mapbender.org/context";
-
+
// set in constructor
var $wmc_id;
var $userId;
- var $timestamp;
- var $public;
+ var $timestamp;
+ var $public;
// set during parsing
var $wmc_version;
@@ -124,21 +124,21 @@
var $wmc_descriptionurl_format;
var $wmc_descriptionurl_type;
- var $inspireCats;
+ var $inspireCats;
public function __construct () {
$this->userId = Mapbender::session()->get("mb_user_id");
$this->wmc_id = time();
$this->timestamp = time();
- }
-
+ }
+
// ---------------------------------------------------------------------------
// INSTANTIATION
// ---------------------------------------------------------------------------
/**
* Parses the XML string and instantiates the WMC object.
- *
+ *
* @param $xml String
*/
public function createFromXml ($xml) {
@@ -147,37 +147,34 @@
/**
* Loads a WMC from the database.
- *
+ *
* @param integer $wmc_id the ID of the WMC document in the database table "mb_user_wmc"
*/
- function createFromDb($wmcId){
+ function createFromDb($wmcId) {
$doc = wmc::getDocument($wmcId);
if ($doc === false) {
return false;
}
$this->createObjFromWMC_xml($doc);
- $sql = "SELECT wmc_timestamp, wmc_title, wmc_public " .
+ $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)";
- $v = array($wmcId, Mapbender::session()->get("mb_user_id"));
- $t = array("s", "i");
-
- $res = db_prep_query($sql,$v,$t);
- if(db_error()) { return false; }
- if($row = db_fetch_row($res)) {
- $this->wmc_id = $wmcId;
- $this->timestamp = $row[0];
- $this->title = $row[1];
- $this->public = $row[2];
-
- }
- else {
- return false;
+ $v = array($wmcId, Mapbender::session()->get("mb_user_id"));
+ $t = array("s", "i");
+
+ $res = db_prep_query($sql,$v,$t);
+ if(db_error()) { return false; }
+ if($row = db_fetch_row($res)) {
+ $this->wmc_id = $wmcId;
+ $this->timestamp = $row[0];
+ $this->title = $row[1];
+ $this->public = $row[2];
+ return true;
}
- return true;
+ return false;
}
public function createFromApplication ($appId) {
- // get the map objects "overview" and "mapframe1"
+ // get the map objects "overview" and "mapframe1"
$this->mainMap = map::selectMainMapByApplication($appId);
$this->overviewMap = map::selectOverviewMapByApplication($appId);
$this->createXml();
@@ -186,30 +183,30 @@
/**
* Creates a WMC object from a JS map object {@see map_obj.js}
- *
+ *
* @param object $mapObject a map object
* @param integer $user_id the ID of the current user
* @param string $generalTitle the desired title of the WMC
- * @param object $extensionData data exclusive to Mapbender, which will be
+ * @param object $extensionData data exclusive to Mapbender, which will be
* mapped into the extension part of the WMC
*/
public function createFromJs($mapObject, $generalTitle,$extensionData, $id=null) {
-
+
if (count($mapObject) > 2) {
$e = new mb_exception("Save WMC only works for two concurrent map frames (overview plus main) at the moment.");
}
-
- // set extension data
+
+ // set extension data
$this->generalExtensionArray = $extensionData;
if ($id) {
- //set id
+ //set id
$this->wmc_id = $id;
}
-
+
// set title
$this->wmc_title = $generalTitle;
-
+
// create the map objects
for ($i = 0; $i < count($mapObject); $i++) {
$currentMap = new Map();
@@ -223,14 +220,14 @@
}
}
-
+
// create XML
$this->createXml();
$this->saveAsFile();
return true;
}
-
+
// ---------------------------------------------------------------------------
// DATABASE FUNCTIONS
// ---------------------------------------------------------------------------
@@ -239,8 +236,8 @@
$sql .= "WHERE wmc_public = 1 GROUP BY wmc_id";
$res_wmc = db_query($sql);
- $wmcArray = array();
- while($row = db_fetch_array($res_wmc)){
+ $wmcArray = array();
+ while($row = db_fetch_array($res_wmc)) {
array_push($wmcArray, $row["wmc_id"]);
}
return $wmcArray;
@@ -248,12 +245,12 @@
public function getAccessibleWmcs ($user) {
$wmcArray = array();
-
- // get WMC ids
+
+ // get WMC ids
$wmcOwnerArray = $user->getWmcByOwner();
-
+
$publicWmcIdArray = $this->getPublicWmcIds();
-
+
return array_keys( array_flip(array_merge($wmcOwnerArray, $publicWmcIdArray)));
}
@@ -261,47 +258,47 @@
public function selectByUser ($user) {
$wmcArray = array();
-
- // get WMC ids
+
+ // get WMC ids
$wmcOwnerArray = $user->getWmcByOwner();
-
+
$publicWmcIdArray = self::getPublicWmcIds();
-
+
$wmcIdArray = array_keys( array_flip(array_merge($wmcOwnerArray, $publicWmcIdArray)));
// get WMC data
$v = array();
$t = array();
$wmcIdList = "";
-
+
for ($i = 0; $i < count($wmcIdArray); $i++) {
- if ($i > 0) {
+ if ($i > 0) {
$wmcIdList .= ",";
}
$wmcIdList .= "$".($i+1);
array_push($v, $wmcIdArray[$i]);
array_push($t, 's');
}
-
+
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 .= "ORDER BY wmc_timestamp DESC";
-
+
$res = db_prep_query($sql, $v, $t);
- while($row = db_fetch_assoc($res)){
+ while($row = db_fetch_assoc($res)) {
$currentResult = array();
$currentResult["id"] = $row["wmc_id"];
$currentResult["abstract"] = $row["abstract"];
$currentResult["title"] = administration::convertIncomingString($row["wmc_title"]);
- $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["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) &&
+ in_array($currentResult["id"], $publicWmcIdArray) &&
!in_array($currentResult["id"], $wmcOwnerArray)) || $user->isPublic()) ?
true : false;
-
+
// get categories
$currentResult["categories"] = $this->getCategoriesById($currentResult["id"], $user);
$currentResult["keywords"] = $this->getKeywordsById($currentResult["id"], $user);
@@ -316,10 +313,10 @@
if (!in_array($id, $wmcArray)) {
return array();
}
-
+
$keywordArray = array();
-
- $sql = "SELECT DISTINCT k.keyword FROM keyword AS k, wmc_keyword AS w " .
+
+ $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";
$v = array($id);
$t = array("s");
@@ -335,12 +332,12 @@
if (!in_array($id, $wmcArray)) {
return array();
}
-
+
$keywordArray = array();
-
- $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 " .
+
+ $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";
$v = array($id);
$t = array("s");
@@ -351,10 +348,10 @@
return $keywordArray;
}
- private function compareWms ($a, $b) {
+ private function compareWms ($a, $b) {
if ($a["id"] === $b["id"]) return 0;
- return -1;
- }
+ return -1;
+ }
public function getAllWms () {
$wmsArray = $this->mainMap->getWmsArray();
$resultObj = array();
@@ -364,56 +361,56 @@
continue;
}
$resultObj[]= array(
- "title" => $wmsArray[$i]->wms_title,
+ "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;
+ return $resultObj;
}
public function getWmsWithoutId () {
- $wmsArray = $this->getAllWms();
+ $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"],
+ "title" => $wmsArray[$i]["title"],
"id" => $wmsArray[$i]["id"],
"index" => $i
);
}
- return $resultObj;
+ return $resultObj;
}
-
+
public function getWmsWithId () {
return array_values(array_udiff(
- $this->getAllWms(),
+ $this->getAllWms(),
$this->getWmsWithoutId(),
array("wmc", "compareWms")
));
}
-
+
public function getValidWms () {
$inv = $this->getInvalidWms();
$withId = $this->getWmsWithId();
return array_values(array_udiff(
- $withId,
+ $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');
@@ -421,17 +418,17 @@
$layerRow = db_fetch_row($res);
if (intval($layerRow[0]) === 0) {
$resultObj[]= array(
- "title" => $wmsArray[$i]["title"],
+ "title" => $wmsArray[$i]["title"],
"id" => intval($wmsArray[$i]["id"]),
"index" => $wmsArray[$i]["index"]
);
- }
+ }
}
return $resultObj;
}
-
+
public function getWmsWithPermission ($user) {
- $wmsArray = $this->getValidWms();
+ $wmsArray = $this->getValidWms();
$resultObj = array();
for ($i = 0; $i < count($wmsArray); $i++) {
@@ -439,39 +436,39 @@
if ($user->isWmsAccessible($currentWmsId)) {
$resultObj[]= array(
- "title" => $wmsArray[$i]["title"],
+ "title" => $wmsArray[$i]["title"],
"id" => intval($currentWmsId),
"index" => $wmsArray[$i]["index"]
);
- }
+ }
}
- return $resultObj;
+ return $resultObj;
}
-
+
public function getWmsWithoutPermission ($user) {
return array_values(array_udiff(
- $this->getValidWms(),
- $this->getWmsWithPermission($user),
- array("wmc", "compareWms")
+ $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")
+ $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";
+ $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);
@@ -479,59 +476,59 @@
$status = intval($statusRow[0]);
if (isset($status) && $status < 0) {
$resultObj[]= array(
- "title" => $wmsArray[$i]["title"],
+ "title" => $wmsArray[$i]["title"],
"id" => $currentWmsId,
"index" => $wmsArray[$i]["index"]
);
}
}
- return $resultObj;
+ return $resultObj;
}
public function updateUrlsFromDb () {
$query_mbWMSId = "/wmc:ViewContext/wmc:LayerList/wmc:Layer/wmc:Extension/mapbender:wms_id";
try {
$WMCDoc = DOMDocument::loadXML($this->toXml());
- }
+ }
catch (Exception $E) {
new mb_exception("WMC XML is broken.");
- }
-
+ }
+
$xpath = new DOMXPath($WMCDoc);
$xpath->registerNamespace("wmc","http://www.opengis.net/context");
$xpath->registerNamespace("mapbender","http://www.mapbender.org/context");
$xpath->registerNamespace("xlink","http://www.w3.org/1999/xlink");
-
+
$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 AND " .
+ $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");
-
+
$res = db_prep_query($sql,$v,$t);
if (db_error()) {
- true;
+ true;
} //FIMXE: PROPER ERROR MESSAGE
-
+
if($row = db_fetch_array($res)) {
$wms_timestamp = $row["wms_timestamp"];
if ($this->timestamp < $wms_timestamp) {
// wmc is fresh, life is good
}
- else{
+ else {
$MapResources = $xpath->query("../../wmc:Server/wmc:OnlineResource",$WMSId);
foreach($MapResources as $MapResource) {
$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["wms_getlegendurl"];
$origurl = explode('&', $LegendResource->getAttribute("xlink:href"),2);
- $url = $base . $origurl[1];
+ $url = $base . $origurl[1];
$LegendResource->setAttribute("xlink:href",$url);
}
}
@@ -544,16 +541,16 @@
/**
* Stores this WMC in the database. The WMC has to be instantiated first, see above.
- *
+ *
* @return mixed[] an assoc array with attributes "success" (boolean) and "message" (String).
*/
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;
@@ -561,19 +558,19 @@
$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg);
return $result;
}
-
+
$overwrite = ($user->isPublic())? false: $overwrite;
-
+
//put keywords into Document
try {
$WMCDoc = DOMDocument::loadXML($this->toXml());
- }
+ }
catch (Exception $E) {
new mb_exception("WMC XML is broken.");
- }
+ }
$NewDoc = new DOMDocument();
-
+
$xpath = new DOMXPath($WMCDoc);
$xpath->registerNamespace("wmc","http://www.opengis.net/context");
$xpath->registerNamespace("mapbender","http://www.mapbender.org/context");
@@ -583,48 +580,48 @@
$query_general = "/wmc:ViewContext/wmc:General";
$DocKeywordLists = $xpath->query($query_KeywordList);
// we just use a single <general> element
-
+
$NewKeywordList = new DOMElement('KeywordList','','http://opengis.net/context');
$NewDoc->appendChild($NewKeywordList);
- foreach($this->keyword as $keyword){
+ foreach($this->keyword as $keyword) {
$Keyword = new DOMElement('Keyword',$keyword, 'http://opengis.net/context');
$NewKeywordList->appendChild($Keyword);
}
-
- $generalList = $xpath->query($query_general);
+
+ $generalList = $xpath->query($query_general);
$general = $generalList->item(0);
- if($DocKeywordLists->item(0)){
+ if($DocKeywordLists->item(0)) {
$general->replaceChild($NewKeywordList,$DocKeywordList->item(0));
- }else{
+ }else {
$tmpNode = $WMCDoc->importNode($NewKeywordList,true);
$general->appendChild($tmpNode);
}
-
+
$this->xml = $WMCDoc->saveXML();
-
+
db_begin();
-
+
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;";
- $v = array($this->userId, $this->wmc_id);
- $t = array("i","i");
-
- $res = db_prep_query($findsql,$v,$t);
+
+ $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;";
+ $v = array($this->userId, $this->wmc_id);
+ $t = array("i","i");
+
+ $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;
+ return $result;
}
-
- if($row = db_fetch_row($res)) {
+
+ 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;";
$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]);
+ $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];
@@ -632,18 +629,18 @@
$delv = array($wmc_DB_ID);
$delt = array("s");
db_prep_query($delsql, $delv,$delt);
-
+
$delkwsql = "DELETE FROM wmc_keyword WHERE fkey_wmc_id = $1;";
$delkwv = array($wmc_DB_ID);
$delkwt = array("s");
db_prep_query($delkwsql, $delkwv,$delkwt);
-
-
-
+
+
+
}
- else{
- $sql = "INSERT INTO mb_user_wmc (" .
- "wmc_id, fkey_user_id, wmc, wmc_title, wmc_public, wmc_timestamp, wmc_timestamp_create, " .
+ else {
+ $sql = "INSERT INTO mb_user_wmc (" .
+ "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(),
@@ -651,75 +648,74 @@
$t = array("s", "i", "s", "s", "i", "s","s", "s","s","i","i","i", "i");
}
}
- else{
-
- $sql = "INSERT INTO mb_user_wmc (" .
- "wmc_id, fkey_user_id, wmc, wmc_title, wmc_public, wmc_timestamp, wmc_timestamp_create, " .
+ else {
+
+ $sql = "INSERT INTO mb_user_wmc (" .
+ "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(),
- $this->wmc_abstract, $this->wmc_srs, $this->wmc_extent->minx, $this->wmc_extent->miny, $this->wmc_extent->maxx, $this->wmc_extent->maxy);
+ $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");
-
+
}
-
-
- $res = db_prep_query($sql, $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);
- }
- 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
+
+
+ $res = db_prep_query($sql, $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);
+ }
+ 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
if(!isset($wmc_DB_ID)) { $wmc_DB_ID = $this->wmc_id; }
-
+
// update keywords
- foreach($this->keyword as $keyword){
+ foreach($this->keyword as $keyword) {
- // if a keyword does not yet exist, create it
- $keywordExistsSql = "SELECT keyword FROM keyword WHERE keyword = $1";
- $keywordCreateSql = "INSERT INTO keyword (keyword) VALUES($1);";
- $v = array($keyword);
- $t = array("s");
- $res = db_prep_query($keywordExistsSql,$v,$t);
- if(db_num_rows($res) == 0){
+ // if a keyword does not yet exist, create it
+ $keywordExistsSql = "SELECT keyword FROM keyword WHERE keyword = $1";
+ $keywordCreateSql = "INSERT INTO keyword (keyword) VALUES($1);";
+ $v = array($keyword);
+ $t = array("s");
+ $res = db_prep_query($keywordExistsSql,$v,$t);
+ if(db_num_rows($res) == 0) {
$res = db_prep_query($keywordCreateSql,$v,$t);
- if($a = db_error()){
- }
- }
-
-
-
+ if($a = db_error()) {
+ }
+ }
+
+
+
$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 );";
$v = array($wmc_DB_ID, $keyword,$wmc_DB_ID);
$t = array("s","s","s");
$res = db_prep_query($keywordsql, $v, $t);
- if($a = db_error()){
+ if($a = db_error()) {
}
-
+
}
// update categories
$this->inspireCats = $this->inspireCats? $this->inspireCats: array();
- foreach($this->inspireCats as $catId)
- {
+ foreach($this->inspireCats as $catId) {
$catSql = "INSERT INTO wmc_md_topic_category (fkey_wmc_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);
-
+
}
-
- $result["success"] = true;
- $msg = "WMC document '" . $this->wmc_title . "' has been saved.";
- $result["message"] = $msg;
- $e = new mb_notice("mod_insertWMCIntoDB: WMC '" . $this->wmc_title . "' saved successfully.");
- }
+
+ $result["success"] = true;
+ $msg = "WMC document '" . $this->wmc_title . "' has been saved.";
+ $result["message"] = $msg;
+ $e = new mb_notice("mod_insertWMCIntoDB: WMC '" . $this->wmc_title . "' saved successfully.");
+ }
}
else {
$result["success"] = false;
@@ -727,25 +723,24 @@
$result["message"] = $errMsg;
$e = new mb_exception("mod_insertWMCIntoDB: " . $errMsg .")");
}
- db_commit();
+ db_commit();
return $result;
}
-
+
/*
* 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";
- $v = array($xml,$id);
- $t = array("s","i");
- $res = db_prep_query($sql,$v,$t);
- if(db_error()) { $e = new mb_exception("There was an error saving an updated WMC"); }
- }
-
+ public function update_existing($xml,$id) {
+ $sql = "UPDATE mb_user_wmc SET wmc = $1 WHERE wmc_id = $2";
+ $v = array($xml,$id);
+ $t = array("s","i");
+ $res = db_prep_query($sql,$v,$t);
+ if(db_error()) { $e = new mb_exception("There was an error saving an updated WMC"); }
+ }
+
/**
- * deletes a {@link http://www.mapbender.org/index.php/WMC WMC}
+ * deletes a {@link http://www.mapbender.org/index.php/WMC WMC}
* entry specified by wmc_id and user_id
*
* @param integer the user_id
@@ -757,17 +752,16 @@
$userId = Mapbender::session()->get("mb_user_id");
}
- try {
- $user = new user($userId);
- } catch (Exception $E) {
- return $false;
- }
-
- if($user->isPublic())
- {
- return $false;
- }
+ try {
+ $user = new user($userId);
+ } catch (Exception $E) {
+ return $false;
+ }
+ if($user->isPublic()) {
+ return $false;
+ }
+
$sql = "DELETE FROM mb_user_wmc ";
$sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
$v = array($userId, $wmcId);
@@ -785,7 +779,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_id = $1 AND " .
"(fkey_user_id = $2 OR wmc_public = 1)";
$v = array($id, Mapbender::session()->get("mb_user_id"));
$t = array('s', 'i');
@@ -803,7 +797,7 @@
* @param $id String the WMC id
*/
public static function getDocumentByTitle ($title) {
- $sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_title = $1 AND " .
+ $sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_title = $1 AND " .
"(fkey_user_id = $2 OR wmc_public = 1)";
$v = array($title, Mapbender::session()->get("mb_user_id"));
$t = array('s', 'i');
@@ -819,27 +813,26 @@
* sets the WMC's public flag
* @param $public boolean wether access should be public
*/
- public function setPublic($public)
- {
- $currentUser = new User(Mapbender::session()->get("mb_user_id"));
- if ($currentUser->isPublic()) {
+ public function setPublic($public) {
+ $currentUser = new User(Mapbender::session()->get("mb_user_id"));
+ if ($currentUser->isPublic()) {
return false;
- }
- $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;";
- $v = array($public,$wmcId, $currentUser->id);
- $t = array("i","s","i");
- $res = db_prep_query($sql,$v,$t);
- if(db_error()){
- return false;
- }
- return true;
- }
+ }
+ $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;";
+ $v = array($public,$wmcId, $currentUser->id);
+ $t = array("i","s","i");
+ $res = db_prep_query($sql,$v,$t);
+ if(db_error()) {
+ return false;
+ }
+ return true;
+ }
// ---------------------------------------------------------------------------
// GETTER FUNCTIONS
// ---------------------------------------------------------------------------
-
+
/**
* @return string the title of the WMC.
*/
@@ -850,16 +843,16 @@
private function getLayerWithoutIdArray () {
$layerWithoutWmsIdArray = array();
$layerWithoutLayerIdArray = array();
-
+
// check if WMS IDs exist
$wmsArray = $this->mainMap->getWmsArray();
for ($i = 0; $i < count($wmsArray); $i++) {
- $currentWms = $wmsArray[$i];
+ $currentWms = $wmsArray[$i];
if (!is_numeric($currentWms[$currentId])) {
array_push($layerWithoutWmsIdArray, $currentId);
}
}
-
+
// check if layer IDs exist
for ($i = 0; $i < count($layerIdArray); $i++) {
$currentId = $layerIdArray[$i];
@@ -875,7 +868,7 @@
// ---------------------------------------------------------------------------
// OUTPUT FUNCTIONS
// ---------------------------------------------------------------------------
-
+
/**
* Wrapper function, returns XML at the moment
* @return String
@@ -886,18 +879,18 @@
/**
* Returns the XML document if available
- *
+ *
* @return String The XML document; if unavailable, null is returned.
*/
public function toXml () {
-// if (!$this->xml) {
- $this->createXml();
-// }
+ // if (!$this->xml) {
+ $this->createXml();
+ // }
return $this->xml;
}
private function incrementLoadCount ($wms) {
- // counts how often a layer has been loaded
+ // counts how often a layer has been loaded
$monitor = new Layer_load_count();
foreach ($wms->objLayer as $l) {
$monitor->increment($l->layer_uid);
@@ -910,17 +903,17 @@
$wmcJsArray = array();
for ($i = 0; $i < count($wmsArray); $i++) {
$currentWms = $wmsArray[$i];
-
+
$wmcJsArray[] = $currentWms->createJsObjFromWMS_();
$this->incrementLoadCount($currentWms);
}
return $wmcJsArray;
}
-
+
public function featuretypeConfToJavaScript() {
$wfsConfIds = $this->generalExtensionArray['WFSCONFIDSTRING'];
$featuretypeConfs = array();
- $featuretypeConfArray = is_string($wfsConfIds) ?
+ $featuretypeConfArray = is_string($wfsConfIds) ?
explode(",", $wfsConfIds) : array();
for ($i = 0; $i < count($featuretypeConfArray); $i++) {
$featuretypeConf = WfsConfiguration::createFromDb($featuretypeConfArray[$i]);
@@ -930,9 +923,32 @@
$featuretypeConfObj = $featuretypeConfObj->encode($featuretypeConfs);
return $featuretypeConfObj;
}
+
+ public function removeWms ($wmsIndexArray) {
+ $wmsArray = $this->mainMap->getWmsArray();
+
+ // remove WMS from overview map
+ if (!is_null($this->overviewMap)) {
+ $ovIndices = array();
+ $ovWmsArray = $this->overviewMap->getWmsArray();
+ for ($i = 0; $i < count($ovWmsArray); $i++) {
+ for ($j = 0; $j < count($wmsArray); $j++) {
+ if ($ovWmsArray[$i]->equals($wmsArray[$j]) && in_array($j, $skipWmsArray)) {
+ $ovIndices[]= $i;
+ break;
+ }
+ }
+ }
+ $this->overviewMap->removeWms($ovIndices);
+ }
+
+ // remove WMS from main map
+ $this->mainMap->removeWms($wmsIndexArray);
+ }
+
/**
* Returns an array of JavaScript statements
- *
+ *
* @return String[]
*/
public function toJavaScript () {
@@ -947,13 +963,13 @@
// will contain the JS code to create the maps
// representing the state stored in this WMC
$wmcJsArray = array();
-
+
// set general extension data
if (count($this->generalExtensionArray) > 0) {
$json = new Mapbender_JSON();
- array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";");
+ array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";");
}
-
+
// reset WMS data
array_push($wmcJsArray, "wms = [];");
array_push($wmcJsArray, "wms_layer_count = 0;");
@@ -971,8 +987,8 @@
for ($i = 0; $i < count($ovWmsArray); $i++) {
for ($j = 0; $j < count($wmsArray); $j++) {
if ($ovWmsArray[$i]->equals($wmsArray[$j]) && !in_array($j, $skipWmsArray)) {
- $overviewWmsIndex = $j;
- $wmsIndexOverview = $i;
+ $overviewWmsIndex = $j;
+ $wmsIndexOverview = $i;
break;
}
}
@@ -987,25 +1003,25 @@
array_push($wmcJsArray, $wmsArray[$i]->createJsObjFromWMS_());
$this->incrementLoadCount($wmsArray[$i]);
}
-
+
// delete existing map objects...
-// array_push($wmcJsArray, "mb_mapObj = [];");
+ // array_push($wmcJsArray, "mb_mapObj = [];");
// .. and add the overview map (if exists) and set map request
if ($this->overviewMap !== null) {
$wmcJsArray = array_merge(
- $wmcJsArray,
+ $wmcJsArray,
$this->overviewMap->toJavaScript(
- "{wms:wms,wmsIndexOverview:" . $overviewWmsIndex . "}"
+ "{wms:wms,wmsIndexOverview:" . $overviewWmsIndex . "}"
)
);
}
// .. and add main map ..
$wmcJsArray = array_merge(
- $wmcJsArray,
+ $wmcJsArray,
$this->mainMap->toJavaScript(
- "{wms:wms,wmsIndexOverview:null}"
+ "{wms:wms,wmsIndexOverview:null}"
)
);
@@ -1013,38 +1029,38 @@
if ($this->overviewMap !== null) {
for ($i = 0; $i < count($ovWmsArray[$wmsIndexOverview]->objLayer); $i++) {
$visStr = "Mapbender.modules['".$this->overviewMap->getFrameName().
-// "'].wms[" .$wmsIndexOverview . "].handleLayer(" .
-// The above doesn't work.
-// But there is only one WMS in the overview anyway! The index 0 is hard wired for now.
- "'].wms[0].handleLayer(" .
- "'" . $ovWmsArray[$wmsIndexOverview]->objLayer[$i]->layer_name . "', " .
- "'visible', " .
+ // "'].wms[" .$wmsIndexOverview . "].handleLayer(" .
+ // The above doesn't work.
+ // But there is only one WMS in the overview anyway! The index 0 is hard wired for now.
+ "'].wms[0].handleLayer(" .
+ "'" . $ovWmsArray[$wmsIndexOverview]->objLayer[$i]->layer_name . "', " .
+ "'visible', " .
($ovWmsArray[$wmsIndexOverview]->objLayer[$i]->gui_layer_visible ? 1 : 0) . ");";
array_push($wmcJsArray, $visStr);
}
array_push($wmcJsArray, "Mapbender.modules['".$this->overviewMap->getFrameName().
- "'].restateLayers(" . $ovWmsArray[$wmsIndexOverview]->wms_id . ");");
+ "'].restateLayers(" . $ovWmsArray[$wmsIndexOverview]->wms_id . ");");
}
// .. request the map
array_push($wmcJsArray, "Mapbender.modules['".$this->mainMap->getFrameName().
- "'].setMapRequest();");
+ "'].setMapRequest();");
if ($this->overviewMap !== null) {
array_push($wmcJsArray, "Mapbender.modules['".$this->overviewMap->getFrameName().
- "'].setMapRequest();");
+ "'].setMapRequest();");
}
array_push($wmcJsArray, "eventAfterLoadWMS.trigger();");
return $wmcJsArray;
}
-
+
// ------------------------------------------------------------------------
// manipulation
// ------------------------------------------------------------------------
/**
* Merges this WMC with another WMC.
* The settings of the other WMC overwrite the settings of this WMC.
- *
+ *
* @return void
* @param $xml2 Object
*/
@@ -1060,7 +1076,7 @@
/**
* Appends the layers of another WMC to this WMC.
- *
+ *
* @return void
* @param $xml2 Object
*/
@@ -1070,24 +1086,24 @@
$this->mainMap->append($someWmc->mainMap);
if (isset($this->overviewMap) && isset($someWmc->overviewMap)) {
- // There is only one WMS in the overview map; merge, not append
+ // There is only one WMS in the overview map; merge, not append
$this->overviewMap->merge($someWmc->overviewMap);
}
}
/**
* Adds a WMS to this WMC
- *
- * @return
+ *
+ * @return
*/
public function appendWmsArray ($wmsArray) {
return $this->mainMap->appendWmsArray($wmsArray);
}
-
+
/**
* Merges a WMS into this WMC
- *
- * @return
+ *
+ * @return
*/
public function mergeWmsArray ($wmsArray) {
if (func_num_args() > 1) {
@@ -1097,20 +1113,20 @@
return $this->mainMap->mergeWmsArray($wmsArray);
}
-// ---------------------------------------------------------------------------
-// private functions
-// ---------------------------------------------------------------------------
+ // ---------------------------------------------------------------------------
+ // private functions
+ // ---------------------------------------------------------------------------
/**
* Loads a WMC from an actual WMC XML document.
* Uses WMS class.
- *
+ *
* @param string $data the data from the XML file
*/
- protected function createObjFromWMC_xml($data){
- // store xml
+ protected function createObjFromWMC_xml($data) {
+ // store xml
$this->xml = $data;
-
+
$values = administration::parseXml($data);
if (!$values) {
throw new Exception("WMC document could not be parsed.");
@@ -1129,7 +1145,7 @@
$this->mainMap = new Map();
$this->overviewMap = null;
$this->generalExtensionArray = array();
-
+
$layerlistArray = array();
$layerlistArray["main"] = array();
$layerlistArray["overview"] = array();
@@ -1140,7 +1156,7 @@
$type = $element[type];
$attributes = $element[attributes];
$value = mb_utf8_decode(html_entity_decode($element[value]));
-
+
if ($tag == "VIEWCONTEXT" && $type == "open") {
$this->wmc_id = $attributes["id"];
$this->wmc_version = $attributes["version"];
@@ -1215,7 +1231,7 @@
if ($tag == "STATEORPROVINCE") {
$this->wmc_contactstateorprovince = $value;
}
- if ($tag == "POSTCODE"){
+ if ($tag == "POSTCODE") {
$this->wmc_contactpostcode = $value;
}
if ($tag == "COUNTRY") {
@@ -1227,10 +1243,10 @@
}
}
if ($tag == "LOGOURL" && $type == "open") {
- $logourl = true;
- $this->wmc_logourl_width = $attributes["width"];
- $this->wmc_logourl_height = $attributes["height"];
- $this->wmc_logourl_format = $attributes["format"];
+ $logourl = true;
+ $this->wmc_logourl_width = $attributes["width"];
+ $this->wmc_logourl_height = $attributes["height"];
+ $this->wmc_logourl_format = $attributes["format"];
}
if ($logourl) {
if ($tag == "LOGOURL" && $type == "close") {
@@ -1242,11 +1258,11 @@
}
}
if ($tag == "DESCRIPTIONURL" && $type == "open") {
- $descriptionurl = true;
- $this->wmc_descriptionurl_format = $attributes["format"];
+ $descriptionurl = true;
+ $this->wmc_descriptionurl_format = $attributes["format"];
}
if ($descriptionurl) {
- if ($tag == "DESCRIPTIONURL" && $type == "close"){
+ if ($tag == "DESCRIPTIONURL" && $type == "close") {
$descriptionurl = false;
}
if ($tag == "ONLINERESOURCE") {
@@ -1284,11 +1300,11 @@
$firstValue = $this->generalExtensionArray[$tag];
$this->generalExtensionArray[$tag] = array();
array_push($this->generalExtensionArray[$tag], $firstValue);
- }
+ }
array_push($this->generalExtensionArray[$tag], $value);
}
else {
- $this->generalExtensionArray[$tag] = $value;
+ $this->generalExtensionArray[$tag] = $value;
}
}
}
@@ -1296,22 +1312,22 @@
$generalExtension = true;
}
if ($tag == "GENERAL" && $type == "close") {
- $general = false;
- }
+ $general = false;
+ }
}
if ($layerlist) {
if ($tag == "LAYERLIST" && $type == "close") {
- $layerlist = false;
+ $layerlist = false;
}
if ($tag == "LAYER" && $type == "open") {
- //
- // The associative array currentLayer holds all
- // data of the currently processed layer.
- // The data will be set in the classes' WMS
- // object when the layer tag is closed.
- //
+ //
+ // The associative array currentLayer holds all
+ // data of the currently processed layer.
+ // The data will be set in the classes' WMS
+ // object when the layer tag is closed.
+ //
$currentLayer = array();
-
+
$currentLayer["queryable"] = $attributes["queryable"];
if ($attributes["hidden"] == "1") {
$currentLayer["visible"] = 0;
@@ -1326,47 +1342,47 @@
if ($layer) {
if ($tag == "LAYER" && $type == "close") {
- //
- // After a layer tag is closed,
- // we have all necessary information to CREATE
- // a layer object and append it to the WMS object
- //
+ //
+ // After a layer tag is closed,
+ // we have all necessary information to CREATE
+ // a layer object and append it to the WMS object
+ //
if (isset($currentLayer["extension"]["OVERVIEWHIDDEN"])) {
- array_push($layerlistArray["overview"], $currentLayer);
+ array_push($layerlistArray["overview"], $currentLayer);
}
$modifiedLayer = $currentLayer;
unset($modifiedLayer["extension"]["OVERVIEWHIDDEN"]);
- array_push($layerlistArray["main"], $modifiedLayer);
- $layer = false;
+ array_push($layerlistArray["main"], $modifiedLayer);
+ $layer = false;
}
if ($formatlist) {
if ($tag == "FORMAT") {
- array_push($currentLayer["format"], array("current" => $attributes["current"], "name" => $value));
+ array_push($currentLayer["format"], array("current" => $attributes["current"], "name" => $value));
if ($attributes["current"] == "1") {
$currentLayer["formatIndex"] = count($currentLayer["format"]) - 1;
}
- }
- if ($tag == "FORMATLIST" && $type == "close") {
- $formatlist = false;
- }
- }
- elseif ($metadataurl) {
+ }
+ if ($tag == "FORMATLIST" && $type == "close") {
+ $formatlist = false;
+ }
+ }
+ elseif ($metadataurl) {
if ($tag == "ONLINERESOURCE") {
$currentLayer["metadataurl"] = $attributes["xlink:href"];
}
if ($tag == "METADATAURL" && $type == "close") {
$metadataurl = false;
}
- }
- elseif ($dataurl) {
+ }
+ elseif ($dataurl) {
if ($tag == "ONLINERESOURCE") {
- $currentLayer["dataurl"] = $attributes["xlink:href"];
+ $currentLayer["dataurl"] = $attributes["xlink:href"];
}
- if ($tag == "DATAURL" && $type == "close") {
+ if ($tag == "DATAURL" && $type == "close") {
$dataurl = false;
- }
- }
- elseif ($stylelist) {
+ }
+ }
+ elseif ($stylelist) {
if ($style) {
$index = count($currentLayer["style"]) - 1;
if ($tag == "STYLE" && $type == "close") {
@@ -1388,7 +1404,7 @@
}
}
else {
- if ($tag == "NAME"){
+ if ($tag == "NAME") {
$currentLayer["style"][$index]["name"] = $value ? $value : "default";
}
if ($tag == "TITLE") {
@@ -1399,15 +1415,15 @@
$legendurl = false;
}
if ($tag == "ONLINERESOURCE") {
- $currentLayer["style"][$index]["legendurl_type"] = $attributes["xlink:type"];
- $currentLayer["style"][$index]["legendurl"] = $attributes["xlink:href"];
+ $currentLayer["style"][$index]["legendurl_type"] = $attributes["xlink:type"];
+ $currentLayer["style"][$index]["legendurl"] = $attributes["xlink:href"];
}
}
if ($tag == "LEGENDURL" && $type == "open") {
- $legendurl = true;
- $currentLayer["style"][$index]["legendurl_width"] = $attributes["width"];
- $currentLayer["style"][$index]["legendurl_height"] = $attributes["height"];
- $currentLayer["style"][$index]["legendurl_format"] = $attributes["format"];
+ $legendurl = true;
+ $currentLayer["style"][$index]["legendurl_width"] = $attributes["width"];
+ $currentLayer["style"][$index]["legendurl_height"] = $attributes["height"];
+ $currentLayer["style"][$index]["legendurl_format"] = $attributes["format"];
}
}
}
@@ -1424,48 +1440,48 @@
}
else {
if ($tag == "SERVER" && $type == "open") {
- $server = true;
- $currentLayer["service"] = $attributes["service"];
- $currentLayer["version"] = $attributes["version"];
- $currentLayer["wms_title"] = $attributes["title"];
+ $server = true;
+ $currentLayer["service"] = $attributes["service"];
+ $currentLayer["version"] = $attributes["version"];
+ $currentLayer["wms_title"] = $attributes["title"];
}
if ($server) {
if ($tag == "SERVER" && $type == "close") {
- $server = false;
- }
+ $server = false;
+ }
if ($tag == "ONLINERESOURCE") {
- $currentLayer["url"] = $attributes["xlink:href"];
+ $currentLayer["url"] = $attributes["xlink:href"];
}
}
if ($tag == "NAME") {
- $currentLayer["name"] = $value;
+ $currentLayer["name"] = $value;
}
if ($tag == "TITLE") {
- $currentLayer["title"] = $value;
+ $currentLayer["title"] = $value;
}
if ($tag == "ABSTRACT") {
- $currentLayer["abstract"] = $value;
+ $currentLayer["abstract"] = $value;
}
if ($tag == "SRS") {
- $currentLayer["epsg"] = explode(" ", $value);
+ $currentLayer["epsg"] = explode(" ", $value);
}
if ($tag == "EXTENSION" && $type == "close") {
$extension = false;
}
- if ($extension == true){
-// if ($value !== "") {
- if (isset($currentLayer["extension"][$tag])) {
- if (!is_array($currentLayer["extension"][$tag])) {
- $firstValue = $currentLayer["extension"][$tag];
- $currentLayer["extension"][$tag] = array();
- array_push($currentLayer["extension"][$tag], $firstValue);
- }
- array_push($currentLayer["extension"][$tag], $value);
+ if ($extension == true) {
+ // if ($value !== "") {
+ if (isset($currentLayer["extension"][$tag])) {
+ if (!is_array($currentLayer["extension"][$tag])) {
+ $firstValue = $currentLayer["extension"][$tag];
+ $currentLayer["extension"][$tag] = array();
+ array_push($currentLayer["extension"][$tag], $firstValue);
}
- else {
- $currentLayer["extension"][$tag] = $value;
- }
-// }
+ array_push($currentLayer["extension"][$tag], $value);
+ }
+ else {
+ $currentLayer["extension"][$tag] = $value;
+ }
+ // }
}
if ($tag == "EXTENSION" && $type == "open") {
$currentLayer["extension"] = array();
@@ -1487,9 +1503,9 @@
}
}
}
-
+
// set WMS data
-
+
$layerlistCompleteArray = array_merge($layerlistArray["main"], $layerlistArray["overview"]);
for ($i = 0; $i < count($layerlistCompleteArray); $i++) {
@@ -1505,17 +1521,17 @@
/**
* Saves the current WMC in the log folder.
- *
+ *
* @return string the filename of the WMC document.
*/
private function saveAsFile() {
if ($this->saveWmcAsFile) {
$filename = "wmc_" . date("Y_m_d_H_i_s") . ".xml";
$logfile = "../tmp/" . $filename;
-
- if($h = fopen($logfile,"a")){
+
+ if($h = fopen($logfile,"a")) {
$content = $this->xml;
- if(!fwrite($h,$content)){
+ if(!fwrite($h,$content)) {
$e = new mb_exception("class_wmc.php: failed to write wmc.");
return false;
}
@@ -1526,11 +1542,11 @@
}
return null;
}
-
+
/**
* Called during WMC parsing; sets the data of a single layer.
- *
- * @return
+ *
+ * @return
* @param $currentLayer Array an associative array with layer data
*/
private function setLayerData ($currentLayer) {
@@ -1558,30 +1574,30 @@
// find last WMS with the same online resource
for ($i = count($wmsArray) - 1; $i >= 0; $i--) {
- if (isset($currentLayer["url"]) &&
+ if (isset($currentLayer["url"]) &&
$currentLayer["url"] == $wmsArray[$i]->wms_getmap) {
- $wmsIndex = $i;
- break;
+ $wmsIndex = $i;
+ break;
}
}
// Even if this WMS has been found before it could still
- // be a duplicate! We would have to create a new WMS and
+ // be a duplicate! We would have to create a new WMS and
// not append this layer to that WMS.
// For the overview layer we never add a new wms.
// check if this layer is an overview layer. If yes, skip this layer.
if ($wmsIndex !== null && !$currentMapIsOverview) {
- // check if this WMS has a layer equal to the current layer.
- // If yes, this is a new WMS. If not, append this layer
- // to the existing WMS.
+ // check if this WMS has a layer equal to the current layer.
+ // If yes, this is a new WMS. If not, append this layer
+ // to the existing WMS.
$matchingWmsLayerArray = $this->wmsArray[$wmsIndex]->objLayer;
-
+
for ($i = 0; $i < count($matchingWmsLayerArray); $i++) {
if ($matchingWmsLayerArray[$i]->layer_name == $currentLayer["name"]) {
- // by re-setting the index to null, a new WMS will be
- // added below.
+ // by re-setting the index to null, a new WMS will be
+ // added below.
$wmsIndex = null;
break;
}
@@ -1602,7 +1618,7 @@
$wms->wms_abstract = $currentLayer["abstract"];
$wms->wms_getmap = $currentLayer["url"];
$wms->wms_getfeatureinfo = $currentLayer["url"]; // TODO : Add correct data
-
+
$styleIndex = $currentLayer["styleIndex"];
$wms->wms_getlegendurl = $currentLayer["style"][$styleIndex]["legendurl"];
@@ -1623,8 +1639,8 @@
// set data formats
//
for ($i = 0; $i < count($currentLayer["format"]); $i++) {
- array_push($wms->data_type, "map");
- array_push($wms->data_format, $currentLayer["format"][$i]["name"]);
+ array_push($wms->data_type, "map");
+ array_push($wms->data_format, $currentLayer["format"][$i]["name"]);
}
// add WMS
@@ -1640,14 +1656,14 @@
$currentMap->setWmsArray($wmsArray);
return true;
}
-
+
/**
* Called during WMC parsing; sets the maps within a WMC.
- *
- * @return
+ *
+ * @return
*/
private function setMapData () {
- if ($this->generalExtensionArray["OV_WIDTH"] &&
+ if ($this->generalExtensionArray["OV_WIDTH"] &&
$this->generalExtensionArray["OV_HEIGHT"] &&
$this->generalExtensionArray["OV_FRAMENAME"] &&
$this->generalExtensionArray["OV_MINX"] &&
@@ -1655,31 +1671,31 @@
$this->generalExtensionArray["OV_MAXX"] &&
$this->generalExtensionArray["OV_MAXY"] &&
$this->generalExtensionArray["OV_SRS"]) {
-
+
$this->overviewMap = new Map();
$this->overviewMap->setWidth(
// this should not be an array, but sometimes it is.
// I can't find the reason at the moment, consider
// this a workaround
is_array($this->generalExtensionArray["OV_WIDTH"]) ?
- $this->generalExtensionArray["OV_WIDTH"][0] :
- $this->generalExtensionArray["OV_WIDTH"]
+ $this->generalExtensionArray["OV_WIDTH"][0] :
+ $this->generalExtensionArray["OV_WIDTH"]
);
$this->overviewMap->setHeight(
// this should not be an array, but sometimes it is.
// I can't find the reason at the moment, consider
// this a workaround
- is_array($this->generalExtensionArray["OV_HEIGHT"]) ?
- $this->generalExtensionArray["OV_HEIGHT"][0] :
- $this->generalExtensionArray["OV_HEIGHT"]
+ is_array($this->generalExtensionArray["OV_HEIGHT"]) ?
+ $this->generalExtensionArray["OV_HEIGHT"][0] :
+ $this->generalExtensionArray["OV_HEIGHT"]
);
$this->overviewMap->setFrameName(
// this should not be an array, but sometimes it is.
// I can't find the reason at the moment, consider
// this a workaround
is_array($this->generalExtensionArray["OV_FRAMENAME"]) ?
- $this->generalExtensionArray["OV_FRAMENAME"][0] :
- $this->generalExtensionArray["OV_FRAMENAME"]
+ $this->generalExtensionArray["OV_FRAMENAME"][0] :
+ $this->generalExtensionArray["OV_FRAMENAME"]
);
$this->overviewMap->setIsOverview(true);
@@ -1693,10 +1709,10 @@
$bbox = new Mapbender_bbox($this->generalExtensionArray["OV_MINX"], $this->generalExtensionArray["OV_MINY"], $this->generalExtensionArray["OV_MAXX"], $this->generalExtensionArray["OV_MAXY"], $this->generalExtensionArray["OV_SRS"]);
$this->overviewMap->setExtent($bbox);
}
- if ($this->generalExtensionArray["EPSG"] &&
- $this->generalExtensionArray["MINX"] &&
- $this->generalExtensionArray["MINY"] &&
- $this->generalExtensionArray["MAXX"] &&
+ if ($this->generalExtensionArray["EPSG"] &&
+ $this->generalExtensionArray["MINX"] &&
+ $this->generalExtensionArray["MINY"] &&
+ $this->generalExtensionArray["MAXX"] &&
$this->generalExtensionArray["MAXY"]) {
$mainEpsgArray = array();
@@ -1721,13 +1737,13 @@
for ($i=0; $i < count($mainEpsgArray); $i++) {
$box = new Mapbender_bbox(
- floatval($mainMinXArray[$i]), floatval($mainMinYArray[$i]),
+ floatval($mainMinXArray[$i]), floatval($mainMinYArray[$i]),
floatval($mainMaxXArray[$i]), floatval($mainMaxYArray[$i]),
$mainEpsgArray[$i]
- );
+ );
$this->mainMap->addZoomFullExtent($box);
}
- }
+ }
if ($this->generalExtensionArray["MAIN_FRAMENAME"]) {
$this->mainMap->setFrameName(
@@ -1735,8 +1751,8 @@
// I can't find the reason at the moment, consider
// this a workaround
is_array($this->generalExtensionArray["MAIN_FRAMENAME"]) ?
- $this->generalExtensionArray["MAIN_FRAMENAME"][0] :
- $this->generalExtensionArray["MAIN_FRAMENAME"]
+ $this->generalExtensionArray["MAIN_FRAMENAME"][0] :
+ $this->generalExtensionArray["MAIN_FRAMENAME"]
);
}
else {
@@ -1747,7 +1763,7 @@
/**
* Creates a WMC document (XML) from the current object
- *
+ *
* @return String XML
*/
private function createXml() {
More information about the Mapbender_commits
mailing list