src/Controller/LocationController.php line 126

Open in your IDE?
  1. <?php
  2.     namespace App\Controller;
  3.     use Devkitchen\DocumentIndexingBundle\Annotations\IndexingDocumentType;
  4.     use Devkitchen\DocumentIndexingBundle\Controller\DocumentTypeAwareController;
  5.     use Devkitchen\DocumentIndexingBundle\IndexingService\IndexingService;
  6.     use Pimcore\Model\DataObject\Location;
  7.     use Pimcore\Model\Document\Page;
  8.     use Pimcore\Model\Document\Service;
  9.     use Symfony\Component\DomCrawler\Crawler;
  10.     use Symfony\Component\HttpFoundation\Request;
  11.     use Symfony\Component\HttpFoundation\Response;
  12.     use Symfony\Component\Routing\Annotation\Route;
  13.     class LocationController extends BaseController implements DocumentTypeAwareController {
  14.         /**
  15.          * @param Request $request
  16.          *
  17.          * @return Response
  18.          */
  19.         public function listingAction(Request $request): Response {
  20.             return $this->render'location/listing.html.twig', [
  21.                 'layoutClass' => 'layout--listing layout--location'
  22.             ]);
  23.         }
  24.         /**
  25.          * @param Request $request
  26.          * @return Response
  27.          *
  28.          * @IndexingDocumentType(type="location", tagIdForSubtype="12")
  29.          */
  30.         public function detailAction(Request $request): Response {
  31.             return $this->render('location/detail.html.twig', [
  32.                 'layoutClass' => 'layout--detail layout--location'
  33.             ]);
  34.         }
  35.         /**
  36.          * @param Request $request
  37.          * @return Response
  38.          *
  39.          * @IndexingDocumentType(type="location", subtype="restaurant")
  40.          */
  41.         public function detailRestaurantAction(Request $requestIndexingService $indexingService):Response {
  42.             //$indexedDocument = $indexingService->get( $this->document );
  43.             //p_r($indexedDocument);
  44.             $addressBlock null;
  45.             $contactBlock null;
  46.             $locationObjectEditable $this->document->getEditable'location');
  47.             if ($locationObjectEditable && !$locationObjectEditable->isEmpty()) {
  48.                 $locationData $locationObjectEditable->getData();
  49.                 $location Location::getById$locationData['id'] );
  50.                 $language $this->document->getProperty'language');
  51.                 $addressBlock['title'] = $location->getTitle($language);
  52.                 $addressBlock['street'] = $location->getStreet($language);
  53.                 $addressBlock['zipCity'] = $location->getZip($language).' '.$location->getCity($language);
  54.                 $contactBlock['phone'] = $location->getTelephone();
  55.                 $contactBlock['phoneRaw'] = preg_replace('/\D/'''$location->getTelephone());
  56.                 $contactBlock['fax'] = $location->getFax();
  57.                 $contactBlock['mail'] = $location->getEmail();
  58.                 $contactBlock['web'] = $location->getWebsite();
  59.             }
  60.             return $this->render('location/detail-restaurant.html.twig', [
  61.                 'layoutClass' => 'layout--detail layout--location',
  62.                 'address' => $addressBlock ?? null,
  63.                 'contact' => $contactBlock ?? null
  64.             ]);
  65.         }
  66.         /**
  67.          * @param Request $request
  68.          * @return Response
  69.          *
  70.          * @IndexingDocumentType(type="location", subtype="member")
  71.          */
  72.         public function detailMemberAction(Request $request):Response {
  73.             $addressBlock null;
  74.             $contactBlock null;
  75.             $locationObjectEditable $this->document->getEditable'location');
  76.             if ($locationObjectEditable && !$locationObjectEditable->isEmpty()) {
  77.                 $locationData $locationObjectEditable->getData();
  78.                 $location Location::getById$locationData['id'] );
  79.                 $language $this->document->getProperty'language');
  80.                 $addressBlock['title'] = $location->getTitle($language);
  81.                 $addressBlock['street'] = $location->getStreet($language);
  82.                 $addressBlock['zipCity'] = $location->getZip($language).' '.$location->getCity($language);
  83.                 $contactBlock['phone'] = $location->getTelephone();
  84.                 $contactBlock['phoneRaw'] = preg_replace('/\D/'''$location->getTelephone());
  85.                 $contactBlock['fax'] = $location->getFax();
  86.                 $contactBlock['mail'] = $location->getEmail();
  87.                 $contactBlock['web'] = $location->getWebsite();
  88.             }
  89.             return $this->render('location/detail-member.html.twig', [
  90.                 'layoutClass' => 'layout--detail layout--location',
  91.                 'address' => $addressBlock ?? null,
  92.                 'contact' => $contactBlock ?? null
  93.             ]);
  94.         }
  95.         /**
  96.          * @param Request $request
  97.          * @return Response
  98.          *
  99.          * @IndexingDocumentType(type="location", subtype="butcher")
  100.          */
  101.         public function detailButcherAction(Request $request):Response {
  102.             $addressBlock null;
  103.             $contactBlock null;
  104.             $locationObjectEditable $this->document->getEditable'location');
  105.             if ($locationObjectEditable && !$locationObjectEditable->isEmpty()) {
  106.                 $locationData $locationObjectEditable->getData();
  107.                 $location Location::getById$locationData['id'] );
  108.                 $language $this->document->getProperty'language');
  109.                 $addressBlock['title'] = $location->getTitle($language);
  110.                 $addressBlock['street'] = $location->getStreet($language);
  111.                 $addressBlock['zipCity'] = $location->getZip($language).' '.$location->getCity($language);
  112.                 $contactBlock['phone'] = $location->getTelephone();
  113.                 $contactBlock['phoneRaw'] = preg_replace('/\D/'''$location->getTelephone());
  114.                 $contactBlock['fax'] = $location->getFax();
  115.                 $contactBlock['mail'] = $location->getEmail();
  116.                 $contactBlock['web'] = $location->getWebsite();
  117.             }
  118.             return $this->render('location/detail-butcher.html.twig', [
  119.                 'layoutClass' => 'layout--detail layout--location',
  120.                 'address' => $addressBlock ?? null,
  121.                 'contact' => $contactBlock ?? null
  122.             ]);
  123.         }
  124.         /**
  125.          * @Route("/pdf")
  126.          * @param Request $request
  127.          *
  128.          * @return void
  129.          */
  130.         public function printAction(Request $request) {
  131.             $html Service::renderPage::getById35 ));
  132.             $crawler = new Crawler();
  133.             $crawler->add($html);
  134.             $htmlFiltered $crawler->filter'.section--printable' )->each( function ( Crawler $node$i ) {
  135.                 return $node->html();
  136.             });
  137.             $params = [];
  138.             $adapter \Pimcore\Web2Print\Processor::getInstance();
  139.             if ($adapter instanceof \Pimcore\Web2Print\Processor\HeadlessChrome) {
  140.                 $params['adapterConfig'] = [
  141.                     'landscape' => false,
  142.                     'printBackground' => false,
  143.                     'mediaType' => 'print',
  144.                     'format' => null,
  145.                     'margin' => [
  146.                         'top' => '16 mm',
  147.                         'bottom' => '30 mm',
  148.                         'right' => '8 mm',
  149.                         'left' => '8 mm',
  150.                     ],
  151.                     'displayHeaderFooter' => false,
  152.                 ];
  153.             }
  154.             return new \Symfony\Component\HttpFoundation\Response(
  155.                 $adapter->getPdfFromString($html$params),
  156.                 200,
  157.                 [
  158.                     'Content-Type' => 'application/pdf',
  159.                     // 'Content-Disposition'   => 'attachment; filename="custom-pdf.pdf"' //direct download
  160.                 ]
  161.             );
  162.         }
  163.     }