src/Document/Areabrick/Documenslider.php line 38

Open in your IDE?
  1. <?php
  2.     /**
  3.      * project: Pimcore - Schutzverband Nuernberg Rostbratwuerste
  4.      * User: erikb
  5.      * Year: 2022
  6.      */
  7.     namespace App\Document\Areabrick;
  8.     use App\Website\Tool\Image;
  9.     use Devkitchen\DocumentIndexingBundle\IndexingService\IndexingService;
  10.     use Pimcore\Http\Request\Resolver\EditmodeResolver;
  11.     use Pimcore\Model\Asset;
  12.     use Pimcore\Model\Document\Editable\Area\Info;
  13.     use Pimcore\Model\Document\Page;
  14.     use Pimcore\Translation\Translator;
  15.     class Documenslider extends AbstractAreabrick {
  16.         private $translator;
  17.         private $editmode;
  18.         private $indexingService;
  19.         public function __constructTranslator $translatorEditmodeResolver $editmodeResolverIndexingService $indexingService) {
  20.             $this->translator $translator;
  21.             $this->editmode $editmodeResolver->isEditmode();
  22.             $this->indexingService $indexingService;
  23.         }
  24.         public function getName() {
  25.             return 'Document slider';
  26.         }
  27.         public function getDescription() {
  28.             return 'Generates a teaser slidershow';
  29.         }
  30.         public function action(Info $info) {
  31.             $cssClasses $info->getParam'cssClasses') ?? [];
  32.             $items null;
  33.             $listing null;
  34.             $columns $info->getParam'columns');
  35.             $brickMode $info->getParam'brickMode');
  36.             $documentTypes $this->indexingService->getDocumentTypes();
  37.             $documentTypeStore = [];
  38.             foreach ($documentTypes as $type) {
  39.                 if ($type->key != 'default' && $type->doc_count 0) {
  40.                     $documentTypeStore[] = [$type->key$this->translator->trans'document-type.'.$type->key, [], 'admin''en')];
  41.                 }
  42.             }
  43.             $documentSubtypeStore = [];
  44.             $selectedDocumentType false;
  45.             if (!$this->getDocumentEditable$info->getDocument(), 'select''document-type')->isEmpty()) {
  46.                 $selectedDocumentType $this->getDocumentEditable$info->getDocument(), 'select''document-type')->getData();
  47.                 $documentSubtypes $this->indexingService->getFieldAggregated$selectedDocumentType );
  48.                 foreach($documentSubtypes as $subtype) {
  49.                     $documentSubtypeStore[] = [$subtype->key$this->translator->trans'document-subtype.'.$subtype->key, [], 'admin''en')];
  50.                 }
  51.                 $selectedDocumentSubtypes = [];
  52.                 if (!$this->getDocumentEditable$info->getDocument(), 'multiselect''document-subtype')->isEmpty()) {
  53.                     $selectedDocumentSubtypes $this->getDocumentEditable$info->getDocument(), 'multiselect''document-subtype' )->getData();
  54.                 }
  55.                 $selectedSort $this->getDocumentEditable$info->getDocument(), 'select''sort')->getData() ?: 'documentIndex';
  56.                 $selectedSortDirection $this->getDocumentEditable$info->getDocument(), 'select''sort-direction')->getData() ?: 'asc';
  57.                 $resultSize 1000;
  58.                 $documentCountEditable $this->getDocumentEditable$info->getDocument(), 'numeric''document-count');
  59.                 if (!$documentCountEditable->isEmpty() && $documentCountEditable->getData() > 0) {
  60.                     $resultSize $documentCountEditable->getData();
  61.                 }
  62.                 //$listing = $this->indexingService->listing( $selectedDocumentType, $selectedDocumentSubtypes, 'default', 'de', $selectedSort, $selectedSortDirection, $resultSize);
  63.                 $listing $this->indexingService->setOrderBy$selectedSort )
  64.                                                  ->setOrderDirection$selectedSortDirection )
  65.                                  ->setResultSize$resultSize )
  66.                                                  ->listing$selectedDocumentType$selectedDocumentSubtypes 'default');
  67.                 if ($listing) {
  68.                     $listingCount count$listing );
  69.                     if ($listingCount 0) {
  70.                         $items = [];
  71.                         foreach($listing as $item) {
  72.                             $document Page::getById$item->documentId );
  73.                             $teaserThumbnail null;
  74.                             $teaserImageId $brickMode == 'structure' $item->teaserAssetId $item->teaserAssetBigId;
  75.                             if ($teaserImageId) {
  76.                                 $teaserImage Asset::getById$teaserImageId );
  77.                             }
  78.                             else {
  79.                                 $teaserImage $document->getProperty'document-teaser-image-fallback' );
  80.                             }
  81.                             if ($teaserImage) {
  82.                                 $thumbnailColumns $brickMode == 'structure' $columns;
  83.                                 $thumbnailOverride $brickMode == 'structure' 'teaser-default' 'teaser-intro';
  84.                                 $gridImageData   Image::getGridThumbnailMetaData$teaserImage$thumbnailColumns $this->editmode$thumbnailOverride );
  85.                                 $teaserThumbnail $teaserImage->getThumbnail$gridImageData->thumbnail );
  86.                                 $loading 'lazy';
  87.                                 $decoding $this->editmode 'sync' 'async';
  88.                                 if (!$this->editmode && ($info->getParam'sectionIndex') == && $info->getParam'gridIndex') <= 1)) {
  89.                                     $loading 'eager';
  90.                                 }
  91.                                 $teaserThumbnail $teaserThumbnail->getHtml([
  92.                                     'imgAttributes' => [
  93.                                         'loading' => $loading,
  94.                                         'decoding' => $decoding
  95.                                     ]
  96.                                                         ]);
  97.                             }
  98.                             $teaserSubtitle null;
  99.                             if ($item->documentSubtype) {
  100.                                 foreach($item->documentSubtype as $key) {
  101.                                     $teaserSubtitle[] = $this->translator->trans('filter.value.'.$key);
  102.                                 }
  103.                                 $teaserSubtitle implode(', '$teaserSubtitle);
  104.                             }
  105.                             $items[] = [
  106.                                 'url' => $document,
  107.                                 'title' => $item->teaserTitle,
  108.                                 'subtitle' => $teaserSubtitle,
  109.                                 'image' => $teaserThumbnail,
  110.                                 'text' => $item->teaserContent
  111.                             ];
  112.                         }
  113.                     }
  114.                 }
  115.             }
  116.             $sortTypeStore[] = ['documentIndex'$this->translator->trans'sort-type.document-index', [], 'admin''en')];
  117.             $sortTypeStore[] = ['documentDate'$this->translator->trans'sort-type.document-date', [], 'admin''en')];
  118.             $sortTypeStore[] = ['teaserTitle.raw'$this->translator->trans'sort-type.teaser-title', [], 'admin''en')];
  119.             $sortTypeStore[] = ['documentTitle.raw'$this->translator->trans'sort-type.document-title', [], 'admin''en')];
  120.             $sortDirectionTypeStore[] = ['asc'$this->translator->trans'sort-direction.asc', [], 'admin''en')];
  121.             $sortDirectionTypeStore[] = ['desc'$this->translator->trans'sort-direction.desc', [], 'admin''en')];
  122.             $displayAsTypeStore[] = ['list'$this->translator->trans'display-as.list', [], 'admin''en')];
  123.             $displayAsTypeStore[] = ['grid'$this->translator->trans'display-as.grid', [], 'admin''en')];
  124.             $selectedDisplayAsType =  $this->getDocumentEditable$info->getDocument(), 'select''display-as')->getData() ?: 'list';
  125.             $info->setParam'documentTypeStore'$documentTypeStore);
  126.             $info->setParam'documentSubtypeStore'$documentSubtypeStore);
  127.             $info->setParam'selectedDocumentType'$selectedDocumentType);
  128.             $info->setParam'sortTypeStore'$sortTypeStore);
  129.             $info->setParam'sortDirectionTypeStore'$sortDirectionTypeStore);
  130.             $info->setParam'displayAsTypeStore'$displayAsTypeStore);
  131.             $info->setParam'selectedDisplayAsType'$selectedDisplayAsType);
  132.             $info->setParam'items'$items);
  133.             $info->setParam'cssClasses'$cssClasses);
  134.         }
  135.         public function needsReload(): bool {
  136.             return false;
  137.         }
  138.         // returns a custom html wrapper element (return an empty string if you don't want a wrapper element)
  139.         public function getHtmlTagOpen(Info $info) {
  140.             return '';
  141.         }
  142.         public function getHtmlTagClose(Info $info) {
  143.             return '';
  144.         }
  145.     }