<?php
/**
 * Klasa administratora
 *
 */
class MfAdmin  extends DataObject {

	/**
	 * nazwa tabeli
	 */
	static $tableName = 'mf_admin';

	/**
	 * nazwa klucza tabeli
	 */
	static $classTablePK = 'id_mf_admin';
		
	/**
	 * nazwa klasy
	 */
	static $className = __CLASS__;

	/**
	 * tabela mapująca pola z bazy SQL na pola klasy.
	 */
	static $fields = array(
		'id_mf_admin' =>'id',
		'login' =>'login',
		'password' =>'password',
		'email' =>'email',
		'last_login'=>'lastLogin'
	);

	protected $id;
	private $login;
	private $password;
	private $email;
	private $lastLogin;

	private $adminAccessList;


	public function GetId() {
		return $this->id;
	}

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

	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 GetEmail() {
		return $this->email;
	}

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

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

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



	public function GetAdminAccessList() {

		if(!is_array($this->adminAccessList)) {
			$data = MfAdminAccessDAL::GetUserAccessList($this->GetId());
			foreach($data as $dataObj) {
				$this->adminAccessList[$dataObj->GetRole()] = true;
			}
		}

		return $this->adminAccessList;
	}

	public function SetAdminAccessList($adminAccessList) {
		$this->adminAccessList = $adminAccessList;
	}

	public function CheckAccess($role) {
		$accesSet = $this->GetAdminAccessList();
		if(isset($accesSet[$role])) {
			return true;
		} else {
			return false;
		}
	}


	/**
	 * Funkcja kontrolna
	 *
	 * @return boolean
	 */
	public function IsAuthorized() {
		return true;
	}




	public function __construct($id = -1) {

	}

	 /**
	 * Pobiera nazwę tabeli reprezentującej obiekt w SQL
	 * @return string
	 */

	public  function GetTableName(){
		return self::$tableName;
      }
	/**
       * Pobiera taablice mapującą pola klasy na pola tabeli
       * @return array
       */
	public  function GetFields(){
		return self::$fields;
      }
	/**
       * Pobiera nazwę klasy
       * @return string
       */
	public  function GetClassName(){
		return self::$className;
      }


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