<?php
namespace App\Controller;
use Devkitchen\DocumentIndexingBundle\Annotations\IndexingDocumentType;
use Devkitchen\DocumentIndexingBundle\Controller\DocumentTypeAwareController;
use Devkitchen\DocumentIndexingBundle\IndexingService\IndexingService;
use Pimcore\Model\DataObject\Location;
use Pimcore\Model\Document\Page;
use Pimcore\Model\Document\Service;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class LocationController extends BaseController implements DocumentTypeAwareController {
/**
* @param Request $request
*
* @return Response
*/
public function listingAction(Request $request): Response {
return $this->render( 'location/listing.html.twig', [
'layoutClass' => 'layout--listing layout--location'
]);
}
/**
* @param Request $request
* @return Response
*
* @IndexingDocumentType(type="location", tagIdForSubtype="12")
*/
public function detailAction(Request $request): Response {
return $this->render('location/detail.html.twig', [
'layoutClass' => 'layout--detail layout--location'
]);
}
/**
* @param Request $request
* @return Response
*
* @IndexingDocumentType(type="location", subtype="restaurant")
*/
public function detailRestaurantAction(Request $request, IndexingService $indexingService):Response {
//$indexedDocument = $indexingService->get( $this->document );
//p_r($indexedDocument);
$addressBlock = null;
$contactBlock = null;
$locationObjectEditable = $this->document->getEditable( 'location');
if ($locationObjectEditable && !$locationObjectEditable->isEmpty()) {
$locationData = $locationObjectEditable->getData();
$location = Location::getById( $locationData['id'] );
$language = $this->document->getProperty( 'language');
$addressBlock['title'] = $location->getTitle($language);
$addressBlock['street'] = $location->getStreet($language);
$addressBlock['zipCity'] = $location->getZip($language).' '.$location->getCity($language);
$contactBlock['phone'] = $location->getTelephone();
$contactBlock['phoneRaw'] = preg_replace('/\D/', '', $location->getTelephone());
$contactBlock['fax'] = $location->getFax();
$contactBlock['mail'] = $location->getEmail();
$contactBlock['web'] = $location->getWebsite();
}
return $this->render('location/detail-restaurant.html.twig', [
'layoutClass' => 'layout--detail layout--location',
'address' => $addressBlock ?? null,
'contact' => $contactBlock ?? null
]);
}
/**
* @param Request $request
* @return Response
*
* @IndexingDocumentType(type="location", subtype="member")
*/
public function detailMemberAction(Request $request):Response {
$addressBlock = null;
$contactBlock = null;
$locationObjectEditable = $this->document->getEditable( 'location');
if ($locationObjectEditable && !$locationObjectEditable->isEmpty()) {
$locationData = $locationObjectEditable->getData();
$location = Location::getById( $locationData['id'] );
$language = $this->document->getProperty( 'language');
$addressBlock['title'] = $location->getTitle($language);
$addressBlock['street'] = $location->getStreet($language);
$addressBlock['zipCity'] = $location->getZip($language).' '.$location->getCity($language);
$contactBlock['phone'] = $location->getTelephone();
$contactBlock['phoneRaw'] = preg_replace('/\D/', '', $location->getTelephone());
$contactBlock['fax'] = $location->getFax();
$contactBlock['mail'] = $location->getEmail();
$contactBlock['web'] = $location->getWebsite();
}
return $this->render('location/detail-member.html.twig', [
'layoutClass' => 'layout--detail layout--location',
'address' => $addressBlock ?? null,
'contact' => $contactBlock ?? null
]);
}
/**
* @param Request $request
* @return Response
*
* @IndexingDocumentType(type="location", subtype="butcher")
*/
public function detailButcherAction(Request $request):Response {
$addressBlock = null;
$contactBlock = null;
$locationObjectEditable = $this->document->getEditable( 'location');
if ($locationObjectEditable && !$locationObjectEditable->isEmpty()) {
$locationData = $locationObjectEditable->getData();
$location = Location::getById( $locationData['id'] );
$language = $this->document->getProperty( 'language');
$addressBlock['title'] = $location->getTitle($language);
$addressBlock['street'] = $location->getStreet($language);
$addressBlock['zipCity'] = $location->getZip($language).' '.$location->getCity($language);
$contactBlock['phone'] = $location->getTelephone();
$contactBlock['phoneRaw'] = preg_replace('/\D/', '', $location->getTelephone());
$contactBlock['fax'] = $location->getFax();
$contactBlock['mail'] = $location->getEmail();
$contactBlock['web'] = $location->getWebsite();
}
return $this->render('location/detail-butcher.html.twig', [
'layoutClass' => 'layout--detail layout--location',
'address' => $addressBlock ?? null,
'contact' => $contactBlock ?? null
]);
}
/**
* @Route("/pdf")
* @param Request $request
*
* @return void
*/
public function printAction(Request $request) {
$html = Service::render( Page::getById( 35 ));
$crawler = new Crawler();
$crawler->add($html);
$htmlFiltered = $crawler->filter( '.section--printable' )->each( function ( Crawler $node, $i ) {
return $node->html();
});
$params = [];
$adapter = \Pimcore\Web2Print\Processor::getInstance();
if ($adapter instanceof \Pimcore\Web2Print\Processor\HeadlessChrome) {
$params['adapterConfig'] = [
'landscape' => false,
'printBackground' => false,
'mediaType' => 'print',
'format' => null,
'margin' => [
'top' => '16 mm',
'bottom' => '30 mm',
'right' => '8 mm',
'left' => '8 mm',
],
'displayHeaderFooter' => false,
];
}
return new \Symfony\Component\HttpFoundation\Response(
$adapter->getPdfFromString($html, $params),
200,
[
'Content-Type' => 'application/pdf',
// 'Content-Disposition' => 'attachment; filename="custom-pdf.pdf"' //direct download
]
);
}
}