[Mapbender-commits] r2369 - branches/2.5/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Apr 10 08:38:06 EDT 2008
Author: christoph
Date: 2008-04-10 08:38:06 -0400 (Thu, 10 Apr 2008)
New Revision: 2369
Added:
branches/2.5/http/classes/class_user.php
Modified:
branches/2.5/http/classes/class_administration.php
branches/2.5/http/classes/class_wfs_conf.php
Log:
refactoring, see http://lists.osgeo.org/pipermail/mapbender_dev/2008-April/001132.html
Modified: branches/2.5/http/classes/class_administration.php
===================================================================
--- branches/2.5/http/classes/class_administration.php 2008-04-09 13:58:53 UTC (rev 2368)
+++ branches/2.5/http/classes/class_administration.php 2008-04-10 12:38:06 UTC (rev 2369)
@@ -18,6 +18,7 @@
require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_user.php");
$con = db_connect(DBSERVER,OWNER,PW);
db_select_db(DB,$con);
@@ -632,51 +633,12 @@
return $arrayWmc;
}
- function getGuisByPermission($mb_user_id,$ignoreublic){
- $arrayGuis = array();
- $mb_user_groups = array();
- $sql_groups = "SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 ";
- $v = array($mb_user_id);
- $t = array("i");
- $res_groups = db_prep_query($sql_groups,$v,$t);
- $cnt_groups = 0;
- while($row = db_fetch_array($res_groups)){
- $mb_user_groups[$cnt_groups] = $row["fkey_mb_group_id"];
- $cnt_groups++;
- }
- if($cnt_groups > 0){
- $v = array();
- $t = array();
- $sql_g = "SELECT gui.gui_id FROM gui JOIN gui_mb_group ";
- $sql_g .= " ON gui.gui_id = gui_mb_group.fkey_gui_id WHERE gui_mb_group.fkey_mb_group_id IN (";
- for($i=0; $i<count($mb_user_groups);$i++){
- if($i > 0){$sql_g .= ",";}
- $sql_g .= "$".strval($i+1);
- array_push($v,$mb_user_groups[$i]);
- array_push($t,"i");
- }
- $sql_g .= ") GROUP BY gui.gui_id";
- $res_g = db_prep_query($sql_g,$v,$t);
- while($row = db_fetch_array($res_g)){
- array_push($arrayGuis,$row["gui_id"]);
- }
- }
- $sql_guis = "SELECT gui.gui_id FROM gui JOIN gui_mb_user ON gui.gui_id = gui_mb_user.fkey_gui_id";
- $sql_guis .= " WHERE (gui_mb_user.fkey_mb_user_id = $1) ";
- if (!isset($ignore_public) OR $ignore_public== false){
- $sql_guis .= " AND gui.gui_public = 1 ";
- }
- $sql_guis .= " GROUP BY gui.gui_id";
- $v = array($mb_user_id);
- $t = array("i");
- $res_guis = db_prep_query($sql_guis,$v,$t);
- $guis = array();
- while($row = db_fetch_array($res_guis)){
- if(!in_array($row['gui_id'],$arrayGuis)){
- array_push($arrayGuis,$row["gui_id"]);
- }
- }
- return $arrayGuis;
+ /**
+ * @deprecated
+ */
+ function getGuisByPermission($mb_user_id,$ignorepublic){
+ $user = new User($mb_user_id);
+ return $user->getApplicationsByPermission($ignorepublic);
}
function getWmsByOwnGuis($array_gui_ids){
@@ -1111,44 +1073,13 @@
/** identifies the Conf-FeatureServices where the current user is owner
*
+ * @deprecated
* @param integer userid the user-ID of the current user
* @return integer[] the IDs of the wfs_conf-table
*/
function getWfsConfByPermission($userid){
-
-
- $guisByPer = array();
-// 1.
- $guisByPer = $this->getGuisByPermission($userid, true);
-
-// 2.
- if(count($guisByPer)>0){
- $v = array();
- $t = array();
- $sql = "SELECT wfs_conf.wfs_conf_id FROM gui_wfs_conf, wfs_conf " .
- "where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
- "and gui_wfs_conf.fkey_gui_id IN(";
- for($i=0; $i<count($guisByPer); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "$".strval($i+1);
-
- array_push($v, $guisByPer[$i]);
- array_push($t, "s");
- }
- $sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
-
-
- $res = db_prep_query($sql,$v,$t);
- $ownWFSconfs = array();
- $i=0;
- while($row = db_fetch_array($res)){
-
- $ownWFSconfs[$i] = $row['wfs_conf_id'];
- $i++;
- }
- }
- return $ownWFSconfs;
-
+ $user = new User($userid);
+ return $user->getWfsConfByPermission();
}
}
?>
\ No newline at end of file
Added: branches/2.5/http/classes/class_user.php
===================================================================
--- branches/2.5/http/classes/class_user.php (rev 0)
+++ branches/2.5/http/classes/class_user.php 2008-04-10 12:38:06 UTC (rev 2369)
@@ -0,0 +1,133 @@
+<?php
+# $Id: class_kml_geometry.php 1966 2008-01-15 08:25:15Z christoph $
+# http://www.mapbender.org/index.php/class_wmc.php
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+/**
+ * A Mapbender user as described in the table mb_user.
+ */
+class User {
+ /**
+ * @var Integer The user ID
+ */
+ var $id;
+
+ /**
+ * Constructor
+ * @param $userId Integer the ID of the user that is represented by
+ * this object.
+ */
+ public function __construct ($userId) {
+ $this->id = $userId;
+ }
+
+ /**
+ * Returns an array of application IDs that the user is allowed to access.
+ *
+ * @return Array an array of application IDs
+ * @param $ignorepublic boolean whether or not to ignore
+ * public applications (?)
+ */
+ public function getApplicationsByPermission ($ignorepublic) {
+ $mb_user_id = $this->id;
+ $arrayGuis = array();
+ $mb_user_groups = array();
+ $sql_groups = "SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 ";
+ $v = array($mb_user_id);
+ $t = array("i");
+ $res_groups = db_prep_query($sql_groups,$v,$t);
+ $cnt_groups = 0;
+ while($row = db_fetch_array($res_groups)){
+ $mb_user_groups[$cnt_groups] = $row["fkey_mb_group_id"];
+ $cnt_groups++;
+ }
+ if($cnt_groups > 0){
+ $v = array();
+ $t = array();
+ $sql_g = "SELECT gui.gui_id FROM gui JOIN gui_mb_group ";
+ $sql_g .= " ON gui.gui_id = gui_mb_group.fkey_gui_id WHERE gui_mb_group.fkey_mb_group_id IN (";
+ for($i=0; $i<count($mb_user_groups);$i++){
+ if($i > 0){$sql_g .= ",";}
+ $sql_g .= "$".strval($i+1);
+ array_push($v,$mb_user_groups[$i]);
+ array_push($t,"i");
+ }
+ $sql_g .= ") GROUP BY gui.gui_id";
+ $res_g = db_prep_query($sql_g,$v,$t);
+ while($row = db_fetch_array($res_g)){
+ array_push($arrayGuis,$row["gui_id"]);
+ }
+ }
+ $sql_guis = "SELECT gui.gui_id FROM gui JOIN gui_mb_user ON gui.gui_id = gui_mb_user.fkey_gui_id";
+ $sql_guis .= " WHERE (gui_mb_user.fkey_mb_user_id = $1) ";
+ if (!isset($ignore_public) OR $ignore_public== false){
+ $sql_guis .= " AND gui.gui_public = 1 ";
+ }
+ $sql_guis .= " GROUP BY gui.gui_id";
+ $v = array($mb_user_id);
+ $t = array("i");
+ $res_guis = db_prep_query($sql_guis,$v,$t);
+ $guis = array();
+ while($row = db_fetch_array($res_guis)){
+ if(!in_array($row['gui_id'],$arrayGuis)){
+ array_push($arrayGuis,$row["gui_id"]);
+ }
+ }
+ return $arrayGuis;
+ }
+
+ /** identifies the IDs of WFS confs where the user is owner
+ *
+ * @param integer userid the user-ID of the current user
+ * @return integer[] the IDs of the wfs_conf-table
+ */
+ public function getWfsConfByPermission(){
+ $userid = $this->id;
+ $guisByPer = array();
+// 1.
+ $adm = new administration();
+ $guisByPer = $adm->getGuisByPermission($userid, true);
+// 2.
+ $ownWFSconfs = array();
+ if(count($guisByPer)>0){
+ $v = array();
+ $t = array();
+ $sql = "SELECT wfs_conf.wfs_conf_id FROM gui_wfs_conf, wfs_conf " .
+ "where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
+ "and gui_wfs_conf.fkey_gui_id IN(";
+ for($i=0; $i<count($guisByPer); $i++){
+ if($i>0){ $sql .= ",";}
+ $sql .= "$".strval($i+1);
+
+ array_push($v, $guisByPer[$i]);
+ array_push($t, "s");
+ }
+ $sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
+
+ $res = db_prep_query($sql,$v,$t);
+ $i=0;
+ while($row = db_fetch_array($res)){
+ $ownWFSconfs[$i] = $row['wfs_conf_id'];
+ $i++;
+ }
+ }
+ return $ownWFSconfs;
+ }
+}
+?>
\ No newline at end of file
Modified: branches/2.5/http/classes/class_wfs_conf.php
===================================================================
--- branches/2.5/http/classes/class_wfs_conf.php 2008-04-09 13:58:53 UTC (rev 2368)
+++ branches/2.5/http/classes/class_wfs_conf.php 2008-04-10 12:38:06 UTC (rev 2369)
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_user.php");
require_once(dirname(__FILE__)."/class_administration.php");
require_once(dirname(__FILE__)."/../extensions/JSON.php");
@@ -31,187 +32,204 @@
}
+ function __toString () {
+ $json = new Services_JSON();
+ return $json->encode($this->confArray);
+ }
+
+ /**
+ * Loads WFS conf data from the database
+ *
+ * @return Object WFS conf data.
+ * @param $idOrIdArray Object May be an integer or an array of integers representing WFS conf IDs.
+ */
public function load ($idOrIdArray) {
- /*
- * Check parameter and set idArray
- */
+ // Check parameter and set idArray
if (isset($idOrIdArray)){
// parameter is a number
if (!is_array($idOrIdArray) && is_numeric($idOrIdArray)) {
- $this->getWfsConfFromDB(array(intval($idOrIdArray)), $_SESSION["mb_user_id"]);
+ $idArray = array(intval($idOrIdArray));
}
+
// parameter is an array of numbers
- else if (is_array($idOrIdArray)) {
+ if (is_array($idOrIdArray)) {
$idArray = array();
for ($i=0; $i < count($idOrIdArray); $i++) {
if (!is_numeric($idOrIdArray[$i])) {
$e = new mb_exception("Wfs_conf: constructor: wrong parameter: ".$idOrIdArray[$i]." is not a number.");
- return null;
+ return array();
}
array_push($idArray, intval($idOrIdArray[$i]));
}
- $this->getWfsConfFromDB($idArray, $_SESSION["mb_user_id"]);
+
+ // If a user ID is given, remove the ones the user has no access to
+ if ($_SESSION["mb_user_id"]) {
+ $user = new User($_SESSION["mb_user_id"]);
+ $idArray = array_intersect($idArray, $user->getWfsConfByPermission());
+ }
+
+ return $this->getWfsConfFromDB($idArray);
}
// parameter is invalid
else {
$e = new mb_exception("Wfs_conf: constructor: parameter must be number or an array of numbers.");
- return null;
+ return array();
}
}
else {
$e = new mb_exception("Wfs_conf: constructor: parameter is not valid");
+ return null;
}
}
+
+ // --------------------------- private -----------------------------------
+
/**
- * get WFS conf data from database
+ * Gets the database content for a number of WFS configurations given by their IDs.
+ *
+ * @return Array
+ * @param $idArray Array an array of integer values representing WFS conf IDs.
*/
- private function getWfsConfFromDB ($idArray, $userId) {
- /*
- * If a user ID is given, remove the ones the user has no access to
- */
- if ($userId) {
- $idArray = array_intersect($idArray, WfsConf::getWfsConfByPermission($userId));
+ private static function getWfsConfFromDbByArray ($idArray) {
+ $sql = "SELECT * FROM wfs_conf ";
+ $sql .= "JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id ";
+ $sql .= "WHERE wfs_conf.wfs_conf_id IN (";
+
+ $v = array();
+ $t = array();
+ for ($i = 0; $i < count($idArray); $i++) {
+ if ($i > 0) {$sql .= ", ";}
+ $sql .= "$" . ($i+1);
+ array_push($v, $idArray[$i]);
+ array_push($t, 'i');
}
+ $sql .= ")";
- if (count($idArray) > 0) {
- /*
- * Get WFS configurations
- */
- $sql = "SELECT * FROM wfs_conf ";
- $sql .= "JOIN wfs ON wfs_conf.fkey_wfs_id = wfs.wfs_id ";
- $sql .= "WHERE wfs_conf.wfs_conf_id IN (";
-
- $v = array();
- $t = array();
- for ($i = 0; $i < count($idArray); $i++) {
- if ($i > 0) {$sql .= ", ";}
- $sql .= "$" . ($i+1);
- array_push($v, $idArray[$i]);
- array_push($t, 'i');
- }
- $sql .= ")";
-
- $res = db_prep_query($sql, $v, $t);
-
- while ($row = db_fetch_array($res)) {
+ $res = db_prep_query($sql, $v, $t);
+
+ $rowArray = array();
+ while ($row = db_fetch_array($res)) {
+ array_push($rowArray, $row);
+ }
+ return $rowArray;
+ }
-
- /*
- * Get WFS conf elements
- */
- $id = $row["wfs_conf_id"];
+ /**
+ * Gets the database content of a WFS conf element given by a WFS conf ID.
+ *
+ * @return Array
+ * @param $id Integer the WFS conf ID.
+ */
+ private static function getWfsConfElementFromDb ($id) {
+ $sql = "SELECT * FROM wfs_conf_element ";
+ $sql .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
+ $sql .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
+ #filtered on client side
+ #$sql .= "AND wfs_conf_element.f_search = 1 ";
+ $sql .= "ORDER BY wfs_conf_element.f_pos";
+ $v = array($id);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
- $sql_conf_element = "SELECT * FROM wfs_conf_element ";
- $sql_conf_element .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
- $sql_conf_element .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
-#filtered on client side
-# $sql_conf_element .= "AND wfs_conf_element.f_search = 1 ";
- $sql_conf_element .= "ORDER BY wfs_conf_element.f_pos";
- $v_conf_element = array($id);
- $t_conf_element = array('i');
- $res_conf_element = db_prep_query($sql_conf_element, $v_conf_element, $t_conf_element);
-
- $elementArray = array();
- while ($row_conf_element = db_fetch_array($res_conf_element)) {
+ $elementArray = array();
+ while ($row = db_fetch_array($res)) {
+ $currentElement = array("element_name" => $row["element_name"],
+ "element_type" => $row["element_type"],
+ "f_search" => $row["f_search"],
+ "f_style_id" => $row["f_style_id"],
+ "f_toupper" => $row["f_toupper"],
+ "f_label" => $row["f_label"],
+ "f_label_id" => $row["f_label_id"],
+ "f_geom" => $row["f_geom"],
+ "f_show" => $row["f_show"],
+ "f_respos" => $row["f_respos"],
+ "f_form_element_html" => $row["f_form_element_html"],
+ "f_show_detail" => $row["f_show_detail"]
+ );
+ array_push($elementArray, $currentElement);
+ }
+ return $elementArray;
+ }
+
+ /**
+ * Gets the database content of a WFS feature type given by a WFS ID and a featuretype ID.
+ *
+ * @return Array
+ * @param $wfsId Integer the WFS ID.
+ * @param $featuretypeId Integer the WFS featuretype ID.
+ */
+ private static function getWfsFeatureTypeFromDb($wfsId, $featuretypeId) {
+ $sql = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND featuretype_id = $2";
+ $v = array($wfsId, $featuretypeId);
+ $t = array("i", "i");
+ $res = db_prep_query($sql, $v, $t);
+
+ $currentRow = array();
+
+ if($row = db_fetch_array($res)){
+ $currentRow["featuretype_name"] = $row["featuretype_name"];
+ $currentRow["featuretype_srs"] = $row["featuretype_srs"];
+ }
- $currentElement = array("f_search" => $row_conf_element["f_search"],
- "f_style_id" => $row_conf_element["f_style_id"],
- "f_toupper" => $row_conf_element["f_toupper"],
- "f_label" => $row_conf_element["f_label"],
- "f_label_id" => $row_conf_element["f_label_id"],
- "f_geom" => $row_conf_element["f_geom"],
- "f_show" => $row_conf_element["f_show"],
- "f_respos" => $row_conf_element["f_respos"],
- "f_form_element_html" => $row_conf_element["f_form_element_html"],
- "f_show_detail" => $row_conf_element["f_show_detail"],
- "element_name" => $row_conf_element["element_name"],
- "element_type" => $row_conf_element["element_type"]
- );
- array_push($elementArray, $currentElement);
- }
-
- /*
- * Get WFS featuretype
- */
- $sql_feature_type = "SELECT * FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND featuretype_id = $2";
- $v_feature_type = array($row["fkey_wfs_id"], $row["fkey_featuretype_id"]);
- $t_feature_type = array("i", "i");
+ return $currentRow;
+ }
+
+ /**
+ * get WFS conf data from database
+ */
+ private function getWfsConfFromDB ($idArray) {
+
+ // if a user has access to some WFS confs...
+ if (count($idArray) > 0) {
+
+ // get WFS conf data from DB
+ $rowArray = self::getWfsConfFromDbByArray($idArray);
- $res_feature_type = db_prep_query($sql_feature_type, $v_feature_type, $t_feature_type);
- if($row_feature_type = db_fetch_array($res_feature_type)){
- $featuretype_name = $row_feature_type["featuretype_name"];
- $featuretype_srs = $row_feature_type["featuretype_srs"];
- }
-
- $currentRow = array("g_label" => $row["g_label"],
- "g_label_id" => $row["g_label_id"],
- "g_style" => $row["g_style"],
- "g_button" => $row["g_button"],
- "g_button_id" => $row["g_button_id"],
- "g_buffer" => $row["g_buffer"],
- "g_res_style" => $row["g_res_style"],
- "g_use_wzgraphics" => $row["g_use_wzgraphics"],
- "wfs_id" => $row["fkey_wfs_id"],
- "featuretype_id" => $row["fkey_featuretype_id"],
- "featuretype_name" => $featuretype_name,
- "featuretype_srs" => $featuretype_srs,
- "wfs_getfeature" => $row["wfs_getfeature"],
- "wfs_describefeaturetype" => $row["wfs_describefeaturetype"],
- "wfs_transaction" => $row["wfs_transaction"],
- "element" => $elementArray
+ for ($i=0; $i < count($rowArray); $i++) {
+
+ // WFS conf data
+ $currentRow = array("g_label" => $rowArray[$i]["g_label"],
+ "g_label_id" => $rowArray[$i]["g_label_id"],
+ "g_style" => $rowArray[$i]["g_style"],
+ "g_button" => $rowArray[$i]["g_button"],
+ "g_button_id" => $rowArray[$i]["g_button_id"],
+ "g_buffer" => $rowArray[$i]["g_buffer"],
+ "g_res_style" => $rowArray[$i]["g_res_style"],
+ "g_use_wzgraphics" => $rowArray[$i]["g_use_wzgraphics"],
+ "wfs_id" => $rowArray[$i]["fkey_wfs_id"],
+ "featuretype_id" => $rowArray[$i]["fkey_featuretype_id"],
+ "wfs_getfeature" => $rowArray[$i]["wfs_getfeature"],
+ "wfs_describefeaturetype" => $rowArray[$i]["wfs_describefeaturetype"],
+ "wfs_transaction" => $rowArray[$i]["wfs_transaction"]
);
-
+
+ // get WFS conf element data of current WFS conf
+ $id = $rowArray[$i]["wfs_conf_id"];
+ $currentRow["element"] = self::getWfsConfElementFromDb($id);
+
+ // get WFS featuretype data of current WFS conf
+ $wfsId = $rowArray[$i]["fkey_wfs_id"];
+ $featuretypeId = $rowArray[$i]["fkey_featuretype_id"];
+ $currentRow = array_merge($currentRow , self::getWfsFeatureTypeFromDb($wfsId, $featuretypeId));
+
$this->confArray[$id] = $currentRow;
}
+ return $this->confArray;
}
else {
$e = new mb_warning("class_wfs_conf.php: getWfsConfFromDB: You don't have access to any WFS confs. Check EDIT WFS.");
+ return array();
}
}
- /** identifies the Conf-FeatureServices where the current user is owner
- *
- * @param integer userid the user-ID of the current user
- * @return integer[] the IDs of the wfs_conf-table
- */
- public static function getWfsConfByPermission($userid){
- $guisByPer = array();
-// 1.
- $adm = new administration();
- $guisByPer = $adm->getGuisByPermission($userid, true);
-// 2.
- if(count($guisByPer)>0){
- $v = array();
- $t = array();
- $sql = "SELECT wfs_conf.wfs_conf_id FROM gui_wfs_conf, wfs_conf " .
- "where wfs_conf.wfs_conf_id = gui_wfs_conf.fkey_wfs_conf_id " .
- "and gui_wfs_conf.fkey_gui_id IN(";
- for($i=0; $i<count($guisByPer); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "$".strval($i+1);
-
- array_push($v, $guisByPer[$i]);
- array_push($t, "s");
- }
- $sql .= ") GROUP BY wfs_conf.wfs_conf_id ORDER BY wfs_conf.wfs_conf_id";
-
- $res = db_prep_query($sql,$v,$t);
- $ownWFSconfs = array();
- $i=0;
- while($row = db_fetch_array($res)){
-
- $ownWFSconfs[$i] = $row['wfs_conf_id'];
- $i++;
- }
- }
- return $ownWFSconfs;
- }
}
-
+/**
+ * @deprecated
+ */
class wfs_conf{
var $wfs_id;
More information about the Mapbender_commits
mailing list