<?php
namespace App\Controller\Website;
use App\Service\MyWebsiteSearchService;
use App\Service\ApiSearchService;
use Sulu\Bundle\SearchBundle\Controller\WebsiteSearchController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
class ApiSearchController extends WebsiteSearchController
{
private $twig;
private $searchService;
private $apiSearchService;
public function __construct(Environment $twig, MyWebsiteSearchService $searchService, ApiSearchService $apiSearchService)
{
$this->twig = $twig;
$this->searchService = $searchService;
$this->apiSearchService = $apiSearchService;
}
/**
*
* @return Response
*/
public function queryAction(Request $request): Response
{
$query = $this->getRequestParameter($request, 'q', false, '');
$elems = $this->getRequestParameter($request, 'elems', false, '');
$page = $this->getRequestParameter($request, 'page', false, '');
$start = $this->getRequestParameter($request, 'start', false, '');
$end = $this->getRequestParameter($request, 'end', false, '');
$thematiques = $this->getRequestParameter($request, 'theme', false, '');
$structure = $this->getRequestParameter($request, 'structure', false, '');
// type agenda
$format = $this->getRequestParameter($request, 'format', false, '');
$orga = $this->getRequestParameter($request, 'organisateur', false, '');
$departement = $this->getRequestParameter($request, 'departement', false, '');
$newsletter_type = $this->getRequestParameter($request, 'newsletter_type', false, '');
$offer_type = $this->getRequestParameter($request, 'offer_type', false, '');
// type d'appel pour aap/ami appel à projet / appel à manifestation d'intérêt
$type_appel = $this->getRequestParameter($request, 'type_appel', false, '');
$type_territoire = $this->getRequestParameter($request, 'type_territoire', false, '');
$hits = $this->searchService->searchWithFilters($query, $thematiques, $start, $end, $structure, ['article_published'], $elems, $page, $format, $orga, $departement, $newsletter_type, $offer_type, $type_appel, $type_territoire);
// mon nbpages que j'envoie sur mon twig
$nbPages = $this->apiSearchService->nbPages(intval($elems), $hits->getTotal());
$res = new Response($this->twig->render(
'api/api_search.html.twig',
[
'hits' => $hits,
'pageCount' => $nbPages,
'currentPage' => $page,
'structure' => $structure
]
));
return $res;
}
}