_role = $role; return $this; } /** * @return string * @throws Exception */ public function getRole() { if (null === $this->_role) { throw new Exception('Role is empty.'); } return $this->_role; } /** * @param int $roleId * @return $this */ public function setRoleId($roleId) { $this->_roleId = $roleId; return $this; } /** * @return int * @throws Exception */ public function getRoleId() { if (null === $this->_role) { throw new Exception('Role ID is empty.'); } return $this->_roleId; } public function getRoleInfo() { $info = null; $role = $this->getRole(); switch ($role) { case Entity::ROLE_USER: $info = $this->_getUserInfo(); break; case Entity::ROLE_ADMIN: $info = $this->_getAdminInfo(); break; case Entity::ROLE_STAFF; throw new Exception('Role "' . $role . '" not implemented'); break; default: throw new Exception('Unknown role "' . $role . '".'); } return $info; } protected function _getUserInfo() { $roleId = $this->getRoleId(); $select = $this->_db->select(); $select->from($this->_getPair('User', 'u')); $select->join($this->_getPair('UserStatus', 'us'), '`u`.`status` = `us`.`id`', ['statusTitle' => 'title']); $select->where('`u`.`id` = ?', $roleId, Qs_Db::INT_TYPE); $row = $this->_db->fetchRow($select); if ($row) { $row['moduleUrl'] = Qs_SiteMap::findFirst(null, ['type' => 'User\\Admin\\'], null, 'url'); } return $row; } protected function _getAdminInfo() { $roleId = $this->getRoleId(); $select = $this->_db->select(); $select->from($this->_getPair('Admin', 'a')); $select->where('`a`.`id` = ?', $roleId, Qs_Db::INT_TYPE); $row = $this->_db->fetchRow($select); if ($row) { $row['moduleUrl'] = Qs_SiteMap::findFirst(null, ['type' => 'Admin_'], null, 'url'); } return $row; } }