Implement filterable offer list
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
namespace EP\EpEvents\Controller;
|
||||
|
||||
use EP\EpEvents\Domain\Dto\FilterSettings;
|
||||
use EP\EpEvents\Domain\Model\Offer;
|
||||
use EP\EpEvents\Domain\Repository\OfferRepository;
|
||||
use EP\EpEvents\Service\FilterOptionsCollector;
|
||||
use EP\EpEvents\Service\SectionCssClassService;
|
||||
use EP\EpEvents\Service\SoftHyphenService;
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\FileReference;
|
||||
use TYPO3\CMS\Core\Resource\FileRepository;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
|
||||
class AjaxOfferController extends ActionController
|
||||
{
|
||||
/**
|
||||
* @var OfferRepository
|
||||
*/
|
||||
protected $offerRepository;
|
||||
|
||||
/**
|
||||
* @var FileRepository
|
||||
*/
|
||||
protected $fileRepository;
|
||||
|
||||
/**
|
||||
* @var ImageService
|
||||
*/
|
||||
protected $imageService;
|
||||
|
||||
/**
|
||||
* @param OfferRepository $offerRepository
|
||||
* @param FileRepository $fileRepository
|
||||
* @param ImageService $imageService
|
||||
*/
|
||||
public function __construct(
|
||||
OfferRepository $offerRepository,
|
||||
FileRepository $fileRepository,
|
||||
ImageService $imageService
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->offerRepository = $offerRepository;
|
||||
$this->fileRepository = $fileRepository;
|
||||
$this->imageService = $imageService;
|
||||
}
|
||||
|
||||
public function initializeListAction()
|
||||
{
|
||||
if (!$this->request->hasArgument('filterSettings')) {
|
||||
$filterSettings = new FilterSettings();
|
||||
$this->request->setArgument('filterSettings', $filterSettings);
|
||||
} else {
|
||||
$propertyMappingConfiguration = $this->arguments['filterSettings']->getPropertyMappingConfiguration();
|
||||
$propertyMappingConfiguration->allowAllProperties();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \EP\EpEvents\Domain\Dto\FilterSettings $filterSettings
|
||||
* @return string
|
||||
*/
|
||||
public function listAction(FilterSettings $filterSettings)
|
||||
{
|
||||
$offers = $this->offerRepository->findByFilterSettings($filterSettings);
|
||||
$filterOptions = FilterOptionsCollector::process($offers);
|
||||
$listData = [];
|
||||
|
||||
foreach ($offers as $uid => $offer) {
|
||||
/** @var Offer $offer */
|
||||
$offerDetailPageUri = $this->getDetailPageUri($offer['detailPageUid']);
|
||||
|
||||
$teaserImageUri = $this->getTeaserImageUri($uid);
|
||||
if (!$teaserImageMobileUri = $this->getTeaserImageUri($uid, 'image_teaser_m', 'mobile')) {
|
||||
$teaserImageMobileUri = $this->getTeaserImageUri($uid, 'image_teaser', 'mobile');
|
||||
}
|
||||
|
||||
$listData[] = [
|
||||
'name' => SoftHyphenService::replace($offer['name']),
|
||||
'cssClass' => SectionCssClassService::getClass($offer['configuratorType']),
|
||||
'detailPageUri' => $offerDetailPageUri,
|
||||
'locationName' => $offer['locationName'],
|
||||
'teaserImage' => $teaserImageUri,
|
||||
'teaserImageMobile' => $teaserImageMobileUri,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'offers' => $listData,
|
||||
'filterSettings' => $filterSettings,
|
||||
'filterOptions' => $filterOptions,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $detailPageUid
|
||||
* @return string
|
||||
*/
|
||||
protected function getDetailPageUri($detailPageUid)
|
||||
{
|
||||
return $this
|
||||
->uriBuilder
|
||||
->reset()
|
||||
->setCreateAbsoluteUri(true)
|
||||
->setTargetPageUid($detailPageUid)
|
||||
->buildFrontendUri();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offerUid
|
||||
* @param string $field
|
||||
* @param string $cropVariant
|
||||
* @return string
|
||||
*/
|
||||
protected function getTeaserImageUri($offerUid, $field = 'image_teaser', $cropVariant = 'default')
|
||||
{
|
||||
$teaserImages = $this->fileRepository->findByRelation(
|
||||
'tx_epevents_domain_model_offer',
|
||||
$field,
|
||||
$offerUid
|
||||
);
|
||||
|
||||
if (count($teaserImages) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$teaserImage = reset($teaserImages);
|
||||
|
||||
$instructions = ['width' => '500'];
|
||||
$cropVariantCollection = CropVariantCollection::create((string)$teaserImage->getProperty('crop'));
|
||||
$cropArea = $cropVariantCollection->getCropArea($cropVariant);
|
||||
$instructions['crop'] = $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($teaserImage);
|
||||
$processedTeaserImage = $this->imageService->applyProcessingInstructions($teaserImage, $instructions);
|
||||
|
||||
return $this->imageService->getImageUri($processedTeaserImage, true);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ use EP\EpEvents\Domain\Model\Offer;
|
||||
use EP\EpEvents\Domain\Repository\OfferRepository;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
|
||||
class OfferController extends ActionController
|
||||
{
|
||||
@@ -65,6 +66,22 @@ class OfferController extends ActionController
|
||||
$this->view->assign('content', $content);
|
||||
}
|
||||
|
||||
public function listAction()
|
||||
{
|
||||
$content = $this->configurationManager->getContentObject()->data;
|
||||
$language = [
|
||||
'type' => LocalizationUtility::translate('tx_epevents.label.configurator_travel_type', 'ep_events'),
|
||||
'destination' => LocalizationUtility::translate('tx_epevents.label.configurator_destination', 'ep_events'),
|
||||
'distance' => LocalizationUtility::translate('tx_epevents.label.configurator_distance', 'ep_events'),
|
||||
'hotel' => LocalizationUtility::translate('tx_epevents.label.configurator_accommodation', 'ep_events'),
|
||||
'programme' => LocalizationUtility::translate('tx_epevents.label.configurator_programme', 'ep_events'),
|
||||
'noSelection' => LocalizationUtility::translate('tx_epevents.label.configurator_please_select', 'ep_events'),
|
||||
'reset' => LocalizationUtility::translate('tx_epevents.label.reset', 'ep_events'),
|
||||
];
|
||||
$this->view->assign('content', $content);
|
||||
$this->view->assign('language', json_encode($language));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Offer $offer
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user