Esempio n. 1
0
 public function getHubTypesTask()
 {
     $config = Component::params('com_search');
     $query = new \Hubzero\Search\Query($config);
     $terms = Request::getVar('terms', '*:*');
     $type = Request::getVar('type', '');
     $limit = 0;
     $start = 0;
     $types = Event::trigger('search.onGetTypes');
     foreach ($types as $type) {
         $query->addFacet($type, array('hubtype', '=', $type));
     }
     // Administrators can see all records
     $isAdmin = User::authorise('core.admin', 'com_users');
     if ($isAdmin) {
         $query = $query->query($terms)->limit($limit)->start($start);
     } else {
         $query = $query->query($terms)->limit($limit)->start($start)->restrictAccess();
     }
     $query = $query->run();
     $facets = array();
     $total = 0;
     foreach ($types as $type) {
         $name = $type;
         if (strpos($type, "-") !== false) {
             $name = substr($type, 0, strpos($type, "-"));
         }
         $count = $query->getFacetCount($type);
         $total += $count;
         $name = ucfirst(\Hubzero\Utility\Inflector::pluralize($name));
         array_push($facets, array('type' => $type, 'name' => $name, 'count' => $count));
     }
     $response = new stdClass();
     $response->results = json_encode($facets);
     $response->total = $total;
     $response->success = true;
     $this->send($response);
 }
Esempio n. 2
0
 /**
  * documentByTypeTask - view a type's records
  * 
  * @access public
  * @return void
  */
 public function documentByTypeTask()
 {
     $type = Request::getVar('type', '');
     $filter = Request::getVar('filter', '');
     $limitstart = Request::getInt('limitstart', 0);
     $limit = Request::getInt('limit', 10);
     // Display CMS errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Get the blacklist to indidicate marked for removal
     $blacklistEntries = Blacklist::all()->select('doc_id')->where('doc_id', 'LIKE', $type . '%')->rows()->toObject();
     // @TODO: PHP 5.5+ supports array_column()
     $blacklist = array();
     foreach ($blacklistEntries as $entry) {
         array_push($blacklist, $entry->doc_id);
     }
     // Temporary override to get all matching documents
     if ($filter == '') {
         $filter = '*:*';
     }
     // Instantitate and get all results for a particular document type
     try {
         $config = Component::params('com_search');
         $query = new \Hubzero\Search\Query($config);
         $results = $query->query($filter)->addFilter('hubtype', array('hubtype', '=', $type))->limit($limit)->start($limitstart)->run()->getResults();
         // Get the total number of records
         $total = $query->getNumFound();
     } catch (\Solarium\Exception\HttpException $e) {
         App::redirect(Route::url('index.php?option=com_search&task=display', false));
     }
     // Pass the type the view
     $this->view->type = $type;
     // Create the pagination
     $pagination = new \Hubzero\Pagination\Paginator($total, $limitstart, $limit);
     $pagination->setLimits(array('5', '10', '15', '20', '50', '100', '200'));
     $this->view->pagination = $pagination;
     // Pass the filters and documents to the display
     $this->view->filter = !isset($filter) || ($filter = '*:*' ? '' : $filter);
     $this->view->documents = isset($results) ? $results : array();
     $this->view->blacklist = $blacklist;
     // Display the view
     $this->view->display();
 }