events/Classes/Controller/DateController.php

173 lines
5.8 KiB
PHP
Raw Normal View History

<?php
namespace Wrm\Events\Controller;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
2019-11-11 12:43:50 +01:00
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use Wrm\Events\Domain\Model\Date;
use Wrm\Events\Domain\Model\Dto\DateDemand;
use Wrm\Events\Domain\Model\Dto\DateDemandFactory;
2021-07-13 15:50:14 +02:00
use Wrm\Events\Domain\Repository\CategoryRepository;
use Wrm\Events\Domain\Repository\DateRepository;
2019-08-14 17:22:01 +02:00
use Wrm\Events\Domain\Repository\RegionRepository;
use Wrm\Events\Events\Controller\DateListVariables;
use Wrm\Events\Events\Controller\DateSearchVariables;
use Wrm\Events\Service\DataProcessingForModels;
/**
* DateController
*/
class DateController extends AbstractController
{
/**
* @var DateDemandFactory
*/
protected $demandFactory;
/**
* @var dateRepository
*/
2019-08-14 17:22:01 +02:00
protected $dateRepository;
/**
* @var regionRepository
*/
protected $regionRepository;
2021-07-13 15:50:14 +02:00
/**
* @var CategoryRepository
*/
protected $categoryRepository;
/**
* @var EventDispatcher
*/
protected $eventDispatcher;
/**
* @var DataProcessingForModels
*/
protected $dataProcessing;
2019-08-14 17:22:01 +02:00
public function __construct(
DateDemandFactory $demandFactory,
2019-08-14 17:22:01 +02:00
RegionRepository $regionRepository,
2021-07-13 15:50:14 +02:00
DateRepository $dateRepository,
CategoryRepository $categoryRepository,
DataProcessingForModels $dataProcessing,
EventDispatcher $eventDispatcher
2019-08-14 17:22:01 +02:00
) {
$this->demandFactory = $demandFactory;
2019-08-14 17:22:01 +02:00
$this->regionRepository = $regionRepository;
$this->dateRepository = $dateRepository;
2021-07-13 15:50:14 +02:00
$this->categoryRepository = $categoryRepository;
$this->dataProcessing = $dataProcessing;
$this->eventDispatcher = $eventDispatcher;
}
protected function initializeAction(): void
{
$contentObject = $this->configurationManager->getContentObject();
if ($contentObject !== null) {
$this->demandFactory->setContentObjectRenderer($contentObject);
}
$this->dataProcessing->setConfigurationManager($this->configurationManager);
}
/**
* @param array $search
*/
public function listAction(array $search = []): void
{
if ($search !== []) {
$demand = DateDemand::createFromRequestValues($search, $this->settings);
} elseif (
2021-07-13 15:50:14 +02:00
($this->request->hasArgument('searchword') && $this->request->getArgument('searchword') != '')
|| ($this->request->hasArgument('region') && $this->request->getArgument('region') != '')
|| ($this->request->hasArgument('start') && $this->request->getArgument('start') != '')
|| ($this->request->hasArgument('end') && $this->request->getArgument('end') != '')
|| ($this->request->hasArgument('events_search') && $this->request->getArgument('events_search') != [])
) {
2019-11-11 12:43:50 +01:00
$demand = $this->createDemandFromSearch();
} else {
$demand = $this->demandFactory->fromSettings($this->settings);
2019-11-11 12:43:50 +01:00
}
$event = $this->eventDispatcher->dispatch(new DateListVariables(
$search,
$demand,
$this->dateRepository->findByDemand($demand)
));
if (!$event instanceof DateListVariables) {
throw new \Exception('Did not retrieve DateSearchVariables from event dispatcher, got: ' . get_class($event), 1657542318);
}
$this->view->assignMultiple($event->getVariablesForView());
}
/**
* @param array $search
*/
public function searchAction(array $search = []): void
2019-08-14 17:22:01 +02:00
{
$arguments = GeneralUtility::_GET('tx_events_datelist') ?? $search;
2021-12-13 09:09:13 +01:00
if (is_array($arguments) === false) {
$arguments = [];
}
if (isset($arguments['events_search']) && is_array($arguments['events_search'])) {
2021-07-13 15:50:14 +02:00
$arguments += $arguments['events_search'];
unset($arguments['events_search']);
}
// For legacy systems.
2021-07-13 15:50:14 +02:00
$this->view->assignMultiple([
'searchword' => $arguments['searchword'] ?? '',
'selRegion' => $arguments['region'] ?? '',
'start' => $arguments['start'] ?? '',
'end' => $arguments['end'] ?? '',
'considerDate' => $arguments['considerDate'] ?? '',
]);
$event = $this->eventDispatcher->dispatch(new DateSearchVariables(
$search,
DateDemand::createFromRequestValues($arguments, $this->settings),
$this->regionRepository->findAll(),
$this->categoryRepository->findAllCurrentlyAssigned($this->settings['uids']['categoriesParent'] ?? 0, 'categories'),
$this->categoryRepository->findAllCurrentlyAssigned($this->settings['uids']['featuresParent'] ?? 0, 'features')
));
if (!$event instanceof DateSearchVariables) {
throw new \Exception('Did not retrieve DateSearchVariables from event dispatcher, got: ' . get_class($event), 1657542318);
}
$this->view->assignMultiple($event->getVariablesForView());
2019-08-14 17:22:01 +02:00
}
public function teaserAction(): void
{
$dates = $this->dateRepository->findByUids($this->settings['eventUids']);
$this->view->assign('dates', $dates);
}
/**
* @Extbase\IgnoreValidation("date")
*/
public function showAction(Date $date): void
{
$this->view->assign('date', $date);
}
2019-08-14 17:22:01 +02:00
protected function createDemandFromSearch(): DateDemand
{
2021-12-13 09:09:13 +01:00
$arguments = $this->request->getArguments();
2021-07-13 15:50:14 +02:00
if (isset($arguments['events_search'])) {
$arguments += $arguments['events_search'];
unset($arguments['events_search']);
}
2021-07-13 15:50:14 +02:00
return DateDemand::createFromRequestValues(
$arguments,
$this->settings
);
}
}