<?php
/**
* Elements DeMI
*
* This source file is available under the elements DeMI license version 1
*
* @copyright Copyright (c) elements.at New Media Solutions GmbH (https://www.elements.at/)
* @license elements DeMI Lizenz Version 1 (https://www.elements.at/de/demi-lizenz)
*/
namespace Elements\Bundle\DemiFrontendBundle\Controller;
use Elements\Demi\Frontend\Service\EventSearchFrontend;
use Elements\Bundle\DemiFrontendBundle\Service\SearchFrontend;
use Elements\Bundle\SeoHelperBundle\Templating\Helper\Robots;
use Elements\Demi\Accommodation\Search\Listing;
use Elements\Demi\Accommodation\Search\Listing\VacancyLocal;
use Elements\Demi\Accommodation\Search\Parameter;
use Elements\Demi\Model\Package;
use Pimcore\Http\Request\Resolver\DocumentResolver;
use Pimcore\Tool\DeviceDetector;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class MapController extends AbstractDemiController
{
public function __construct(protected Robots $robots, protected DocumentResolver $documentResolver, protected SearchFrontend $searchFrontend,
protected VacancyLocal $corridor, protected VacancyLocal $vacancyLocal, protected EventSearchFrontend $eventSearchFrontend)
{
}
public function mapAction(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
{
$this->robots->setNoIndex();
$this->robots->setNoFollow();
$viewParams["language"] = $request->getLocale();
$package = $this->getDocumentEditable('relation','package')?->getElement();
if ($package instanceof Package) {
$viewParams["tvbPackage"] = $package;
} else {
$viewParams["tvbPackge"] = null;
}
$deviceDetector = DeviceDetector::getInstance();
if (!$deviceDetector->isPhone()) {
$correctUrl = $this->document->getFullPath().'?'.$request->getQueryString();
return $this->redirect($correctUrl);
}
return $this->renderTemplate("@ElementsDemiFrontend/Map/map.html.twig", $viewParams);
}
public function mapPoiJsonAction(Request $request): JsonResponse
{
$this->addResponseHeader('X-Robots-Tag', 'noindex,follow');
$searchParams = $this->searchFrontend->getSearchParam(null, false, true);
if ($searchParams->getDateFrom() && empty($searchParams->getRoomrows())) {
//faulty search parameters
throw new NotFoundHttpException('Faulty Search Params! Roomrows are missing');
}
if ($searchParams->getIsCorridor()) {
$search = $this->corridor;
} else {
$search = $this->vacancyLocal;
}
if ($searchParams->getSearchType() == Parameter::SEARCH_TYPE_ONE_PRODUCT_PER_PACKAGE) {
$search->setReturnType(Listing::RETURNTYPE_PACKAGES);
}
$searchParams->setExtendedResultset(true);
$search->setParameter($searchParams);
$jsonArray = [];
foreach ($search->getResultSet()?->getAccommodations() as $item) {
if (!empty($item->getLatitude()) && !empty($item->getLongitude())) {
$jsonArray[] = [
'lat' => $item->getLatitude(),
'lng' => $item->getLongitude(),
'id' => $item->getAccommodationId()
];
}
}
return $this->json($jsonArray);
}
}