282 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			282 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace A2G\A2gMaps\Controller;
 | 
						|
 | 
						|
use A2G\A2gMaps\Domain\Traits\{
 | 
						|
    InjectMapEntryRepositoryTrait,
 | 
						|
    InjectMarkerRepositoryTrait,
 | 
						|
    InjectImageServiceTrait,
 | 
						|
    InjectSysFileReferenceRepositoryTrait,
 | 
						|
    InjectObjectManagerTrait
 | 
						|
};
 | 
						|
use A2G\A2gMaps\Utility\MapConfigUtility;
 | 
						|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
 | 
						|
use TYPO3\CMS\Core\Utility\GeneralUtility;
 | 
						|
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
 | 
						|
use TYPO3\CMS\Extbase\Object\ObjectManager;
 | 
						|
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
 | 
						|
use TYPO3\CMS\Fluid\View\TemplateView;
 | 
						|
use TYPO3\CMS\Fluid\View\StandaloneView;
 | 
						|
use TYPO3\CMS\Core\Resource\ResourceFactory;
 | 
						|
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * This file is part of the "Products" Extension for TYPO3 CMS.
 | 
						|
 *
 | 
						|
 * For the full copyright and license information, please read the
 | 
						|
 * LICENSE.txt file that was distributed with this source code.
 | 
						|
 *
 | 
						|
 * (c) 2021 Raphael Martin <raphy.martin@gmail.com>, none
 | 
						|
 */
 | 
						|
 | 
						|
/**
 | 
						|
 * MapController
 | 
						|
 */
 | 
						|
