src/Elements/Bundle/DemiFrontendBundle/Controller/MapController.php line 57

Open in your IDE?
  1. <?php
  2. /**
  3.  * Elements DeMI
  4.  *
  5.  * This source file is available under the elements DeMI license version 1
  6.  *
  7.  *  @copyright  Copyright (c) elements.at New Media Solutions GmbH (https://www.elements.at/)
  8.  *  @license    elements DeMI Lizenz Version 1 (https://www.elements.at/de/demi-lizenz)
  9.  */
  10. namespace Elements\Bundle\DemiFrontendBundle\Controller;
  11. use Elements\Demi\Frontend\Service\EventSearchFrontend;
  12. use Elements\Bundle\DemiFrontendBundle\Service\SearchFrontend;
  13. use Elements\Bundle\SeoHelperBundle\Templating\Helper\Robots;
  14. use Elements\Demi\Accommodation\Search\Listing;
  15. use Elements\Demi\Accommodation\Search\Listing\VacancyLocal;
  16. use Elements\Demi\Accommodation\Search\Parameter;
  17. use Elements\Demi\Model\Package;
  18. use Pimcore\Http\Request\Resolver\DocumentResolver;
  19. use Pimcore\Tool\DeviceDetector;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  23. class MapController extends AbstractDemiController
  24. {
  25.     public function __construct(protected Robots       $robots, protected DocumentResolver $documentResolver, protected SearchFrontend $searchFrontend,
  26.                                 protected VacancyLocal $corridor, protected VacancyLocal $vacancyLocal, protected EventSearchFrontend $eventSearchFrontend)
  27.     {
  28.     }
  29.     public function mapAction(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  30.     {
  31.         $this->robots->setNoIndex();
  32.         $this->robots->setNoFollow();
  33.         $viewParams["language"] = $request->getLocale();
  34.         $package $this->getDocumentEditable('relation','package')?->getElement();
  35.         if ($package instanceof Package) {
  36.             $viewParams["tvbPackage"] = $package;
  37.         } else {
  38.             $viewParams["tvbPackge"] = null;
  39.         }
  40.         $deviceDetector DeviceDetector::getInstance();
  41.         if (!$deviceDetector->isPhone()) {
  42.             $correctUrl $this->document->getFullPath().'?'.$request->getQueryString();
  43.             return $this->redirect($correctUrl);
  44.         }
  45.         return $this->renderTemplate("@ElementsDemiFrontend/Map/map.html.twig"$viewParams);
  46.     }
  47.     public function mapPoiJsonAction(Request $request): JsonResponse
  48.     {
  49.         $this->addResponseHeader('X-Robots-Tag''noindex,follow');
  50.         $searchParams $this->searchFrontend->getSearchParam(nullfalse,  true);
  51.         if ($searchParams->getDateFrom() && empty($searchParams->getRoomrows())) {
  52.             //faulty search parameters
  53.             throw new NotFoundHttpException('Faulty Search Params! Roomrows are missing');
  54.         }
  55.         if ($searchParams->getIsCorridor()) {
  56.             $search $this->corridor;
  57.         } else {
  58.             $search $this->vacancyLocal;
  59.         }
  60.         if ($searchParams->getSearchType() == Parameter::SEARCH_TYPE_ONE_PRODUCT_PER_PACKAGE) {
  61.             $search->setReturnType(Listing::RETURNTYPE_PACKAGES);
  62.         }
  63.         $searchParams->setExtendedResultset(true);
  64.         $search->setParameter($searchParams);
  65.         $jsonArray = [];
  66.         foreach ($search->getResultSet()?->getAccommodations() as $item) {
  67.             if (!empty($item->getLatitude()) && !empty($item->getLongitude())) {
  68.                 $jsonArray[] = [
  69.                     'lat' => $item->getLatitude(),
  70.                     'lng' => $item->getLongitude(),
  71.                     'id' => $item->getAccommodationId()
  72.                 ];
  73.             }
  74.         }
  75.         return $this->json($jsonArray);
  76.     }
  77. }