<?php
namespace App\Controller;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Model\DataObject\DemiAccommodationServiceProvider;
use Pimcore\Model\DataObject\DemiInfrastructure;
use Pimcore\Model\DataObject\DemiRegion;
use Pimcore\Model\DataObject\DemiTown;
use Pimcore\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
use Pimcore\Model\DataObject\AccessibilityCategory;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class ContentController extends AbstractController
{
public function portalAction(Request $request)
{
return $this->renderTemplate('Content/portal.html.twig');
}
public function contentAction(Request $request)
{
return $this->renderTemplate('Content/content.html.twig');
}
public function contentWithVideoHeaderAction(Request $request)
{
return $this->renderTemplate('Content/contentWithVideoHeader.html.twig');
}
public function whiteLabelAction(Request $request)
{
return $this->renderTemplate('Content/whiteLabel.html.twig');
}
public function landingPageAction(Request $request) {
return $this->renderTemplate('Content/landingPage.html.twig');
}
public function incertAction(Request $request) {
return $this->renderTemplate('Content/incert.html.twig');
}
public function gletscherWeinAction(Request $request) {
return $this->renderTemplate('Content/gletscherWein.html.twig');
}
public function barrierFreeOverviewAccoAction(Request $request, PaginatorInterface $paginator) {
$accessibilityCategories = new AccessibilityCategory\Listing();
$accessibilityCategories->setOrderKey('title');
$accessibilityAccommodation = new DemiAccommodationServiceProvider\Listing();
$accessibilityAccommodation->addObjectbrick('demiAccessibilityCategories');
$classId = $accessibilityAccommodation->getClassId();
$accessibilityAccommodation->addConditionParam("object_localized_{$classId}_{$request->getLocale()}.o_id IN (SELECT object_metadata_$classId.o_id FROM object_metadata_$classId WHERE object_metadata_$classId.fieldname = 'accessibilityCategories' AND object_metadata_$classId.column = 'percent' AND object_metadata_$classId.data >= 80)");
if($demiRegion = DemiRegion::getById($this->getDocumentEditable('relation', 'regionFilter')->getData()['id'])) {
$townIds = $this->getTownsByRegion($demiRegion);
if(!empty($townIds)) {
$accessibilityAccommodation->addConditionParam('town__id IN (' . implode(',', $townIds) . ')');
}
}
if (!empty($request->get('accessibility', []))) {
$validAccessibilityIds = [];
foreach($request->get('accessibility', []) as $accessibilityId) {
if(intval($accessibilityId)) {
$validAccessibilityIds[] = intval($accessibilityId);
}
}
if(!empty($validAccessibilityIds)) {
$validAccessibilityIds = implode(',', $validAccessibilityIds);
$accessibilityAccommodation->addConditionParam("object_localized_{$classId}_{$request->getLocale()}.o_id IN (SELECT object_metadata_$classId.o_id FROM object_metadata_$classId WHERE object_metadata_$classId.fieldname = 'accessibilityCategories' AND object_metadata_$classId.column = 'percent' AND object_metadata_$classId.data >= 80 AND dest_id IN ($validAccessibilityIds))");
}
}
$accessibilityAccommodation = $paginator->paginate($accessibilityAccommodation, $request->get('page', 1), 8);
if($request->isXmlHttpRequest()) {
return $this->json([
'content' => [
'result-main' => $this->renderView('Includes/barrier-free-list-acco.html.twig', [
'accessibilityAccommodation' => $accessibilityAccommodation
]),
],
'success' => true,
]);
}
return $this->renderTemplate('Content/barrierFreeOverviewAcco.html.twig', [
'accessibilityCategories' => $accessibilityCategories,
'accessibilityAccommodation' => $accessibilityAccommodation
]);
}
public function barrierFreeOverviewInfrastructureAction(Request $request, PaginatorInterface $paginator) {
$accessibilityCategories = new AccessibilityCategory\Listing();
$accessibilityCategories->setOrderKey('title');
$accessibilityInfrastructure = new DemiInfrastructure\Listing();
$accessibilityInfrastructure->addObjectbrick('demiAccessibilityCategories');
$classId = $accessibilityInfrastructure->getClassId();
$accessibilityInfrastructure->addConditionParam("object_localized_{$classId}_{$request->getLocale()}.o_id IN (SELECT object_metadata_$classId.o_id FROM object_metadata_$classId WHERE object_metadata_$classId.fieldname = 'accessibilityCategories' AND object_metadata_$classId.column = 'percent' AND object_metadata_$classId.data >= 80)");
if($demiRegion = DemiRegion::getById($this->getDocumentEditable('relation', 'regionFilter')->getData()['id'])) {
$townIds = $this->getTownsByRegion($demiRegion);
if(!empty($townIds)) {
$subConditions = [];
foreach ($townIds as $townId) {
$subConditions[] = '(towns LIKE ",' . $townId . ',")';
}
if(!empty($subConditions)) {
$accessibilityInfrastructure->addConditionParam(implode(' OR ', $subConditions));
}
}
}
if (!empty($request->get('accessibility', []))) {
$validAccessibilityIds = [];
foreach($request->get('accessibility', []) as $accessibilityId) {
if(intval($accessibilityId)) {
$validAccessibilityIds[] = intval($accessibilityId);
}
}
if(!empty($validAccessibilityIds)) {
$validAccessibilityIds = implode(',', $validAccessibilityIds);
$accessibilityInfrastructure->addConditionParam("object_localized_{$classId}_{$request->getLocale()}.o_id IN (SELECT object_metadata_$classId.o_id FROM object_metadata_$classId WHERE object_metadata_$classId.fieldname = 'accessibilityCategories' AND object_metadata_$classId.column = 'percent' AND object_metadata_$classId.data >= 80 AND dest_id IN ($validAccessibilityIds))");
}
}
$accessibilityInfrastructure = $paginator->paginate($accessibilityInfrastructure, $request->get('page', 1), 8);
if($request->isXmlHttpRequest()) {
return $this->json([
'content' => [
'result-main' => $this->renderView('Includes/barrier-free-list-infrastructure.html.twig', [
'accessibilityInfrastructure' => $accessibilityInfrastructure
]),
],
'success' => true,
]);
}
return $this->renderTemplate('Content/barrierFreeOverviewInfrastructure.html.twig', [
'accessibilityCategories' => $accessibilityCategories,
'accessibilityInfrastructure' => $accessibilityInfrastructure
]);
}
/**
* @param Request $request
* @return Response
* @Route ("{_locale}/accessibility-lightbox_{id}" , name="accessibility-lightbox")
*/
public function accessibilityLightboxAction(Request $request): Response
{
$id = $request->get('id');
$language = $request->get('lang') != '' ? $request->get('lang') : 'en';
$object = null;
if($id) {
$object = \Pimcore\Model\DataObject::getById($id);
}
if(!$object instanceof AccessibilityCategory) {
throw new NotFoundHttpException("the requested object doesn't exist anymore");
}
return $this->renderTemplate("Content/accessibilityLightbox.html.twig", [
'object' => $object,
'language' => $language
]);
}
/**
* @Route("/{_locale}/top_offer_teaser_slider_ajax", name="top_offer_teaser_slider_ajax", methods={"GET"})
*/
public function topOfferTeaserSliderAjaxAction(Request $request): Response {
$this->addResponseHeader('X-Robots-Tag', 'noindex,nofollow');
$ids = $request->get('ids');
if (null === $ids) {
return $this->json(['success' => false, 'message' => 'Invalid IDs format']);
}
$elements = [];
foreach ($ids as $idInfo) {
if (!isset($idInfo['type'], $idInfo['id'])) {
continue;
}
$id = $idInfo['id'];
switch ($idInfo['type']) {
case 'doc':
$element = \Pimcore\Model\Document::getById(($id));
break;
case 'obj':
$element = \Pimcore\Model\DataObject::getById(($id));
break;
default:
$element = null;
}
if (null !== $element) {
$elements[] = $element;
}
}
return $this->json([
'html' => $this->renderTemplate('areas/teaser-top-offer/Includes/topOfferTeaserSliderAjax.html.twig', [
'elements' => $elements
])->getContent(),
'success' => true,
]);
}
private function getTownsByRegion(DemiRegion $demiRegion) {
$demiTowns = new DemiTown\Listing();
$demiTowns->addConditionParam("o_path LIKE :opath", ['opath' => ($demiRegion->getFullPath() . "%")]);
return array_map(function($demiTown) {
return $demiTown->getId();
}, $demiTowns->getObjects());
}
}