getRestParam(0)) { reset($this->_roles); $this->redirect($this->finalUrl() . '/' . key($this->_roles)); } return parent::exec(); } protected function _initFilter() { $filter = []; if (null !== ($roleId = Qs_Request::getGetValue('roleId'))) { $filter['roleId'] = $roleId; } if (null !== ($controller = Qs_Request::getGetValue('controller')) && ($controllerOptions = $this->_getDataObj()->getControllerOptions()) && array_key_exists($controller, $controllerOptions) ) { $filter['controller'] = $controller; } if (null !== ($sessionId = Qs_Request::getGetValue('sessionId')) && ($sessionOptions = $this->_getDataObj()->getSessionOptions($filter)) && array_key_exists($sessionId, $sessionOptions) ) { $filter['sessionId'] = $sessionId; } $filter = array_filter($filter); $request = array_filter(Qs_Request::getGetValues('roleId', 'controller', 'sessionId')); $diff = array_diff($request, $filter); if (!empty($diff)) { $this->redirect($filter); } $this->_getDataObj()->addFilter($filter); return $this; } protected function _initAction() { parent::_initAction(); if ('list' == $this->_action) { $this->_initRole(); $this->_initFilter(); } return $this; } protected function _initRole() { reset($this->_roles); $this->_role = $this->getRestParam(0); if (array_key_exists($this->_role, $this->_roles)) { $this->_getDataObj()->setFilter('role', $this->_role); } else { $this->_action = self::ACTION_NOT_FOUND; } return $this; } protected function _getListOptions() { $options = parent::_getListOptions(); $options['baseUrl'] = $this->_getBaseUrl(); $options['hasRole'] = (bool) $this->_getDataObj()->getFilter('roleId'); $options['hasApplication'] = (bool) $this->_getDataObj()->getFilter('controller'); $options['groupBySession'] = $options['hasRole']; return $options; } protected function _getFilterFormOptions() { $options = parent::_getFilterFormOptions(); $options['roleOptions'] = $this->_getDataObj()->getRoleOptions(); $options['applicationOptions'] = $this->_getDataObj()->getControllerOptions(); if ($this->_getDataObj()->getFilter('roleId')) { $options['sessionOptions'] = $this->_getDataObj()->getSessionOptions(); } $options['defaults'] = Qs_Request::getGet(); return $options; } protected function _getBaseUrl() { return $this->finalUrl() . '/' . $this->_role; } public function setRoles(array $roles) { $this->_roles = []; foreach ($roles as $role => $options) { $this->setRole($role, $options); } return $this; } public function setRole($role, array $options) { $this->_roles[$role] = $options; return $this; } protected function _getRoleLinks() { $links = $this->_roles; $links[$this->_role]['active'] = 'y'; foreach ($links as $alias => &$link) { if ($alias == $this->_role) { $link['isActive'] = true; } else { $link['url'] = Qs_Request::getFinalBaseUrl() . '/' . $alias; } $link['options']['delimiter'] = '|'; } return $links; } protected function _doList() { $this->_saveBackUrl(); $this->_addLinksItem($this->_getRoleLinks()); $this->_addFilterItem(); $this->_addListItem(); $this->_postList(); return $this; } }