vendor/pdir/panorama-bundle/src/Controller/ContentElement/KrPanoramaExtController.php line 43

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Contao Panorama bundle for Contao Open Source CMS
  5.  *
  6.  * Copyright (c) 2022 pdir / digital agentur // pdir GmbH
  7.  *
  8.  * @package    panorama-bundle
  9.  * @link       https://pdir.de/panorama-bundle/
  10.  * @license    pdir license - All-rights-reserved - commercial extension
  11.  * @author     Mathias Arzberger <develop@pdir.de>
  12.  * @author     Christian Mette <develop@pdir.de>
  13.  *
  14.  * For the full copyright and license information, please view the LICENSE
  15.  * file that was distributed with this source code.
  16.  */
  17. namespace Pdir\PanoramaBundle\Controller\ContentElement;
  18. use Contao\Combiner;
  19. use Contao\Config;
  20. use Contao\ContentModel;
  21. use Contao\Controller;
  22. use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement;
  23. use Contao\Environment;
  24. use Contao\FilesModel;
  25. use Contao\Input;
  26. use Contao\System;
  27. use Contao\Template;
  28. use Pdir\KrPanoBundle\Controller\ContentElement\KrPanoramaController;
  29. use Pdir\KrPanoBundle\Model\ConfigModel;
  30. use Pdir\KrPanoBundle\Model\PanoramaModel;
  31. use Pdir\PanoramaBundle\Model\PanoCityMapModel;
  32. use Pdir\PanoramaBundle\Model\PanoCityModel;
  33. use Pdir\PanoramaBundle\Model\PanoramaExtendedModel;
  34. use Pdir\PanoramaBundle\Model\PanoTimeperiodModel;
  35. use Symfony\Component\HttpFoundation\Request;
  36. use Symfony\Component\HttpFoundation\Response;
  37. #[AsContentElement(category:'pdir'template:'ce_krpanorama')]
  38. class KrPanoramaExtController extends KrPanoramaController
  39. {
  40.     /**
  41.      * Assets directory.
  42.      *
  43.      * @var string
  44.      */
  45.     protected $extAssetsDir 'bundles/pdirpanorama';
  46.     public function retrievePanoramaAndConfigByAutoItem(): void
  47.     {
  48.         // Retrieve current item by auto_item request parameter
  49.         if (Config::get('useAutoItem') && ($autoItem Input::get('auto_item'))) {
  50.             // tell contao that the auto_item parameter has been used -> else a UnusedArgumentsException is thrown resulting in a 404 response
  51.             Input::get('auto_item');
  52.         }
  53.         // get the panorama data record
  54.         /** @var PanoramaModel $this->objPanoPanorama */
  55.         $this->objPanoPanorama PanoramaModel::findByIdOrAlias($autoItem);
  56.         // get the panorama configuration
  57.         $this->objConfig ConfigModel::findByPk($this->model->pdir_pano_config_id);
  58.         // check whether the viewer directory has been overwritten
  59.         if (isset($this->objConfig->override_krpanojs)) {
  60.             // user has own krpano viewer activated - krpanojsSRC is mandatory
  61.             if ($this->objConfig->krpanojsSRC) {
  62.                 // get the path
  63.                 $this->viewerDir FilesModel::findByUuid($this->objConfig->krpanojsSRC)->path;
  64.             }
  65.         }
  66.     }
  67.     protected function getResponse(Template $templateContentModel $modelRequest $request): Response
  68.     {
  69.         $request System::getContainer()->get('request_stack')->getCurrentRequest();
  70.         $this->template $template;
  71.         $this->model $model;
  72.         $this->page $this->getPageModel();
  73.         System::loadLanguageFile('tl_pano_panorama');
  74.         $this->retrievePanoramaAndConfigByAutoItem();
  75.         // Display a wildcard in the back end.
  76.         if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request)) {
  77.             $this->renderBackendView($model->id$model->pdir_pano_debug);
  78.         }
  79.         if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isFrontendRequest($request) && ($model->invisible || null === $this->objPanoPanorama || '1' !== $this->objPanoPanorama->published)) {
  80.             return new Response('');
  81.         }
  82.         if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isFrontendRequest($request)) {
  83.             $this->renderPanoramaView();
  84.             $this->renderExtendedPanoramaView();
  85.         }
  86.         return $this->template->getResponse();
  87.     }
  88.     protected function renderExtendedPanoramaView(): void
  89.     {
  90.         // overwrite element id to use split mode
  91.         $this->template->contentId 1;
  92.         $combinedJS = new Combiner();
  93.         // render timeline
  94.         if ($this->model->pdir_pano_timeline) {
  95.             $this->template->timeline $this->generateTimeline();
  96.             $GLOBALS['TL_CSS'][] = $this->extAssetsDir.'/css/timeline.scss|static';
  97.         }
  98.         // render control panel
  99.         if ($this->model->pdirPanoControlPanel) {
  100.             $combinedJS->add($this->extAssetsDir.'/js/control-panel.js');
  101.             $GLOBALS['TL_CSS'][] = $this->extAssetsDir.'/css/control-panel.scss|static';
  102.             $this->template->controlPanel $this->renderView(
  103.                 '@PdirPanorama/mod_pano_control_panel_view.twig',
  104.                 [
  105.                     'panoName' => $this->objPanoPanorama->name,
  106.                     'panoDescription' => $this->objPanoPanorama->description,
  107.                     'panoLink' => null !== $this->objPanoPanorama Environment::get('url').'/'.Controller::generateFrontendUrl($this->page->row(), '/'.$this->objPanoPanorama->alias) : null,
  108.                 ]
  109.             );
  110.         }
  111.         // render map view
  112.         $GLOBALS['TL_CSS'][] = $this->extAssetsDir.'/css/catalog.scss|static';
  113.         $GLOBALS['TL_CSS'][] = $this->extAssetsDir.'/css/card.scss|static';
  114.         $GLOBALS['TL_CSS'][] = $this->extAssetsDir.'/css/map-container.scss|static';
  115.         $GLOBALS['TL_CSS'][] = $this->extAssetsDir.'/css/panorama.scss|static';
  116.         $combinedJS->add($this->extAssetsDir.'/js/helper.js');
  117.         $combinedJS->add($this->extAssetsDir.'/js/map.js');
  118.         $combinedJS->add($this->extAssetsDir.'/js/sidebar.js');
  119.         $GLOBALS['TL_JAVASCRIPT'][] = 'https://maps.googleapis.com/maps/api/js?key='.$this->model->pano_google_maps_api_key;
  120.         $GLOBALS['TL_JAVASCRIPT'][] = $this->extAssetsDir.'/js/gmap.js|static';
  121.         $GLOBALS['TL_JAVASCRIPT'][] = $this->extAssetsDir.'/js/markercluster.js|static';
  122.         $objCityModel PanoCityModel::findOneBy('id'$this->objPanoPanorama->city);
  123.         if (null === $objCityModel) {
  124.             // @todo allow pano only mode
  125.             // throw new InvalidArgumentException('NO CITY SELECTED!');
  126.         }
  127.         // get city map model from pdirPanoCityMap
  128.         $cityMap null;
  129.         if ($this->model->pdirPanoCityMap) {
  130.             $cityMap PanoCityMapModel::findOneById($this->model->pdirPanoCityMap);
  131.         }
  132.         //dump($objCityModel);
  133.         //dump($cityMap);
  134.         //dump($cityMap->id.'/catalog/1');
  135.         // lade city map from pano object if pdirPanoCityMap is not set
  136.         if (null === $cityMap) {
  137.             $cityMap PanoCityMapModel::findBy(
  138.                 ['city=?''time_period=?'],
  139.                 [$this->objPanoPanorama->city$this->objPanoPanorama->time_period],
  140.             );
  141.         }
  142.         //dump($cityMap);
  143.         //dump($cityMap->getOverlayImage);
  144.         if (null === $cityMap) {
  145.             // @todo allow pano only mode
  146.             // throw new InvalidArgumentException('NO CITY MAP AVAILABLE!');
  147.         }
  148.         // fix overlayImage
  149.         if($cityMap->overlay_imag) {
  150.             $cityMap->overlayImage $cityMap->overlay_imag;
  151.         }
  152.         if (null !== $cityMap && null !== $objCityModel) {
  153.             $timePeriod PanoTimeperiodModel::findOneBy('id'$this->objPanoPanorama->time_period);
  154.             $this->template->mapView $this->renderView(
  155.                 '@PdirPanorama/mod_pano_map_view.twig',
  156.                 [
  157.                     'city' => $objCityModel,
  158.                     'cityMap' => $cityMap,
  159.                     'name' => $objCityModel->name,
  160.                     'actYear' => $this->getTimePeriodYear($timePeriod),
  161.                     'yearLinkText' => $timePeriod->yearLinkText,
  162.                     'timePeriod' => $timePeriod?->id,
  163.                     'iCatalogPageId' => 77,
  164.                     'sCatalogUri' => 'dresden/ajax/ajaxgetcatalog/973ea6f32f8e2ae501b061fab480e805/?tx_arstempanocityselection_cityplugin%5BbPanoCatalog%5D=1',
  165.                     'cat' => '2',
  166.                     'iControlPanel' => 1,
  167.                     'overlayImage' => $cityMap->overlay_image,
  168.                     'url' => Environment::get('url'),
  169.                     'catalogUri' => $cityMap->id.'/catalog/1',
  170.                 ]
  171.             );
  172.         }
  173.         // add assets
  174.         $GLOBALS['TL_BODY'][] = '<script src="'.$combinedJS->getCombinedFile().'"></script>';
  175.         $GLOBALS['TL_CSS'][] = $this->extAssetsDir.'/fontawesome/css/brands.min.css|static';
  176.     }
  177.     protected function getTimePeriodYear(PanoTimeperiodModel $model)
  178.     {
  179.         if (null === $model) {
  180.             return date('Y'time());
  181.         }
  182.         return $model->year;
  183.     }
  184.     /**
  185.      * generate a timeline html and return it as string.
  186.      */
  187.     private function generateTimeline(): string
  188.     {
  189.         $timelineValues = [];
  190.         $panoTimes unserialize($this->model->pdirPanoTimes);
  191.         foreach ($panoTimes as $time) {
  192.             /** @var PanoTimeperiodModel $timeperiodModel */
  193.             $timeperiodModel PanoTimeperiodModel::findByPk($time);
  194.             // find panorama by catalog category
  195.             $panorama PanoramaExtendedModel::findOneBy(['selectioncatalog = ?''time_period = ?'], [$this->objPanoPanorama->selectioncatalog$timeperiodModel->id]);
  196.             $timelineValues[] = [
  197.                 'id' => $timeperiodModel->id,
  198.                 'desc' => $timeperiodModel->desciption,
  199.                 'year' => $timeperiodModel->year,
  200.                 'label' => !empty($timeperiodModel->yearLinkText) ? $timeperiodModel->yearLinkText $timeperiodModel->year,
  201.                 'link' => null !== $panorama null Controller::generateFrontendUrl($this->page->row(), '/'.$panorama->alias),
  202.                 'class' => null === $panorama 'hidden' : ($time === $this->objPanoPanorama->time_period '' 'inactive'),
  203.             ];
  204.         }
  205.         return $this->renderView(
  206.             '@PdirPanorama/mod_pano_timeline_view.twig',
  207.             [
  208.                 'times' => $timelineValues,
  209.                 'krpanoId' => 1// $this->template->contentId,
  210.                 'activeTimePeriod' => $this->objPanoPanorama->time_period,
  211.                 'dualView' => $this->model->pdirPanoDualView,
  212.             ]
  213.         );
  214.     }
  215. }