vendor/numero2/contao-storelocator/src/Resources/contao/modules/ModuleStoreLocatorDetails.php line 61

Open in your IDE?
  1. <?php
  2. /**
  3.  * StoreLocator Bundle for Contao Open Source CMS
  4.  *
  5.  * @author    Benny Born <benny.born@numero2.de>
  6.  * @author    Michael Bösherz <michael.boesherz@numero2.de>
  7.  * @license   LGPL-3.0-or-later
  8.  * @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR
  9.  */
  10. namespace numero2\StoreLocator;
  11. use Contao\BackendTemplate;
  12. use Contao\Config;
  13. use Contao\CoreBundle\Exception\PageNotFoundException;
  14. use Contao\FilesModel;
  15. use Contao\Input;
  16. use Contao\Module;
  17. use Contao\System;
  18. use stdClass;
  19. class ModuleStoreLocatorDetails extends Module {
  20.     /**
  21.      * Template
  22.      * @var string
  23.      */
  24.     protected $strTemplate 'mod_storelocator_details';
  25.     /**
  26.      * Display a wildcard in the back end
  27.      *
  28.      * @return string
  29.      */
  30.     public function generate(): string {
  31.         $scopeMatcher System::getContainer()->get('contao.routing.scope_matcher');
  32.         $requestStack System::getContainer()->get('request_stack');
  33.         if( $scopeMatcher->isBackendRequest($requestStack->getCurrentRequest()) ) {
  34.             $objTemplate = new BackendTemplate('be_wildcard');
  35.             $objTemplate->wildcard '### '.$GLOBALS['TL_LANG']['FMD']['storelocator_details'][0].' ###';
  36.             $objTemplate->title $this->headline;
  37.             $objTemplate->id $this->id;
  38.             $objTemplate->link $this->name;
  39.             $objTemplate->href System::getContainer()->get('router')->generate(
  40.                 'contao_backend',
  41.                 ['do' => 'themes''table' => 'tl_module''act' => 'edit''id' => $this->id],
  42.             );
  43.             return $objTemplate->parse();
  44.         }
  45.         return parent::generate();
  46.     }
  47.     /**
  48.      * Generate module
  49.      */
  50.     protected function compile(): void {
  51.         global $objPage;
  52.         $this->Template->referer 'javascript:history.go(-1)';
  53.         $this->Template->back $GLOBALS['TL_LANG']['MSC']['goBack'];
  54.         if( !isset($_GET['store']) && Config::get('useAutoItem') && isset($_GET['auto_item']) ) {
  55.             Input::setGet('store'Input::get('auto_item'));
  56.         }
  57.         $alias Input::get('store') ? Input::get('store') : null;
  58.         $objStore null;
  59.         $objStore StoresModel::findByIdOrAlias($alias);
  60.         if( !$objStore || !$objStore->published ) {
  61.             throw new PageNotFoundException('store not found');
  62.         }
  63.         // change page title
  64.         $objPage->pageTitle $objStore->name;
  65.         // get image
  66.         if( $objStore->singleSRC ) {
  67.             $objFile null;
  68.             $objFile FilesModel::findByUuid($objStore->singleSRC);
  69.             $objStore->image $objFile;
  70.         }
  71.         $this->Template->labelPhone $GLOBALS['TL_LANG']['tl_storelocator']['field']['phone'];
  72.         $this->Template->labelFax $GLOBALS['TL_LANG']['tl_storelocator']['field']['fax'];
  73.         $this->Template->labelEMail $GLOBALS['TL_LANG']['tl_storelocator']['field']['email'];
  74.         $this->Template->labelWWW $GLOBALS['TL_LANG']['tl_storelocator']['field']['www'];
  75.         $this->Template->maps_provider $this->storelocator_provider;
  76.         if( $this->storelocator_provider == 'google-maps' ) {
  77.             $this->Template->mapsURI sprintf(
  78.                 "https://www.google.com/maps/embed/v1/place?q=%s&key=%s"
  79.                 ,   rawurlencode($objStore->name.', '.$objStore->street.', '.$objStore->postal.' '.$objStore->city)
  80.                 ,   Config::get('google_maps_browser_key')
  81.             );
  82.         }
  83.         if( $objStore->image ) {
  84.             $temp = new stdClass();
  85.             // Contao >= 4.9
  86.             if( method_exists($this'addImageToTemplate') ) {
  87.                 $this->addImageToTemplate($this->Template, [
  88.                     'singleSRC' => $objStore->image->path
  89.                 ,   'size' => $this->imgSize
  90.                 ], nullnull$objFile);
  91.             // Contao 5
  92.             } else {
  93.                 $figureBuilder System::getContainer()
  94.                     ->get('contao.image.studio')
  95.                     ->createFigureBuilder()
  96.                     ->from($objStore->image->path)
  97.                     ->setSize($this->imgSize);
  98.                 if( null !== ($figure $figureBuilder->buildIfResourceExists()) ) {
  99.                     $figure->applyLegacyTemplateData($this->Template);
  100.                 }
  101.             }
  102.         }
  103.         StoreLocator::parseStoreData($objStore$this);
  104.         $this->Template->store $objStore;
  105.     }
  106. }