[Mapbender-commits] r4738 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Sat Sep 26 14:37:47 EDT 2009


Author: kmq
Date: 2009-09-26 14:37:47 -0400 (Sat, 26 Sep 2009)
New Revision: 4738

Modified:
   trunk/mapbender/http/classes/class_group.php
   trunk/mapbender/http/classes/class_user.php
Log:
some fixes

Modified: trunk/mapbender/http/classes/class_group.php
===================================================================
--- trunk/mapbender/http/classes/class_group.php	2009-09-26 18:35:52 UTC (rev 4737)
+++ trunk/mapbender/http/classes/class_group.php	2009-09-26 18:37:47 UTC (rev 4738)
@@ -19,6 +19,7 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_RPCEndpoint.php");
+require_once(dirname(__FILE__)."/../classes/class_user.php");
 
 /**
  * A Mapbender user as described in the table mb_group.
@@ -42,6 +43,7 @@
 	 */
 	public function __construct ($groupId) {
 		
+       // throw new Exception("CONSTR  : ". $this->id);
         if($groupId == null){
           // new group
           return;
@@ -115,8 +117,7 @@
 
 
 		db_commit();
-
-
+        return true;
 	}
 
 
@@ -125,8 +126,13 @@
 	*/
 	public function change($changes) {
         //FIXME: validate input
+
+        if($changes->owner)
+        {
+          $owner = User::byName($changes->owner);
+        }
 		$this->name = $changes->name ? $changes->name : $this->name;
-		$this->owner = $changes->owner ? $changes->owner : $this->owner;
+		$this->owner = $changes->owner ? $owner->id : $this->owner;
 		$this->description = $changes->description ? $changes->description : $this->description;
 		$this->id = $changes->id ? $changes->id->value : $this->id;
 
@@ -159,15 +165,15 @@
 	}
 
 	public function remove() {
-
-		$sql_group_remove = "DELETE FROM mb_group WHERE mb_group_id = $1";
+		
+        //throw new Exception("I AM   : ". $this->id);
+        $sql_group_remove = "DELETE FROM mb_group WHERE mb_group_id = $1";
 		$v = array($this->id);
 		$t = array("i");
 		$result = db_prep_query($sql_group_remove,$v,$t);
-		
 		if($result == false)
 		{
-			$e = new mb_exception("Database error deleting group");
+			throw new Exception("Database error deleting group");
 		}
 		return true;
 	}
@@ -180,9 +186,12 @@
 		if($row = db_fetch_array($res_group)){
 
 			$this->name = $row['mb_group_name'];
-			$this->owner = $row['mb_group_owner'];
-			$this->description	= $row['mb_group_description'];
 
+            //FIXME: needs checking
+            $tmpuser =  new User($row['mb_group_owner']);
+            $this->owner = $tmpuser->name;
+            $this->description	= $row['mb_group_description'];
+
 		}else{
 			 throw new Exception("no such Group");
 		}
@@ -191,12 +200,21 @@
 
     /*
     * @return Array of Groups
-    * @param $filter UNUSED! string that must be contained in the username
+    * @param $filter UNUSED! AssocArray, valid keys "id","name". Use SQL's % and _ to perform simple matching
     */
     public static function getList($filter) {
+
+      //set up filters:
+      $id = $filter->id ? $filter->id : "%";
+      $name = $filter->name ? $filter->name : "%";
+
+
+
       $groups = Array();
-      $sql_grouplist = "SELECT mb_group_id FROM mb_group";
-      $res_groups = db_query($sql_grouplist);
+      $sql_grouplist = "SELECT mb_group_id FROM mb_group WHERE mb_group_id LIKE $1 AND mb_group_name LIKE $2;";
+      $v = array($id,$name);
+      $t = array("s","s");
+      $res_groups = db_prep_query($sql_grouplist,$v,$t);
 
       while($row = db_fetch_array($res_groups))
       {
@@ -225,9 +243,10 @@
 
       $sql_group = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = '$name'";
       $res_group = db_query($sql_group);
+
       if($row = db_fetch_array($res_group))
       {
-        return  new Group($row['mb_group_id']);
+        return new Group($row['mb_group_id']);
       }
       return null;
 

Modified: trunk/mapbender/http/classes/class_user.php
===================================================================
--- trunk/mapbender/http/classes/class_user.php	2009-09-26 18:35:52 UTC (rev 4737)
+++ trunk/mapbender/http/classes/class_user.php	2009-09-26 18:37:47 UTC (rev 4738)
@@ -128,7 +128,7 @@
 		if($insert_result == false)
 		{
 			db_rollback();
-			$e = new Exception("Could not insert new user");
+			throw new Exception("Could not insert new user");
 		}
 
 		$id = db_insertid($insert_result,'mb_user','mb_user_id');
@@ -145,13 +145,13 @@
 			}
 			catch(Exception $E)
 			{
-				$newE = new Exception("Could not set inital values of new user");
-				throw $newE;
+				throw new Exception("Could not set inital values of new user");
 			}
 		}
 
 
 		db_commit();
+        return true;
 
 
 	}
@@ -162,8 +162,12 @@
 	*/
 	public function change($changes) {
         //FIXME: validate input
+        if($changes->owner)
+        {
+          $owner = User::byName($changes->owner);
+        }
 		$this->name = $changes->name ? $changes->name : $this->name;
-		$this->owner = $changes->owner ? $changes->owner : $this->owner;
+		$this->owner = $changes->owner ? $owner->id : $this->owner;
 		$this->description = $changes->description ? $changes->description : $this->description;
 		$this->email = $changes->email ? $changes->email : $this->email;
 		$this->phone = $changes->phone ? $changes->phone : $this->phone;



More information about the Mapbender_commits mailing list