Ejemplo n.º 1
0
 /**
  * Browse publications
  *
  * @return  void
  */
 public function browseTask()
 {
     // Set the default sort
     $default_sort = 'date';
     if ($this->config->get('show_ranking')) {
         $default_sort = 'ranking';
     }
     // Incoming
     $this->view->filters = array('category' => Request::getVar('category', ''), 'sortby' => Request::getCmd('sortby', $default_sort), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'tag' => trim(Request::getVar('tag', '', 'request', 'none', 2)), 'tag_ignored' => array());
     if (!in_array($this->view->filters['sortby'], array('date', 'title', 'id', 'rating', 'ranking', 'popularity'))) {
         $this->view->filters['sortby'] = $default_sort;
     }
     // Get projects user has access to
     if (!User::isGuest()) {
         $obj = new \Components\Projects\Tables\Project($this->database);
         $this->view->filters['projects'] = $obj->getUserProjectIds(User::get('id'));
     }
     // Get major types
     $t = new Tables\Category($this->database);
     $this->view->categories = $t->getCategories();
     if (is_numeric($this->view->filters['category'])) {
         $this->view->filters['category'] = (int) $this->view->filters['category'];
     }
     if (!is_int($this->view->filters['category'])) {
         foreach ($this->view->categories as $cat) {
             if (trim($this->view->filters['category']) == $cat->url_alias) {
                 $this->view->filters['category'] = (int) $cat->id;
                 break;
             }
         }
         if (!is_int($this->view->filters['category'])) {
             $this->view->filters['category'] = null;
         }
     }
     // Instantiate a publication object
     $model = new Models\Publication();
     // Execute count query
     $this->view->total = $model->entries('count', $this->view->filters);
     // Run query with limit
     $this->view->results = $model->entries('list', $this->view->filters);
     // Initiate paging
     $this->view->pageNav = new \Hubzero\Pagination\Paginator($this->view->total, $this->view->filters['start'], $this->view->filters['limit']);
     // Get type if not given
     $this->_title = Lang::txt(strtoupper($this->_option)) . ': ';
     if ($this->view->filters['category'] != '') {
         $t->load($this->view->filters['category']);
         $this->_title .= $t->name;
         $this->_task_title = $t->name;
     } else {
         $this->_title .= Lang::txt('COM_PUBLICATIONS_ALL');
         $this->_task_title = Lang::txt('COM_PUBLICATIONS_ALL');
     }
     // Set page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Output HTML
     $this->view->title = $this->_title;
     $this->view->config = $this->config;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setName('browse')->setLayout('default')->display();
 }