flush(); } /** * * @return Masters_Helper_Acl */ public static function getInstance() { if ( NULL == self::$instance) self::$instance = new self(); return self::$instance; } /** * Method flushing privileges, for instance for situations when we change language during execution * * @return NULL */ public function flush() { $this->privileges = array(); $this->privileges_loaded = false; } /** * Check privilege * * @param string $name property name * @return bool */ public function get($num) { if($this->privileges_loaded==false) { $this->loadConstPrivileges(); } if ( array_key_exists($num,$this->const_privileges) ) { return $this->const_privileges[$num]; } else { //print "wpadam"; $this->checkAndFill($num); return 1; } } /** * Check full rights array * * @param string $name property name * @return bool */ public function getArray() { print_r($this->const_privileges); die; } private function checkAndFill($num) { $req = $_SERVER['REQUEST_URI']; $varName = $num; $varValue = $num; $parent = 0; $privilegeModel = new User_Privileges(); $check = $privilegeModel->getAdapter()->fetchRow("select * from privileges where stala='".$num."'"); if($check===false) { $mDictionaryVariable = new Dictionary_Variable(); $mDictionaryValue = new Dictionary_Value(); $aDictionaryVariableData = array("name" => $varName, "controller" => 'privileges'); $varId = $mDictionaryVariable->insert($aDictionaryVariableData); $aDictionaryValueData = array( "dictionaryVariableId" => $varId, "languageId" => Zend_Registry::get('defaultLanguageId'), "value" => $varValue); $mDictionaryValue->insert($aDictionaryValueData); $aPrivilegeData = array( "dictionaryVariableId" => $varId, "parent" => $parent, "is_active"=>0, "occurrence"=>$req, "stala"=>$num); $privilegeModel = new User_Privileges(); $prId = $privilegeModel->insert($aPrivilegeData); } } /** * laduje uprawnienia w oparciu o stringi * powszechnie uzywana. * @return unknown_type */ public function loadConstPrivileges() { $oDbAdapter = Zend_Registry::get("dbAdapter"); $view = Zend_Layout::getMvcInstance()->getView(); $uid = $view->current_user->id; $query="select t1.id, userId,t1.stala, t1.is_active from (select * from `privileges`) as t1 left join (select * from user_privileges where userId=".$uid.") as t2 on t1.id=t2.privilegeId "; //print $query; die; $result = $oDbAdapter->fetchAll($query); foreach($result as $res) { if($res->userId>0) { $val=1; } else { if($res->is_active==0) { $val=1; } else { $val=0; } } $this->const_privileges[$res->stala] = $val; } //print_r($this->const_privileges); $this->privileges_loaded = true; } /** * laduje uprawnienia w oparciu o stringi * uzywana gdy na strone wchodzi guest * @return unknown_type */ public function loadConstPrivilegesByGroup($id) { $oDbAdapter = Zend_Registry::get("dbAdapter"); $query="select t1.id, group_id,t1.stala, t1.is_active from (select * from `privileges`) as t1 left join (select * from user_groups_privileges where group_id=".$id.") as t2 on t1.id=t2.privilege_id "; $result = $oDbAdapter->fetchAll($query); foreach($result as $res) { if($res->group_id>0) { $val=1; } else { if($res->is_active==0) { $val=1; } else { $val=0; } } $this->const_privileges[$res->stala] = $val; } //print_r($this->const_privileges); $this->privileges_loaded = true; } /** * @todo zdecydowac siÄ™ na jakies zachowanie gdy nie ma uprawnien * Enter description here... * @return unknown_type */ public function noPrivileges() { die; } }