Location: PHPKode > projects > Monyet > classes/user.php
<?php

//this class will be notified if belonging group is deleted

Class User Extends EntityBase implements Observer{

	private $username;
	private $password;
	private $group;
	private $realname;
	private $email;
	private $handset;

	public function __construct(){
		//PHYSIC TABLE DEFINITION for User
		//-----------------------------------------------------
		$tablename = 'userauth';
		
		$field_username = 'username';
		$field_password = 'password';
		$field_group = 'group_id';
		$field_realname = 'realname';
		$field_email = 'email';
		$field_handset = 'handset';
		//-----------------------------------------------------
		
		$rawfields = array('username'=>$field_username,'password'=>$field_password,'group'=>$field_group,
				  'realname'=>$field_realname,'email'=>$field_email,'handset'=>$field_handset);
		$group = new Group();	 
		$attributes = array($field_username,$group->getField('name'),$field_realname,$field_email,$field_handset);
		$condition = $group->getPrimaryKey().' = '.$tablename.'.'.$field_group;

		parent::__construct(array($tablename,$group->getPrimaryTable()),$field_username,$attributes,$rawfields,$condition);
	}
	
	public function notifyRemove($obj,$id){
		if($obj instanceOf Group){
			$this->removeWith($this->getField('group'),$id);
		}
	}

	//this is only wrapper to provide single object
	//just copy paste for all children
	public function selectByID($id){
		$tempobj = parent::selectByID($id);
		if($tempobj){
			foreach($this->rawfields as $key => $value){
				$this->$key = $tempobj->$value;
			}
		}
	}

	public function getUsername(){
		return $this->username;
	}

	public function getEmail(){
		return $this->email;
	}

	public function getRealname(){
		return $this->realname;
	}

	public function getPassword(){
		return $this->password;
	}

	public function getHandset(){
		return $this->handset;
	}

	public function getGroup(){
		return $this->group;
	}

	public function getGroupID($username){
		$groupfield = $this->getField('group');
		$sql = 'SELECT '.$groupfield.' FROM '.$this->getPrimaryTable().' WHERE '.$this->getField('username').' =\''.$username.'\'';
		$result = $this->dba->query($sql);
		if($result){
			return $result[0]->$groupfield;
		}
	}	
	public function validate($username,$password){
		$where = $this->getField('username').' = \''.$username.'\''.' AND '.$this->getField('password').'=\''.$password.'\'';
		return parent::isExistByCondition($where); 	
	}	
	public function __destruct(){
		parent::__destruct();	
	}
}

?>
Return current item: Monyet