<?

/**
 * $Id: Admin.mod.php 703 2008-06-26 11:15:09Z pawy $
 * Klasa przechowujaca dane zalogowanego admina
 *
 */
class Admin  extends  DataObject  {

	const SMARTY_NAME = 'admin';
	const SMARTY_DEFAULT_ACCESS = 'admin';
	

	static $tableName = 'mf_admin';
	static $classTablePK = 'id_mf_admin';

	static $className = __CLASS__;


	static $fields = array(
		'id_mf_admin'			=> 'id',
		'email'				=> 'email',
		'first_name'			=> 'firstName',
		'last_name'			=> 'lastName',
		'login'				=> 'login',
		'password'			=> 'password',
		'role'				=> 'role',
		'last_login'			=> 'lastLogin',
		'description'			=> 'description',
		'online'			=> 'online',
		'last_activity'			=> 'lastActivity',
		'phone'				=> 'phone',
		'authorized'			=> 'authorized',
		'photo_src'			=> 'photoSrc',
		'forum_count'		=> 'forumCount',
		'_create_time'		=> 'createTime',
		'moderated_post_count'		=> 'moderatedPostCount',
		'archive'			=> 'archive',
		'delete_time'		=> 'deleteTime'
	);


	public  function GetTableName(){
		return self::$tableName;
      }

	public  function GetFields(){
		return self::$fields;
      }

	public  function GetClassName(){
		return self::$className;
      }


    public function GetClassTablePK() {
        return self::$classTablePK;
    }



	
	/**
	 * id admnina
	 *
	 * @var integer
	 */
	protected $id;
	/**
	 * email admina
	 *
	 * @var string
	 */
	private $email;
	/**
	 * Imie i nazwisko admina
	 *
	 * @var string
	 */
	private $firstName;
	private $lastName;
	/**
	 * login admina
	 *
	 * @var string
	 */
	private $login;
	private $password;
	/**
	 * Rola admina
	 *
	 * @var string
	 */

	private $role;
	/**
	 * Szablon uprawnien
	 *
	 * @var array
	 */
	private $access;
	/**
	 * Data i godzina ostatniego logowania
	 *
	 * @var string
	 */
	private $lastLogin;

	private $online;
	private $lastActivity;

	private $phone;
	
	private $description;

	private $authorized;

	private $photoSrc;

	private $forumCount;

	private $createTime;
	private $moderatedPostCount;

	private $archive;
	private $deleteTime;

	function __construct($id = -1, $description = null, $email = null, $firstName = null, $lastName = null, $login = null, $password = null, $role = null, $access = null, $lastLogin = null, $online = null, $phone = null, $authorized = null, $moderatedPostCount = null,$archive =null) {
	    $this->id = $id;
	    $this->description = $description;
	    $this->email = $email;
	    $this->firstName = $firstName;
	    $this->lastName = $lastName;
	    $this->login = $login;
	    $this->role = $role;
	    $this->access = $access;
	    $this->lastLogin = $lastLogin;
	    $this->online = $online;
	    $this->phone = $phone;
	    $this->authorized = $authorized;
	    $this->moderatedPostCount = $moderatedPostCount;
	    $this->archive = $archive;

	}


	public function getModeratedPostCount() {
	    return $this->moderatedPostCount;
	}

	public function setModeratedPostCount($moderatedPostCount) {
	    $this->moderatedPostCount = $moderatedPostCount;
	}
	
	public function getId() {
	    return $this->id;
	}

	public function setId($id) {
	    $this->id = $id;
	}

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

	public function setEmail($email) {
	    $this->email = $email;
	}

	public function getName() {
	    return $this->firstName . " " . $this->lastName;
	}

	public function getFirstName() {
	    return $this->firstName;
	}

	public function setFirstName($firstName) {
	    $this->firstName = $firstName;
	}

	public function getLastName() {
	    return $this->lastName;
	}

	public function setLastName($lastName) {
	    $this->lastName = $lastName;
	}

	public function getLogin() {
	    return $this->login;
	}

	public function setLogin($login) {
	    $this->login = $login;
	}
	
	public function getPassword() {
	    return $this->password;
	}
	
	public function setPassword($password) {
	    $this->password = $password;
	}
	
	public function getRole() {
	    return $this->role;
	}

	public function setRole($role) {
	    $this->role = $role;
	}

	public function getLastLogin() {
	    return $this->lastLogin;
	}

	public function setLastLogin($lastLogin) {
	    $this->lastLogin = $lastLogin;
	}

	public function getOnline() {
	    return $this->online;
	}

	public function setOnline($online) {
	    $this->online = $online;
	}

	public function getLastActivity() {
	    return $this->lastActivity;
	}

	public function setLastActivity($lastActivity) {
	    $this->lastActivity = $lastActivity;
	}


	public function getPhone() {
	    return $this->phone;
	}

	public function setPhone($phone) {
	    $this->phone = $phone;
	}

	public function getDescription() {
	    return $this->description;
	}

	public function setDescription($description) {
	    $this->description = $description;
	}

	public function getAuthorized() {
	    return $this->authorized;
	}

	public function setAuthorized($authorized) {
	    $this->authorized = $authorized;
	}

	public function getPhotoSrc() {
	    return $this->photoSrc;
	}

	public function setPhotoSrc($photoSrc) {
	    $this->photoSrc = $photoSrc;
	}

	public function getForumCount() {
		return $this->forumCount;
	}

	public function setForumCount($forumCount) {
		$this->forumCount = $forumCount;
	}

	public function GetPhotoUrl($type = 120) {
		if($this->photoSrc) {
			switch($type) {
				case 50:
					return $this->photoSrc .'_50.' . PhotoDAL::PHOTO_NEW_EXT;
					break;

				case 120:
					return $this->photoSrc .'_120.' . PhotoDAL::PHOTO_NEW_EXT;
					break;

				default:
					return $this->photoSrc .'_120.'. PhotoDAL::PHOTO_NEW_EXT;
					break;
			}
		}
		return null;
	}


	/**
	 * Funkcja kontrolna
	 *
	 * @return boolean
	 */
	public function IsAuthorized() {
		return $this->authorized;
	}


	public function getAccess() {

		if($this->access == null){
		    $this->access = AdminDAL::GetArrayAccess($this);
		}
		return $this->access;
	}

	public function setAccess($access) {
	    $this->access = $access;
	}

	public function getCreateTime() {
		return $this->createTime;
	}

	public function setCreateTime($createTime) {
		$this->createTime = $createTime;
	}
	
	public function getArchive() {
		return $this->archive;
	}

	public function setArchive($archive) {
		$this->archive = $archive;
	}

	public function getDeleteTime() {
		return $this->deleteTime;
	}

	public function setDeleteTime($deleteTime) {
		$this->deleteTime = $deleteTime;
	}

	/**
	 * Sprawdza uprawnienia do zasobu
	 *
	 * @param string $where
	 * @return boolean
	 */
	public function CheckAccess($where) {
		
	
		if (array_key_exists($where, $this->access)) {
			return true;
		} else {
			return false;
		}
		

	}
}
?>