Ejemplo n.º 1
0
 /**
  * Produce an overview of all progress reports.
  *
  * @return ViewModel
  */
 public function indexAction()
 {
     /*
      * Check the access to the challenges, if not redirect to the NDA page
      */
     if (!$this->isAllowed('route/community/roadmap/challenges', 'challenges')) {
         $this->flashMessenger()->addInfoMessage(sprintf(_("txt-a-valid-nda-is-needed-to-access-the-roadmap")));
         return $this->redirect()->toRoute('program/nda/upload');
     }
     $client = $this->getSearchService()->getSolrClient('roadmap');
     $challenges = $this->getGeneralService()->findAll('challenge');
     $form = new SearchResult();
     if ($this->getRequest()->isGet()) {
         //Only produce an isValid as we don't care about the result
         if (isset($_GET['query']) && !empty($_GET['query'])) {
             $query = $_GET['query'];
         } else {
             $query = '*';
         }
         $this->getSearchService()->facetSearchProject($query);
         if (isset($_GET['facet'])) {
             foreach ($_GET['facet'] as $facetField => $values) {
                 $quotedValues = [];
                 foreach ($values as $value) {
                     $quotedValues[] = sprintf("\"%s\"", $value);
                 }
                 $this->getSearchService()->addFilterQuery($facetField, implode(" OR ", $quotedValues));
             }
         }
         $form->addSearchResults($this->getSearchService()->getFacetSet(), $this->getSearchService()->getResultSet()->getFacetSet());
         $form->setData($_GET);
     }
     $paginator = new Paginator(new SolariumPaginator($client, $this->getSearchService()->getQuery()));
     $paginator->setCurrentPageNumber($this->params('page', 1));
     $paginator->setItemCountPerPage(150);
     return new ViewModel(['challenges' => $challenges, 'form' => $form, 'paginator' => $paginator]);
 }
Ejemplo n.º 2
0
 /**
  * @return ViewModel
  */
 public function searchAction()
 {
     $searchService = $this->getContactSearchService();
     $page = $this->params('page', 1);
     $form = new SearchResult();
     $data = array_merge(['query' => '*', 'facet' => []], $this->getRequest()->getQuery()->toArray());
     if ($this->getRequest()->isGet()) {
         $searchService->setSearch($data['query']);
         if (isset($data['facet'])) {
             foreach ($data['facet'] as $facetField => $values) {
                 $quotedValues = [];
                 foreach ($values as $value) {
                     $quotedValues[] = sprintf("\"%s\"", $value);
                 }
                 $searchService->addFilterQuery($facetField, implode(' ' . SolariumQuery::QUERY_OPERATOR_OR . ' ', $quotedValues));
             }
         }
         $form->addSearchResults($searchService->getQuery()->getFacetSet(), $searchService->getResultSet()->getFacetSet());
         $form->setData($data);
     }
     $paginator = new Paginator(new SolariumPaginator($searchService->getSolrClient(), $searchService->getQuery()));
     $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 16);
     $paginator->setCurrentPageNumber($page);
     $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage()));
     return new ViewModel(['form' => $form, 'paginator' => $paginator, 'queryParams' => http_build_query($data), 'routeName' => $this->getEvent()->getRouteMatch()->getMatchedRouteName(), 'params' => $this->getEvent()->getRouteMatch()->getParams(), 'currentPage' => $page, 'lastPage' => $paginator->getPageRange(), 'showAlwaysFirstAndLast' => true]);
 }