_init('aw_hdu3/department_permission'); } /** * @param $departmentId * * @return $this */ public function loadByDepartmentId($departmentId) { return $this->load($departmentId, 'department_id'); } /** * @param Mage_Admin_Model_User $user * * @return bool */ public function isCanViewTicket($user) { $agent = Mage::getModel('aw_hdu3/department_agent')->loadAgentByUserId($user->getId()); $agentDepartmentCollection = $agent->getDepartmentCollection(); $departmentIds = $agentDepartmentCollection->getAllIds(); //check department foreach ($departmentIds as $depId) { if (in_array($depId, $this->getDepartmentIds())) { return true; } } //check admin role if (in_array($user->getRole()->getId(), $this->getAdminRoleIds())) { return true; } return false; } public function save() { $this->isDeleted(!($this->getDepartmentIds() || $this->getAdminRoleIds())); return parent::save(); } }