src/Controller/Website/ApiSearchController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Website;
  3. use App\Service\MyWebsiteSearchService;
  4. use App\Service\ApiSearchService;
  5. use Sulu\Bundle\SearchBundle\Controller\WebsiteSearchController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Twig\Environment;
  9. class ApiSearchController extends WebsiteSearchController
  10. {
  11.     private $twig;
  12.     private $searchService;
  13.     private $apiSearchService;
  14.     public function __construct(Environment $twigMyWebsiteSearchService $searchServiceApiSearchService $apiSearchService)
  15.     {
  16.         $this->twig $twig;
  17.         $this->searchService $searchService;
  18.         $this->apiSearchService $apiSearchService;
  19.     }
  20.     /**
  21.      *  
  22.      * @return Response
  23.      */
  24.     public function queryAction(Request $request): Response
  25.     {
  26.         $query $this->getRequestParameter($request'q'false'');
  27.         $elems $this->getRequestParameter($request'elems'false'');
  28.         $page $this->getRequestParameter($request'page'false'');
  29.         $start $this->getRequestParameter($request'start'false'');
  30.         $end $this->getRequestParameter($request'end'false'');
  31.         $thematiques $this->getRequestParameter($request'theme'false'');
  32.         $structure $this->getRequestParameter($request'structure'false'');
  33.         // type agenda
  34.         $format $this->getRequestParameter($request'format'false'');
  35.         $orga $this->getRequestParameter($request'organisateur'false'');
  36.         $departement $this->getRequestParameter($request'departement'false'');
  37.         $newsletter_type $this->getRequestParameter($request'newsletter_type'false'');
  38.         $offer_type $this->getRequestParameter($request'offer_type'false'');
  39.         // type d'appel pour aap/ami appel à projet / appel à manifestation d'intérêt
  40.         $type_appel $this->getRequestParameter($request'type_appel'false'');
  41.         $type_territoire $this->getRequestParameter($request'type_territoire'false'');
  42.         $hits $this->searchService->searchWithFilters($query$thematiques$start$end$structure, ['article_published'], $elems$page$format$orga$departement$newsletter_type$offer_type$type_appel$type_territoire);
  43.         // mon nbpages que j'envoie sur mon twig
  44.         $nbPages $this->apiSearchService->nbPages(intval($elems), $hits->getTotal());
  45.         $res = new Response($this->twig->render(
  46.             'api/api_search.html.twig',
  47.             [
  48.                 'hits' => $hits,
  49.                 'pageCount' => $nbPages,
  50.                 'currentPage' => $page,
  51.                 'structure' => $structure
  52.             ]
  53.         ));
  54.         return $res;
  55.     }
  56. }