Exemplo n.º 1
0
 /**
  * Index action method
  *
  * @param  int $id
  * @return void
  */
 public function index($id = null)
 {
     if (null === $id || $this->services['acl']->isAllowed($this->sess->user->role, 'users-of-role-' . $id, 'index')) {
         $deniedRoles = [];
         $resources = $this->services['acl']->getResources();
         foreach ($resources as $name => $resource) {
             if (!$this->services['acl']->isAllowed($this->sess->user->role, $name, 'index')) {
                 $deniedRoles[] = (int) substr($name, strrpos($name, '-') + 1);
             }
         }
         $user = new Model\User();
         $searchAry = null;
         if (null !== $this->request->getQuery('search_for') && null !== $this->request->getQuery('search_by') && $this->request->getQuery('search_for') != '' && $this->request->getQuery('search_by') != '----') {
             $searchAry = ['for' => $this->request->getQuery('search_for'), 'by' => $this->request->getQuery('search_by')];
         }
         if ($user->hasPages($this->config->pagination, $id, $searchAry, $deniedRoles)) {
             $limit = $this->config->pagination;
             $pages = new Paginator($user->getCount($id, $searchAry, $deniedRoles), $limit);
             $pages->useInput(true);
         } else {
             $limit = null;
             $pages = null;
         }
         $this->prepareView('phire/users/index.phtml');
         $this->view->title = 'Users';
         $this->view->pages = $pages;
         $this->view->roleId = $id;
         $this->view->queryString = $this->getQueryString('sort');
         $this->view->searchFor = $this->request->getQuery('search_for');
         $this->view->searchBy = $this->request->getQuery('search_by');
         $this->view->users = $user->getAll($id, $searchAry, $deniedRoles, $limit, $this->request->getQuery('page'), $this->request->getQuery('sort'));
         $this->view->roles = $user->getRoles();
         $this->send();
     } else {
         $this->redirect(BASE_PATH . APP_URI . '/users');
     }
 }