_db->select(); $select->from($this->_getPair('User2Permission')); $select->where('User2Permission.userId = ?', $userId, Qs_Db::INT_TYPE); $select->join( $this->_getPair($this->_tableAlias), 'User2Permission.permissionId=' . $this->_tableAlias . '.id' ); $select->join( $this->_getPair('DResource'), 'DResource.id=' . $this->_tableAlias . '.resourceId', array('resourceName' => 'DResource.name') ); $select->join( $this->_getPair('DPrivilege'), 'DPrivilege.id=' . $this->_tableAlias . '.privilegeId', array('privilegeName' => 'DPrivilege.name') ); return array_merge($this->_db->fetchAll($select), $this->_getDepartmentRule($userId)); } public function getResource() { return array_merge($this->getDResource4Select(), $this->_getDepartmentResource()); } protected function _getDepartmentResource() { $select = $this->_db->select(); $select->from( $this->_getPair('Department'), new Zend_Db_Expr("('" . self::DEPARTMENT_PREFIX . "' + CAST(id AS varchar(30)))") ); $select->where('parentId = ?', 0, Qs_Db::INT_TYPE); return $this->_db->fetchCol($select); } protected function _getDepartmentRule($userId) { $select = $this->_db->select(); $select->from( $this->_getPair('User2Department'), array( 'userId', 'resourceName' => new Zend_Db_Expr("('" . self::DEPARTMENT_PREFIX . "' + CAST(departmentId AS varchar(30)))"), 'privilegeName' => new Zend_Db_Expr($this->_db->quote(self::DEPARTMENT_PRIVILEGE)) ) ); $select->where('userId = ?', $userId, Qs_Db::INT_TYPE); return $this->_db->fetchAll($select); } }