[Mapbender-commits] r4061 - branches/kmq_dev/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jun 19 16:47:58 EDT 2009


Author: kmq
Date: 2009-06-19 16:47:57 -0400 (Fri, 19 Jun 2009)
New Revision: 4061

Modified:
   branches/kmq_dev/http/classes/class_user.php
Log:
Started adding Methods to class Use

Modified: branches/kmq_dev/http/classes/class_user.php
===================================================================
--- branches/kmq_dev/http/classes/class_user.php	2009-06-19 15:41:40 UTC (rev 4060)
+++ branches/kmq_dev/http/classes/class_user.php	2009-06-19 20:47:57 UTC (rev 4061)
@@ -27,6 +27,25 @@
 	 * @var Integer The user ID
 	 */
 	var $id;
+	var $name;
+	var $password = ""; // passwords should be set, not read
+	var $owner; // make this reference to a USER object 
+	var $descr;
+	var $loginCount;
+	var $email;
+	var $phone;
+	var $department;
+	var $resolution;
+	var $organization;
+	var $position;
+	var $phone1;
+	var $fax;
+	var $deliveryPoint;
+	var $city;
+	var $postalCode;
+	var $country;
+	var $url;
+
 	
 	/**
 	 * Constructor
@@ -35,6 +54,8 @@
 	 */
 	public function __construct ($userId) {
 		$this->id = $userId;
+		
+		if($userId ) {$this->load();}
 	}	
 	
 	/**
@@ -43,7 +64,129 @@
 	public function __toString () {
 		return (string) $this->id;	
 	}
+
+	/*
+	* @return JSON serialization of this user
+	*/
+
+	public function toJSON()
+	{
+			
+		$result = '{"name":"'. 				$this->name .'",'
+							.'"password":"'. 		$this->password .'",'
+							.'"owner":"'. 			$this->owner .'",'
+							.'"descr":"'. 			$this->descr .'",'
+							.'"loginCount":"'.	$this->loginCount .'",'
+							.'"email":"'.				$this->email .'",'
+							.'"phone":"'.				$this->phone .'",'
+							.'"department":"'.	$this->department .'",'
+							.'"resolution":"'.		$this->resolution .'",'
+							.'"organization":"'.$this->organizatin .'",'
+							.'"position":"'.		$this->position .'",'
+							.'"phone1":"'.			$this->phone1	.'",'
+							.'"fax":"'.					$this->fax	.'",'
+							.'"deliveryPoint":"'.	$this->deliveryPoint	.'",'
+							.'"city":"'.				$this->city	.'",'
+							.'"postalCode":"'.	$this->postalCode	.'",'
+							.'"country":"'.			$this->country	.'",'
+							.'"url":"'.					$this->url	.'"}';
+
+		return $result;
+	}
+
+	public function  create()
+	{
+		//FIXME: can users exist that have the same name? I think not, but the db does not enforce it
+		if($this->name == ""){ $e = new mb_exception("Can' t create user without name");}
+		
+		$sql_user_create = "INSERT INTO mb_user (mb_user_name) VALUES ($1) ; ";
+		$v = array($this->name);
+		$t = array("s");
 	
+		db_begin();
+	//	$sql_user_prepared = db_prepare_query($sql_user_create,$v,$t);
+		$sql_user_prepared = "INSERT INTO mb_user (mb_user_name) VALUES ('". $this->name ."') ; ";
+		$result = db_query($sql_user_prepared);
+		
+		if($result == false)
+		{
+			db_rollback();
+			$e = new mb_exception("Could not insert new user");
+		}
+	
+		$commit_result = $this->commit();
+		if($commit_result == false)
+		{
+			try {
+				db_rollback();
+			}
+			catch(Exception $E)
+			{
+				print "cautght it";
+				$newE = new mb_exception("Could not set inital values of new user");
+				throw $newE;
+			}
+		}
+		db_commit();
+
+
+	}
+
+	public function commit()
+	{
+		//db_begin();
+		//db_commit();
+	}
+
+	public function remove()
+	{
+
+		$sql_user_remove = "DELETE FROM mb_user WHERE mb_user_id = $1";
+		$v = array($this->id);
+		$t = array("i");
+		$sql_prepared = db_prepare_query($sql_user_remove,$v,$t);
+		$result = db_query($sql_prepared);
+		if($result == false)
+		{
+			$e = new mb_exception("Could not delete user");
+		}
+		return true;
+	}
+
+	public function load()
+	{
+		$sql_user = "SELECT * from mb_user WHERE mb_user_id = $1; ";
+		$v = array($this->id);
+		$t = array("i");
+		$res_user = db_prep_query($sql_user,$v,$t);
+		if($row = db_fetch_array($res_user)){
+
+			$this->name = $row['mb_user_name'];
+			$this->password = ""; // passwords should be set, not read
+			$this->owner = $row['mb_user_owner'];
+			$this->descr	= $row['mb_user_description'];
+			$this->loginCount = $row['mb_user_login_count'];
+			$this->email = $row['mb_user_email'];
+			$this->phone = $row['mb_user_phone'];
+			$this->department = $row['mb_user_department'];
+			$this->resolution = $row['mb_user_resolution'];
+			$this->organization = $row['mb_user_organizationName'];
+			$this->position = $row['mb_user_position_name'];
+			$this->phone1 = $row['mb_user_phone1'];
+			$this->fax = $row['mb_user_facsimile'];
+			$this->deliveryPoint = $row['mb_user_delivery_point'];
+			$this->city = $row['mb_user_user_city'];
+			$this->postalCode = $row['mb_user_postal_code'];
+			$this->country = $row['mb_user_country'];
+			$this->url = $row['mb_user_online_resource'];
+
+		}else{
+			//no such user
+			echo "no such user";
+		}
+		return true;
+	}
+	
 	/**
 	 * Returns an array of application IDs that the user is allowed to access.
 	 * 



More information about the Mapbender_commits mailing list