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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon May 31 07:57:12 EDT 2010


Author: christoph
Date: 2010-05-31 07:57:12 -0400 (Mon, 31 May 2010)
New Revision: 6226

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


Modified: trunk/mapbender/http/classes/class_group.php
===================================================================
--- trunk/mapbender/http/classes/class_group.php	2010-05-31 11:52:05 UTC (rev 6225)
+++ trunk/mapbender/http/classes/class_group.php	2010-05-31 11:57:12 UTC (rev 6226)
@@ -42,21 +42,17 @@
 	 * 							this object. If null, create an empty object
 	 */
 	public function __construct ($groupId) {
-
-       // throw new Exception("CONSTR  : ". $this->id);
-        if($groupId == null){
-          // new group
-          return;
-        }
-        $this->id = $groupId;
+		if (!is_numeric($groupId)) {
+			return;
+		}
 		try{
 			$this->load();
 		}
-		catch(Exception $E)
-		{
-			new mb_exception($E->getMessage());
+		catch(Exception $e) {
+			new mb_exception($e->getMessage());
+			return;
 		}
-
+		$this->id = $groupId;
 	}
 
 
@@ -67,69 +63,66 @@
 		return (string) $this->id;
 	}
 
+    /**
+     * @return Assoc Array containing the fields to send to the user
+     */
+	public function getFields () {
+		return array(
+			"name" => $this->name,
+			"owner" => $this->owner,
+			"description" => $this->description
+		);
+	}
+	
+	public function create() {
+		if (is_null($this->name) || $this->name == "") {
+			$e = new Exception("Can't create group without name");
+		}
+		
+		db_begin();
 
-    /*
-    * @return Assoc Array containing the fields to send to the user
-    */
-    public function getFields() {
-      $result = array(
-        "name" => $this->name,
-        "owner" => $this->owner,
-        "description" => $this->description
-      );
-      return $result;
-    }
-
-	public function  create() {
-		if($this->name == ""){ $e = new Exception("Can' t create group without name");}
-
-		$sql_group_create = "INSERT INTO mb_group (mb_group_name) VALUES ('". $this->name ."');";
+		$sql_group_create = "INSERT INTO mb_group (mb_group_name) VALUES ($1)";
 		$v = array($this->name);
 		$t = array("s");
+		$insert_result = db_query($sql_group_create);
 
-		db_begin();
-
-		$insert_result = db_query($sql_group_create);
-		if($insert_result == false)
-		{
+		if (!$insert_result) {
 			db_rollback();
 			$e = new Exception("Could not insert new group");
+			return false;
 		}
-
+		
 		$id = db_insertid($insert_result,'mb_group','mb_group_id');
-		if($id != 0)
-		{
+		if ($id != 0) {
 			$this->id = $id;
 		}
-
+		
 		$commit_result = $this->commit();
-		if($commit_result == false)
-		{
+		if ($commit_result == false) {
 			try {
 				db_rollback();
 			}
-			catch(Exception $E)
-			{
+			catch (Exception $E)	{
 				$newE = new Exception("Could not set inital values of new group");
 				throw $newE;
+				return false;
 			}
+			return false;
 		}
-
-
+		
 		db_commit();
-        return true;
+		return true;
 	}
 
 
-	/*
-	*	@param	$changes JSON  keys and their values of what to change in the object
-	*/
+	/**
+	 *	@param	$changes JSON  keys and their values of what to change in the object
+	 */
 	public function change($changes) {
         //FIXME: validate input
 
-        if($changes->owner)
-        {
-          $owner = User::byName($changes->owner);
+        if ($changes->owner) {
+			$owner = User::byName($changes->owner);
         }
 		$this->name = $changes->name ? $changes->name : $this->name;
 		$this->owner = $changes->owner ? $owner->id : $this->owner;
@@ -198,6 +191,20 @@
 		return true;
 	}
 
+	public static function intersect ($groups1, $groups2) {
+		$intersection = array();
+		$len1 = count($groups1) - 1;
+		for ($i = $len1; $i >= 0; $i--) {
+			$len2 = count($groups2) - 1;
+			for ($j = $len1; $j >= 0; $j--) {
+				if ($groups1[$i]->id === $groups2[$j]->id) {
+					$intersection[]= $groups1[$i];
+				}
+			}
+		}
+		return $intersection;
+	}
+
     /*
     * @return Array of Groups
     * @param $filter UNUSED! AssocArray, valid keys "id","name". Use SQL's % and _ to perform simple matching
@@ -216,8 +223,7 @@
       $t = array("s");
       $res_groups = db_prep_query($sql_grouplist,$v,$t);
 
-      while($row = db_fetch_array($res_groups))
-      {
+      while($row = db_fetch_array($res_groups)) {
         try{
           $groups[] = new Group($row['mb_group_id']);
         }
@@ -241,8 +247,8 @@
 
       if($name == null) { return new Group(null); }
 
-      $sql_group = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = '$name'";
-      $res_group = db_query($sql_group);
+      $sql_group = "SELECT mb_group_id FROM mb_group WHERE mb_group_name = $1";
+      $res_group = db_prep_query($sql_group, array($name), array("s"));
 
       if($row = db_fetch_array($res_group))
       {
@@ -251,5 +257,13 @@
       return null;
 
     }
+	
+	public function isValid () {
+		if (!is_null($this->name)) {
+			return true;
+		}
+		return false;
 	}
+	
+	}
 ?>

Modified: trunk/mapbender/http/classes/class_user.php
===================================================================
--- trunk/mapbender/http/classes/class_user.php	2010-05-31 11:52:05 UTC (rev 6225)
+++ trunk/mapbender/http/classes/class_user.php	2010-05-31 11:57:12 UTC (rev 6226)
@@ -823,5 +823,12 @@
 		}
         return true;
 	}
+	
+	public function isValid () {
+		if (!is_null($this->name)) {
+			return true;
+		}
+		return false;
+	}
 }
 ?>



More information about the Mapbender_commits mailing list