<?php
/**
* Created by Elements.at New Media Solutions GmbH
*
*/
namespace App\Controller;
use App\Service\FacilityService;
use Pimcore\Model\DataObject\TicketMachine;
use Pimcore\Model\Exception\NotFoundException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class FacilityController extends AbstractController
{
public function overviewAction(Request $request, FacilityService $service): Response
{
$tabs = $service->getResortTabs($this->document->getEditable('resorts'));
$returnArray = [
'tabs' => $tabs,
'facilitiesCount' => $service->getFacilitiesCount(),
];
if ($request->get('ajax')) {
$template = $this->renderTemplate('facility/partials/facility-tabbing-ajax-result.html.twig', $returnArray);
return $this->json(['success' => true, 'html' => $template->getContent()]);
}
return $this->render('facility/overview.html.twig', $returnArray);
}
public function openingHoursAction(Request $request): Response
{
$pois = [];
$poiListing = new TicketMachine\Listing();
$poiListing->addConditionParam('coordinates__longitude IS NOT NULL AND coordinates__latitude IS NOT NULL');
foreach ($poiListing as $poi) {
$pois[] = [
'id' => $poi->getId(),
'lng' => $poi->getCoordinates()->getLongitude(),
'lat' => $poi->getCoordinates()->getLatitude(),
'poiStyle' => 'main',
'detailInfoBoxUrl' => $this->generateUrl('google_map_hotspot_modal', [ 'id' => $poi->getId() ]),
];
}
return $this->render('facility/opening-hours.html.twig', [ 'pois' => $pois ]);
}
public function mapAction(Request $request): Response
{
return $this->render('facility/map.html.twig');
}
/**
* @param Request $request
*
* @return Response
*
* @Route("/{_locale}/google-map-hotspot-modal?id={id}", name="google_map_hotspot_modal")
*/
public function googleMapHotspotModal(Request $request): Response
{
$poi = TicketMachine::getById($request->get('id'));
if (!$poi instanceof TicketMachine || !$poi->isPublished()) {
throw new NotFoundException();
}
$template = $this->renderTemplate('includes/overlays/google-map-hotspot-modal.html.twig', [ 'poi' => $poi ]);
return new JsonResponse([ 'success' => true, 'html' => $template->getContent() ]);
}
}