Exemplo n.º 1
0
 /**
  * @param Mage_Admin_Model_User $user
  *
  * @return $this
  */
 public function addAdminUserFilter($user)
 {
     $this->getSelect()->joinLeft(array('dep_perm' => $this->getTable('aw_hdu3/department_permission')), 'main_table.department_id = dep_perm.department_id', array());
     /**
      * @var $agent AW_Helpdesk3_Model_Department_Agent
      */
     $agent = Mage::getModel('aw_hdu3/department_agent')->loadAgentByUserId($user->getId());
     $agentFullDepartmentCollection = $agent->getFullDepartmentCollection();
     $agentFullDepartmentIds = $agentFullDepartmentCollection->getAllIds();
     $mainTableDepartmentSql = '1=0';
     if (!empty($agentFullDepartmentIds)) {
         $mainTableDepartmentSql = 'FIND_IN_SET(main_table.department_id, \'' . join(',', $agentFullDepartmentCollection->getAllIds()) . '\')';
     }
     $agentDepartmentCollection = $agent->getDepartmentCollection();
     $departmentIdConditionList = array();
     foreach ($agentDepartmentCollection->getAllIds() as $departmentId) {
         $departmentIdConditionList[] = 'FIND_IN_SET(' . $departmentId . ', department_ids)';
     }
     $departmentIdSql = '1=0';
     if (count($departmentIdConditionList)) {
         $departmentIdSql = join(' OR ', $departmentIdConditionList);
     }
     $adminRoleIdSql = 'FIND_IN_SET(' . $user->getRole()->getId() . ', admin_role_ids)';
     $whereSql = '(' . $mainTableDepartmentSql . ' OR ' . $departmentIdSql . ' OR ' . $adminRoleIdSql . ')';
     $this->getSelect()->where($whereSql);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * @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;
 }