src/Controller/ContentController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Pimcore\Model\DataObject\DemiAccommodationServiceProvider;
  5. use Pimcore\Model\DataObject\DemiInfrastructure;
  6. use Pimcore\Model\DataObject\DemiRegion;
  7. use Pimcore\Model\DataObject\DemiTown;
  8. use Pimcore\Translation\Translator;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Pimcore\Model\DataObject\AccessibilityCategory;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class ContentController extends AbstractController
  15. {
  16.     public function portalAction(Request $request)
  17.     {
  18.         return $this->renderTemplate('Content/portal.html.twig');
  19.     }
  20.     public function contentAction(Request $request)
  21.     {
  22.         return $this->renderTemplate('Content/content.html.twig');
  23.     }
  24.     public function contentWithVideoHeaderAction(Request $request)
  25.     {
  26.         return $this->renderTemplate('Content/contentWithVideoHeader.html.twig');
  27.     }
  28.     public function whiteLabelAction(Request $request)
  29.     {
  30.         return $this->renderTemplate('Content/whiteLabel.html.twig');
  31.     }
  32.     public function landingPageAction(Request $request) {
  33.         return $this->renderTemplate('Content/landingPage.html.twig');
  34.     }
  35.     public function incertAction(Request $request) {
  36.         return $this->renderTemplate('Content/incert.html.twig');
  37.     }
  38.     public function gletscherWeinAction(Request $request) {
  39.         return $this->renderTemplate('Content/gletscherWein.html.twig');
  40.     }
  41.     public function barrierFreeOverviewAccoAction(Request $requestPaginatorInterface $paginator) {
  42.         $accessibilityCategories = new AccessibilityCategory\Listing();
  43.         $accessibilityCategories->setOrderKey('title');
  44.         $accessibilityAccommodation = new DemiAccommodationServiceProvider\Listing();
  45.         $accessibilityAccommodation->addObjectbrick('demiAccessibilityCategories');
  46.         $classId $accessibilityAccommodation->getClassId();
  47.         $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)");
  48.         if($demiRegion DemiRegion::getById($this->getDocumentEditable('relation''regionFilter')->getData()['id'])) {
  49.             $townIds $this->getTownsByRegion($demiRegion);
  50.             if(!empty($townIds)) {
  51.                 $accessibilityAccommodation->addConditionParam('town__id IN (' implode(','$townIds) . ')');
  52.             }
  53.         }
  54.         if (!empty($request->get('accessibility', []))) {
  55.             $validAccessibilityIds = [];
  56.             foreach($request->get('accessibility', []) as $accessibilityId) {
  57.                 if(intval($accessibilityId)) {
  58.                     $validAccessibilityIds[] = intval($accessibilityId);
  59.                 }
  60.             }
  61.             if(!empty($validAccessibilityIds)) {
  62.                 $validAccessibilityIds implode(','$validAccessibilityIds);
  63.                 $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))");
  64.             }
  65.         }
  66.         $accessibilityAccommodation $paginator->paginate($accessibilityAccommodation$request->get('page'1), 8);
  67.         if($request->isXmlHttpRequest()) {
  68.             return $this->json([
  69.                 'content' => [
  70.                     'result-main' => $this->renderView('Includes/barrier-free-list-acco.html.twig', [
  71.                         'accessibilityAccommodation' => $accessibilityAccommodation
  72.                     ]),
  73.                 ],
  74.                 'success' => true,
  75.             ]);
  76.         }
  77.         return $this->renderTemplate('Content/barrierFreeOverviewAcco.html.twig', [
  78.             'accessibilityCategories' => $accessibilityCategories,
  79.             'accessibilityAccommodation' => $accessibilityAccommodation
  80.         ]);
  81.     }
  82.     public function barrierFreeOverviewInfrastructureAction(Request $requestPaginatorInterface $paginator) {
  83.         $accessibilityCategories = new AccessibilityCategory\Listing();
  84.         $accessibilityCategories->setOrderKey('title');
  85.         $accessibilityInfrastructure = new DemiInfrastructure\Listing();
  86.         $accessibilityInfrastructure->addObjectbrick('demiAccessibilityCategories');
  87.         $classId $accessibilityInfrastructure->getClassId();
  88.         $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)");
  89.         if($demiRegion DemiRegion::getById($this->getDocumentEditable('relation''regionFilter')->getData()['id'])) {
  90.             $townIds $this->getTownsByRegion($demiRegion);
  91.             if(!empty($townIds)) {
  92.                 $subConditions = [];
  93.                 foreach ($townIds as $townId) {
  94.                     $subConditions[] = '(towns LIKE ",' $townId ',")';
  95.                 }
  96.                 if(!empty($subConditions)) {
  97.                     $accessibilityInfrastructure->addConditionParam(implode(' OR '$subConditions));
  98.                 }
  99.             }
  100.         }
  101.         if (!empty($request->get('accessibility', []))) {
  102.             $validAccessibilityIds = [];
  103.             foreach($request->get('accessibility', []) as $accessibilityId) {
  104.                 if(intval($accessibilityId)) {
  105.                     $validAccessibilityIds[] = intval($accessibilityId);
  106.                 }
  107.             }
  108.             if(!empty($validAccessibilityIds)) {
  109.                 $validAccessibilityIds implode(','$validAccessibilityIds);
  110.                 $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))");
  111.             }
  112.         }
  113.         $accessibilityInfrastructure $paginator->paginate($accessibilityInfrastructure$request->get('page'1), 8);
  114.         if($request->isXmlHttpRequest()) {
  115.             return $this->json([
  116.                 'content' => [
  117.                     'result-main' => $this->renderView('Includes/barrier-free-list-infrastructure.html.twig', [
  118.                         'accessibilityInfrastructure' => $accessibilityInfrastructure
  119.                     ]),
  120.                 ],
  121.                 'success' => true,
  122.             ]);
  123.         }
  124.         return $this->renderTemplate('Content/barrierFreeOverviewInfrastructure.html.twig', [
  125.             'accessibilityCategories' => $accessibilityCategories,
  126.             'accessibilityInfrastructure' => $accessibilityInfrastructure
  127.         ]);
  128.     }
  129.     /**
  130.      * @param Request $request
  131.      * @return Response
  132.      * @Route ("{_locale}/accessibility-lightbox_{id}" , name="accessibility-lightbox")
  133.      */
  134.     public function accessibilityLightboxAction(Request $request): Response
  135.     {
  136.         $id $request->get('id');
  137.         $language $request->get('lang') != '' $request->get('lang') : 'en';
  138.         $object null;
  139.         if($id) {
  140.             $object \Pimcore\Model\DataObject::getById($id);
  141.         }
  142.         if(!$object instanceof AccessibilityCategory) {
  143.             throw new NotFoundHttpException("the requested object doesn't exist anymore");
  144.         }
  145.         return $this->renderTemplate("Content/accessibilityLightbox.html.twig", [
  146.             'object' => $object,
  147.             'language' => $language
  148.         ]);
  149.     }
  150.     /**
  151.      * @Route("/{_locale}/top_offer_teaser_slider_ajax", name="top_offer_teaser_slider_ajax", methods={"GET"})
  152.      */
  153.     public function topOfferTeaserSliderAjaxAction(Request $request): Response {
  154.         $this->addResponseHeader('X-Robots-Tag''noindex,nofollow');
  155.         $ids $request->get('ids');
  156.         if (null === $ids) {
  157.             return $this->json(['success' => false'message' => 'Invalid IDs format']);
  158.         }
  159.         $elements = [];
  160.         foreach ($ids as $idInfo) {
  161.             if (!isset($idInfo['type'], $idInfo['id'])) {
  162.                 continue;
  163.             }
  164.             $id $idInfo['id'];
  165.             switch ($idInfo['type']) {
  166.                 case 'doc':
  167.                     $element \Pimcore\Model\Document::getById(($id));
  168.                     break;
  169.                 case 'obj':
  170.                     $element \Pimcore\Model\DataObject::getById(($id));
  171.                     break;
  172.                 default:
  173.                     $element null;
  174.             }
  175.             if (null !== $element) {
  176.                 $elements[] = $element;
  177.             }
  178.         }
  179.         return $this->json([
  180.             'html' => $this->renderTemplate('areas/teaser-top-offer/Includes/topOfferTeaserSliderAjax.html.twig', [
  181.                 'elements' => $elements
  182.             ])->getContent(),
  183.             'success' => true,
  184.         ]);
  185.     }
  186.     private function getTownsByRegion(DemiRegion $demiRegion) {
  187.         $demiTowns = new DemiTown\Listing();
  188.         $demiTowns->addConditionParam("o_path LIKE :opath", ['opath' => ($demiRegion->getFullPath() . "%")]);
  189.         return array_map(function($demiTown) {
  190.             return $demiTown->getId();
  191.         }, $demiTowns->getObjects());
  192.     }
  193. }