Example #1
0
 /**
  * Lists projects
  *
  * @return  void
  */
 public function displayTask()
 {
     $this->view->config = $this->config;
     // Get quotas
     $this->view->defaultQuota = Helpers\Html::convertSize(floatval($this->config->get('defaultQuota', 1)), 'GB', 'b');
     $this->view->premiumQuota = Helpers\Html::convertSize(floatval($this->config->get('premiumQuota', 30)), 'GB', 'b');
     // Get filters
     $this->view->filters = array('limit' => Request::getState($this->_option . '.projects.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.projects.limitstart', 'limitstart', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.projects.search', 'search', '')), 'sortby' => Request::getState($this->_option . '.projects.sort', 'filter_order', 'id'), 'sortdir' => Request::getState($this->_option . '.projects.sortdir', 'filter_order_Dir', 'DESC'), 'authorized' => true, 'getowner' => 1, 'activity' => 1, 'quota' => Request::getVar('quota', 'all', 'post'));
     $this->view->limit = $this->view->filters['limit'];
     $this->view->start = $this->view->filters['start'];
     // Retrieve all records when filtering by quota (no paging)
     if ($this->view->filters['quota'] != 'all') {
         $this->view->filters['limit'] = 'all';
         $this->view->filters['start'] = 0;
     }
     $obj = new Tables\Project($this->database);
     // Get records
     $this->view->rows = $obj->getRecords($this->view->filters, true, 0, 1);
     // Get a record count
     $this->view->total = $obj->getCount($this->view->filters, true, 0, 1);
     // Filtering by quota
     if ($this->view->filters['quota'] != 'all' && $this->view->rows) {
         $counter = $this->view->total;
         $rows = $this->view->rows;
         for ($i = 0, $n = count($rows); $i < $n; $i++) {
             $params = new \Hubzero\Config\Registry($rows[$i]->params);
             $quota = $params->get('quota', 0);
             if ($this->view->filters['quota'] == 'premium' && $quota < $this->view->premiumQuota || $this->view->filters['quota'] == 'regular' && $quota > $this->view->defaultQuota) {
                 $counter--;
                 unset($rows[$i]);
             }
         }
         $rows = array_values($rows);
         $this->view->total = $counter > 0 ? $counter : 0;
         // Fix up paging after filter
         if (count($rows) > $this->view->limit) {
             $k = 0;
             for ($i = 0, $n = count($rows); $i < $n; $i++) {
                 if ($k < $this->view->start || $k >= $this->view->limit + $this->view->start) {
                     unset($rows[$i]);
                 }
                 $k++;
             }
         }
         $this->view->rows = array_values($rows);
     }
     // Set any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     // Check that master path is there
     if ($this->config->get('offroot') && !is_dir($this->config->get('webpath'))) {
         $this->view->setError(Lang::txt('Master directory does not exist. Administrator must fix this! ') . $this->config->get('webpath'));
     }
     // Output the HTML
     $this->view->display();
 }