class MapController extends ActionController {
 | 
						|
 | 
						|
    use InjectMapEntryRepositoryTrait;
 | 
						|
    use InjectMarkerRepositoryTrait;
 | 
						|
    use InjectImageServiceTrait;
 | 
						|
    use InjectSysFileReferenceRepositoryTrait;
 | 
						|
 | 
						|
    private static $mapIcons = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * 
 | 
						|
     * @param UriBuilder $uriBuilder
 | 
						|
     * @param TemplateView $sourceView
 | 
						|
     * @param type $arguments
 | 
						|
     * @param type $actionName
 | 
						|
     * @param type $controllerName
 | 
						|
     * @return StandaloneView
 | 
						|
     */
 | 
						|
    static private function generateContent(UriBuilder $uriBuilder, TemplateView &$sourceView, $arguments = [], $actionName = 'popup', $controllerName = 'Map'): StandaloneView {
 | 
						|
        $templatePath = $controllerName . '/' . ucfirst($actionName);
 | 
						|
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
 | 
						|
        $templateRootPaths = $sourceView->getTemplateRootPaths();
 | 
						|
        $context = $objectManager->get(ControllerContext::class);
 | 
						|
        $request =$objectManager->get(\TYPO3\CMS\Extbase\Mvc\Request::class);
 | 
						|
        $context->setRequest($request);
 | 
						|
        $context->setUriBuilder($uriBuilder);
 | 
						|
        /**
 | 
						|
         * @var StandaloneView $view
 | 
						|
         */
 | 
						|
        $view = GeneralUtility::makeInstance(StandaloneView::class);
 | 
						|
        $view->setControllerContext($context);
 | 
						|
        $view->setLayoutRootPaths($sourceView->getLayoutRootPaths());
 | 
						|
        $view->setTemplateRootPaths($templateRootPaths);
 | 
						|
        $view->setPartialRootPaths($sourceView->getPartialRootPaths());
 | 
						|
        $view->setTemplate($templatePath);
 | 
						|
        $arguments['today'] = (new \DateTime())->format('d.m.Y');
 | 
						|
 | 
						|
        $view->assignMultiple($arguments);
 | 
						|
//        \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($arguments);
 | 
						|
//        die();
 | 
						|
        return $view;
 | 
						|
    }
 | 
						|
 | 
						|
    private function setMapMarkerIcons(){
 | 
						|
        if (self::$mapIcons === null) {
 | 
						|
            self::$mapIcons = [];
 | 
						|
            $markers = $this->markerRepository->findAll();
 | 
						|
            foreach ($markers as $marker) {
 | 
						|
                if ($marker->getMapIcon() !== null) {
 | 
						|
                    self::$mapIcons[] = [
 | 
						|
                        'uid' => 'i-' . $marker->getUid(),
 | 
						|
                        'icon' => $this->imageService->getImageUri($this->imageService->applyProcessingInstructions($this->imageService->getImage('', $marker->getMapIcon(), false), []), true)
 | 
						|
                    ];
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * action map
 | 
						|
     *
 | 
						|
     * @return string|object|null|void
 | 
						|
     */
 | 
						|
    public function mapAction() {
 | 
						|
        if ((int) $this->settings['gpxData'] > 0) {
 | 
						|
            $tmp = $this->sysFileReferenceRepository->findByTablename('tt_content', (int) $this->configurationManager->getContentObject()->data['uid']);
 | 
						|
            $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
 | 
						|
            $file = $resourceFactory->getFileReferenceObject($tmp[0]->getUid());
 | 
						|
            $showGpxData=true;
 | 
						|
        } else {
 | 
						|
            $showGpxData=false;
 | 
						|
        }
 | 
						|
        
 | 
						|
        $this->setMapMarkerIcons();
 | 
						|
        if(array_key_exists('markers',$this->settings) && $this->settings['markers'] !== null){
 | 
						|
 | 
						|
        $markers = explode(',', $this->settings['markers']);
 | 
						|
        if(count($markers)>0){
 | 
						|
            $showMarkers = true;
 | 
						|
            $this->uriBuilder->setTargetPageType(1652369510);
 | 
						|
            $markerUri = $this->uriBuilder->uriFor('mapMarkers', ['ttContentUid'=>(int) $this->configurationManager->getContentObject()->data['uid']]);
 | 
						|
            if((bool)$this->settings['showMarkerList'] === true && !empty($markers)){
 | 
						|
                if(array_key_exists('markerListOrderBy', $markers)){
 | 
						|
                    $mapEntries=$this->mapEntryRepository->getFromUids($markers, $this->settings['markerListOrderBy']);
 | 
						|
                } else {
 | 
						|
                    $mapEntries=$this->mapEntryRepository->getFromUids($markers);  
 | 
						|
                }
 | 
						|
               
 | 
						|
               $mapEntriesSort =  [];
 | 
						|
               foreach($mapEntries as $mapEntrie){
 | 
						|
                   if(array_key_exists($mapEntrie->getRegion(),$mapEntriesSort)){
 | 
						|
                      
 | 
						|
                       $mapEntriesSort[$mapEntrie->getRegion()][]=$mapEntrie;
 | 
						|
                   } else {
 | 
						|
                       
 | 
						|
                       $mapEntriesSort[$mapEntrie->getRegion()]=[];
 | 
						|
                       
 | 
						|
                       $mapEntriesSort[$mapEntrie->getRegion()][]=$mapEntrie;
 | 
						|
                   }
 | 
						|
               }
 | 
						|
               $this->view->assign('mapEntries', $mapEntriesSort);
 | 
						|
            }
 | 
						|
        } else {
 | 
						|
            $showMarkers = false;
 | 
						|
        }
 | 
						|
 | 
						|
        }else {
 | 
						|
            $showMarkers = false;
 | 
						|
        }
 | 
						|
        
 | 
						|
        if(array_key_exists('layers',$this->settings) && $this->settings['layers'] !== null){
 | 
						|
            $layerIds = explode(',', $this->settings['layers']);
 | 
						|
        } else {
 | 
						|
            $layerIds = [];
 | 
						|
        }
 | 
						|
        
 | 
						|
        $this->view->assignMultiple([
 | 
						|
            'mapId' => 'a2g-map-' . uniqid(),
 | 
						|
            'countMapLayers' => count($layerIds),
 | 
						|
            'mapIcons' => \GuzzleHttp\json_encode(self::$mapIcons),
 | 
						|
            'mapConfig' =>  \GuzzleHttp\json_encode(MapConfigUtility::getMapConfig(
 | 
						|
                    $layerIds, 
 | 
						|
                    $showGpxData === true ? $file->getOriginalFile()->getPublicUrl() : null,
 | 
						|
                    $showMarkers === true ? $markerUri : null,
 | 
						|
                    $this->settings['defaultMapMarker'], 
 | 
						|
                    (int)$this->settings['zoom'],
 | 
						|
                    (int)$this->settings['maxZoom'], (float)$this->settings['centerLon'], (float)$this->settings['centerLat'], 
 | 
						|
                    (bool)$this->settings['useZoomSlider'], (bool)$this->settings['useFullscreenButton'], (bool)$this->settings['useLayerSwitcher']))
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * action mapMarkers
 | 
						|
     *
 | 
						|
     * @return string|object|null|void
 | 
						|
     */
 | 
						|
    public function mapMarkersAction() {
 | 
						|
 | 
						|
        if($this->mapEntryRepository->findAll()->count() > 0){
 | 
						|
            $markersUids = $this->mapEntryRepository->getEntriesFromMap((int)GeneralUtility::_GET('tx_a2gmaps_map')['ttContentUid']);
 | 
						|
            $markers = $this->mapEntryRepository->getFromUids($markersUids);
 | 
						|
            if($markers===null){
 | 
						|
                $markers = [];
 | 
						|
            }
 | 
						|
        } else {
 | 
						|
            $markers=[];
 | 
						|
        }
 | 
						|
        $out = [
 | 
						|
            "type" => "FeatureCollection",
 | 
						|
            "totalFeatures" => count($markers),
 | 
						|
            "csr" => MapConfigUtility::getMarkerCsr(),
 | 
						|
            "features" => []
 | 
						|
        ];
 | 
						|
        foreach ($markers as $marker) {
 | 
						|
            if ($marker->getRelMarker() !== null) {
 | 
						|
                $tmpIcon = "i-" . $marker->getRelMarker()->getUid();
 | 
						|
            } else {
 | 
						|
                $tmpIcon = null;
 | 
						|
            }
 | 
						|
            $out["features"][] = MapConfigUtility::getMarker($marker, $tmpIcon, self::generateContent( $this->uriBuilder, $this->view, ['mapEntry' => $marker ])->render());
 | 
						|
        }
 | 
						|
        return \GuzzleHttp\json_encode($out);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * action popup
 | 
						|
     *
 | 
						|
     * @return string|object|null|void
 | 
						|
     */
 | 
						|
    public function MapEntry() {
 | 
						|
        
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * action list
 | 
						|
     *
 | 
						|
     * @return string|object|null|void
 | 
						|
     */
 | 
						|
    public function listAction() {
 | 
						|
        
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * action ajaxListAction
 | 
						|
     *
 | 
						|
     * @return string|object|null|void
 | 
						|
     */
 | 
						|
    public function ajaxListAction() {
 | 
						|
        
 | 
						|
    }
 | 
						|
 | 
						|
//    /**
 | 
						|
//     * action show
 | 
						|
//     *
 | 
						|
//     * @param Ingredients $ingredient
 | 
						|
//     * @return string|object|null|void
 | 
						|
//     */
 | 
						|
//    public function showAction(Ingredients $ingredient) {
 | 
						|
//        $titleProvider = GeneralUtility::makeInstance(A2gPageTitleProvider::class);
 | 
						|
//        
 | 
						|
//        if($this->settings['pageTitleSuffix'] !== null && $this->settings['pageTitleSuffix'] !== '' && (strlen($ingredient->getTitle()) + strlen($this->settings['pageTitleSuffix'])) < 66 ){
 | 
						|
//            $pageTitle = $ingredient->getTitle(). ' ' . $this->settings['pageTitleSuffix'];
 | 
						|
//        } else {
 | 
						|
//            $pageTitle = $ingredient->getTitle();
 | 
						|
//        }
 | 
						|
//        $titleProvider->setTitle($pageTitle);
 | 
						|
//        $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
 | 
						|
//        $description = $contentObject->crop($ingredient->getDescription(), 125 . '|...|' . true);
 | 
						|
//
 | 
						|
//        $uri = $this->uriBuilder->reset()->setCreateAbsoluteUri(true)->setTargetPageUid(
 | 
						|
//                        $GLOBALS['TSFE']->id)->uriFor('show', ['ingredient' => $ingredient], 'Ingredients', 'a2gProducts', 'ingredientsdetail');
 | 
						|
//
 | 
						|
//        $metaTagManager = GeneralUtility::makeInstance(MetaTagManagerRegistry::class);
 | 
						|
//
 | 
						|
//        $metaTagManager->getManagerForProperty('robots')->addProperty('robots', 'index, folow');
 | 
						|
//        $metaTagManager->getManagerForProperty('og:type')->addProperty('og:type', 'website');
 | 
						|
//        $metaTagManager->getManagerForProperty('twitter:card')->addProperty('twitter:card', 'summary_large_image');
 | 
						|
//
 | 
						|
//        if ($ingredient->getTitle() !== '') {
 | 
						|
//            $metaTagManager->getManagerForProperty('title')->addProperty('title', $pageTitle);
 | 
						|
//            $metaTagManager->getManagerForProperty('og:title')->addProperty('og:title', $pageTitle);
 | 
						|
//            $metaTagManager->getManagerForProperty('twitter:title')->addProperty('twitter:title', $pageTitle);
 | 
						|
//        }
 | 
						|
//        if ($ingredient->getDescription() !== '') {
 | 
						|
//            $metaTagManager->getManagerForProperty('description')->addProperty('description', $description);
 | 
						|
//            $metaTagManager->getManagerForProperty('og:description')->addProperty('og:description', $description);
 | 
						|
//            $metaTagManager->getManagerForProperty('twitter:description')->addProperty('twitter:description', $description);
 | 
						|
//        }
 | 
						|
//        $metaTagManager->getManagerForProperty('og:url')->addProperty('og:url', $uri);
 | 
						|
//        $metaTagManager->getManagerForProperty('twitter:url')->addProperty('twitter:url', $uri);
 | 
						|
//
 | 
						|
//        if ($ingredient->getImage() !== null) {
 | 
						|
//            $processedImage = $this->imageService->applyProcessingInstructions(
 | 
						|
//                    $this->imageService->getImage('', $ingredient->getImage(), false),
 | 
						|
//                    ['width' => '
 | 
						|
//        1200', 'height' => '630c']
 | 
						|
//            );
 | 
						|
//            $metaTagManager->getManagerForProperty('twitter:image')->addProperty('twitter:image', $this->imageService->getImageUri($processedImage, true));
 | 
						|
//            $metaTagManager->getManagerForProperty('og:image')->addProperty('og:image', $this->imageService->getImageUri($processedImage, true));
 | 
						|
//        }
 | 
						|
//        $this->view->assign('ingredient', $ingredient);
 | 
						|
//    }
 | 
						|
}
 |