[Mapbender-commits] r1756 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Oct 26 10:35:47 EDT 2007
Author: christoph
Date: 2007-10-26 10:35:47 -0400 (Fri, 26 Oct 2007)
New Revision: 1756
Modified:
trunk/mapbender/http/classes/class_wfs_conf.php
Log:
temporarily added a class WfsConf. It needs to be merged with other classes and code into a single class
Modified: trunk/mapbender/http/classes/class_wfs_conf.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_conf.php 2007-10-26 14:24:50 UTC (rev 1755)
+++ trunk/mapbender/http/classes/class_wfs_conf.php 2007-10-26 14:35:47 UTC (rev 1756)
@@ -1,5 +1,5 @@
<?php
-# $Id: class_wfs_conf.php 530 2006-06-19 15:08:35Z vera_schulze $
+# $Id: class_wfs_conf.php 1032 2007-10-09 10:37:42Z baudson $
# http://www.mapbender.org/index.php/class_wfs_conf.php
# Copyright (C) 2002 CCGIS
#
@@ -17,6 +17,169 @@
# 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__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../extensions/JSON.php");
+
+class WfsConf {
+ var $confArray = array();
+
+ /**
+ * Gets the configuration from the database
+ */
+ function __construct ($idOrIdArray) {
+
+ /*
+ * Check parameter and set idArray
+ */
+ if (isset($idOrIdArray)){
+
+ // parameter is a number
+ if (!is_array($idOrIdArray) && is_numeric($idOrIdArray)) {
+ $this->getWfsConfFromDB(array(intval($idOrIdArray)));
+ }
+ // parameter is an array of numbers
+ else 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;
+ }
+ array_push($idArray, intval($idOrIdArray[$i]));
+ }
+ $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;
+ }
+ }
+ else {
+ $e = new mb_exception("Wfs_conf: constructor: parameter is not valid");
+ }
+ }
+
+ /**
+ * get WFS conf data from database
+ */
+ private function getWfsConfFromDB ($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 .= ")";
+
+ $res = db_prep_query($sql, $v, $t);
+
+ $checkedIdArray = array();
+
+ while ($row = db_fetch_array($res)) {
+
+ $id = $row["wfs_conf_id"];
+
+ $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 ";
+ $sql_conf_element .= "AND wfs_conf_element.f_search = 1 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)) {
+
+
+ $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"],
+ "element_name" => $row_conf_element["element_name"],
+ "element_type" => $row_conf_element["element_type"]
+ );
+ array_push($elementArray, $currentElement);
+ }
+
+ $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");
+
+ $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_id" => $featuretype_srs,
+ "wfs_getfeature" => $row["wfs_getfeature"],
+ "element" => $elementArray
+ );
+
+ $this->confArray[$id] = $currentRow;
+ }
+ }
+
+ /** 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.
+ $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;
+ }
+}
+
+
class wfs_conf{
var $wfs_id;
@@ -30,17 +193,8 @@
var $features;
var $elements;
var $namespaces;
-
- function exportToArray() {
- $obj = array();
- for ($i = 0; $i < count($this->wfs_id); $i++) {
- $obj[$this->wfs_id[$i]] = $this->wfs_title[$i];;
-
- }
- return $obj;
- }
- function getallwfs(){
+ function getallwfs($userid){
$this->wfs_id = array();
$this->wfs_name = array();
$this->wfs_title = array();
@@ -48,9 +202,18 @@
global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
- db_select_db($DB,$con);
- $sql = "SELECT * FROM wfs"; // include permission handling
- $res = db_query($sql);
+ db_select_db($DB,$con);
+ if($userid){
+ $sql = "SELECT * FROM wfs WHERE wfs_owner = $1";
+ $v = array($userid);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ }
+ else{
+ $sql = "SELECT * FROM wfs";
+ $res = db_query($sql);
+ }
+
$cnt = 0;
while ($row = db_fetch_array($res)){
$this->wfs_version[$cnt] = $row["wfs_version"];
More information about the Mapbender_commits
mailing list