2019-07-18 13:44:19 +02:00
|
|
|
<?php
|
2021-01-07 08:50:43 +01:00
|
|
|
|
2019-07-18 13:44:19 +02:00
|
|
|
namespace Wrm\Events\Controller;
|
|
|
|
|
2022-07-11 08:59:32 +02:00
|
|
|
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
|
2021-01-11 09:20:51 +01:00
|
|
|
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
2022-11-22 12:58:36 +01:00
|
|
|
use TYPO3\CMS\Extbase\Service\ExtensionService;
|
2023-10-16 07:47:48 +02:00
|
|
|
use Throwable;
|
2021-01-07 08:58:03 +01:00
|
|
|
use Wrm\Events\Domain\Model\Date;
|
2021-12-06 12:14:19 +01:00
|
|
|
use Wrm\Events\Domain\Model\Dto\DateDemandFactory;
|
2021-07-13 15:50:14 +02:00
|
|
|
use Wrm\Events\Domain\Repository\CategoryRepository;
|
2019-07-18 13:44:19 +02:00
|
|
|
use Wrm\Events\Domain\Repository\DateRepository;
|
2019-08-14 17:22:01 +02:00
|
|
|
use Wrm\Events\Domain\Repository\RegionRepository;
|
2022-07-11 08:59:32 +02:00
|
|
|
use Wrm\Events\Events\Controller\DateListVariables;
|
|
|
|
use Wrm\Events\Events\Controller\DateSearchVariables;
|
2023-11-29 10:36:59 +01:00
|
|
|
use Wrm\Events\Frontend\MetaInformation\DateMetaInformationInterface;
|
2022-08-02 17:15:47 +02:00
|
|
|
use Wrm\Events\Pagination\Factory;
|
2021-01-11 09:20:51 +01:00
|
|
|
use Wrm\Events\Service\DataProcessingForModels;
|
2019-07-18 13:44:19 +02:00
|
|
|
|
2021-06-16 11:19:11 +02:00
|
|
|
class DateController extends AbstractController
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
2021-12-06 12:14:19 +01:00
|
|
|
/**
|
|
|
|
* @var DateDemandFactory
|
|
|
|
*/
|
|
|
|
protected $demandFactory;
|
|
|
|
|
2019-07-18 13:44:19 +02:00
|
|
|
/**
|
|
|
|
* @var dateRepository
|
|
|
|
*/
|
2019-08-14 17:22:01 +02:00
|
|
|
protected $dateRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var regionRepository
|
|
|
|
*/
|
|
|
|
protected $regionRepository;
|
2019-07-18 13:44:19 +02:00
|
|
|
|
2021-07-13 15:50:14 +02:00
|
|
|
/**
|
|
|
|
* @var CategoryRepository
|
|
|
|
*/
|
|
|
|
protected $categoryRepository;
|
|
|
|
|
2022-08-02 17:15:47 +02:00
|
|
|
/**
|
|
|
|
* @var Factory
|
|
|
|
*/
|
|
|
|
protected $paginationFactory;
|
|
|
|
|
2021-01-11 09:20:51 +01:00
|
|
|
/**
|
|
|
|
* @var DataProcessingForModels
|
|
|
|
*/
|
|
|
|
protected $dataProcessing;
|
|
|
|
|
2022-11-22 12:58:36 +01:00
|
|
|
/**
|
|
|
|
* @var EventDispatcher
|
|
|
|
*/
|
|
|
|
protected $eventDispatcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ExtensionService
|
|
|
|
*/
|
|
|
|
protected $extensionService;
|
|
|
|
|
2023-11-29 10:36:59 +01:00
|
|
|
/**
|
|
|
|
* @var DateMetaInformationInterface
|
|
|
|
*/
|
|
|
|
protected $metaInformationService;
|
|
|
|
|
2019-08-14 17:22:01 +02:00
|
|
|
public function __construct(
|
2021-12-06 12:14:19 +01:00
|
|
|
DateDemandFactory $demandFactory,
|
2021-07-13 15:50:14 +02:00
|
|
|
DateRepository $dateRepository,
|
2022-11-22 12:58:36 +01:00
|
|
|
RegionRepository $regionRepository,
|
2022-07-11 08:59:32 +02:00
|
|
|
CategoryRepository $categoryRepository,
|
2022-11-22 12:58:36 +01:00
|
|
|
Factory $paginationFactory,
|
2022-07-11 08:59:32 +02:00
|
|
|
DataProcessingForModels $dataProcessing,
|
2022-08-02 17:15:47 +02:00
|
|
|
EventDispatcher $eventDispatcher,
|
2023-11-29 10:36:59 +01:00
|
|
|
ExtensionService $extensionService,
|
|
|
|
DateMetaInformationInterface $metaInformationService
|
2019-08-14 17:22:01 +02:00
|
|
|
) {
|
2021-12-06 12:14:19 +01:00
|
|
|
$this->demandFactory = $demandFactory;
|
2019-07-18 13:44:19 +02:00
|
|
|
$this->dateRepository = $dateRepository;
|
2022-11-22 12:58:36 +01:00
|
|
|
$this->regionRepository = $regionRepository;
|
2021-07-13 15:50:14 +02:00
|
|
|
$this->categoryRepository = $categoryRepository;
|
2022-11-22 12:58:36 +01:00
|
|
|
$this->paginationFactory = $paginationFactory;
|
2021-01-11 09:20:51 +01:00
|
|
|
$this->dataProcessing = $dataProcessing;
|
2022-07-11 08:59:32 +02:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
2022-11-22 12:58:36 +01:00
|
|
|
$this->extensionService = $extensionService;
|
2023-11-29 10:36:59 +01:00
|
|
|
$this->metaInformationService = $metaInformationService;
|
2021-01-11 09:20:51 +01:00
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
protected function initializeAction(): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
2023-06-19 10:13:26 +02:00
|
|
|
parent::initializeAction();
|
|
|
|
|
2021-12-06 12:14:19 +01:00
|
|
|
$contentObject = $this->configurationManager->getContentObject();
|
|
|
|
if ($contentObject !== null) {
|
|
|
|
$this->demandFactory->setContentObjectRenderer($contentObject);
|
|
|
|
}
|
2021-01-11 09:20:51 +01:00
|
|
|
$this->dataProcessing->setConfigurationManager($this->configurationManager);
|
2022-11-22 12:58:36 +01:00
|
|
|
|
|
|
|
$this->handlePostRequest();
|
2019-07-18 13:44:19 +02:00
|
|
|
}
|
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
/**
|
|
|
|
* @param array $search
|
2022-08-02 17:15:47 +02:00
|
|
|
* @param int $currentPage
|
2022-06-28 11:38:55 +02:00
|
|
|
*/
|
2022-08-02 17:15:47 +02:00
|
|
|
public function listAction(
|
|
|
|
array $search = [],
|
|
|
|
int $currentPage = 1
|
|
|
|
): void {
|
2022-07-12 09:49:28 +02:00
|
|
|
$demand = $this->demandFactory->fromSettings($this->settings);
|
2022-06-28 11:38:55 +02:00
|
|
|
if ($search !== []) {
|
2022-11-22 13:49:57 +01:00
|
|
|
$demand = $this->demandFactory->createFromRequestValues($search, $this->settings);
|
2019-11-11 12:43:50 +01:00
|
|
|
}
|
2022-06-28 11:38:55 +02:00
|
|
|
|
2022-08-02 17:15:47 +02:00
|
|
|
$dates = $this->dateRepository->findByDemand($demand);
|
2022-07-11 08:59:32 +02:00
|
|
|
$event = $this->eventDispatcher->dispatch(new DateListVariables(
|
|
|
|
$search,
|
|
|
|
$demand,
|
2022-08-02 17:15:47 +02:00
|
|
|
$dates,
|
|
|
|
$this->paginationFactory->create(
|
|
|
|
$currentPage,
|
|
|
|
$this->settings['itemsPerPage'] ?? 25,
|
|
|
|
$this->settings['maximumLinks'] ?? 5,
|
|
|
|
$dates
|
|
|
|
)
|
2022-07-11 08:59:32 +02:00
|
|
|
));
|
|
|
|
if (!$event instanceof DateListVariables) {
|
|
|
|
throw new \Exception('Did not retrieve DateSearchVariables from event dispatcher, got: ' . get_class($event), 1657542318);
|
|
|
|
}
|
|
|
|
$this->view->assignMultiple($event->getVariablesForView());
|
2019-07-18 13:44:19 +02:00
|
|
|
}
|
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
/**
|
|
|
|
* @param array $search
|
|
|
|
*/
|
|
|
|
public function searchAction(array $search = []): void
|
2019-08-14 17:22:01 +02:00
|
|
|
{
|
2022-07-12 09:49:28 +02:00
|
|
|
$demand = $this->demandFactory->fromSettings($this->settings);
|
|
|
|
if ($search !== []) {
|
2022-11-22 13:49:57 +01:00
|
|
|
$demand = $this->demandFactory->createFromRequestValues($search, $this->settings);
|
2022-07-12 09:49:28 +02:00
|
|
|
}
|
|
|
|
|
2022-07-11 08:59:32 +02:00
|
|
|
$event = $this->eventDispatcher->dispatch(new DateSearchVariables(
|
2024-06-27 10:09:29 +02:00
|
|
|
$this->settings,
|
2022-07-11 08:59:32 +02:00
|
|
|
$search,
|
2022-07-12 09:49:28 +02:00
|
|
|
$demand,
|
2022-07-11 08:59:32 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function teaserAction(): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$dates = $this->dateRepository->findByUids($this->settings['eventUids']);
|
|
|
|
$this->view->assign('dates', $dates);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-11 09:20:51 +01:00
|
|
|
* @Extbase\IgnoreValidation("date")
|
2019-07-18 13:44:19 +02:00
|
|
|
*/
|
2021-09-07 09:52:14 +02:00
|
|
|
public function showAction(Date $date): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
2023-10-16 07:47:48 +02:00
|
|
|
try {
|
|
|
|
$date->getEvent();
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
$this->trigger404('No event found for requested date.');
|
|
|
|
}
|
|
|
|
|
2023-11-29 10:36:59 +01:00
|
|
|
$this->metaInformationService->setDate($date);
|
2019-07-18 13:44:19 +02:00
|
|
|
$this->view->assign('date', $date);
|
|
|
|
}
|
|
|
|
|
2022-11-22 12:58:36 +01:00
|
|
|
/**
|
|
|
|
* Convert POST to proper GET.
|
|
|
|
*
|
|
|
|
* @see: https://en.wikipedia.org/wiki/Post/Redirect/Get
|
|
|
|
*/
|
|
|
|
private function handlePostRequest(): void
|
2019-08-14 17:22:01 +02:00
|
|
|
{
|
2022-11-22 12:58:36 +01:00
|
|
|
if (
|
|
|
|
$this->request->getMethod() === 'POST'
|
|
|
|
&& $this->request->hasArgument('search')
|
|
|
|
&& is_array($this->request->getArgument('search'))
|
|
|
|
) {
|
|
|
|
$namespace = $this->extensionService->getPluginNamespace(null, null);
|
|
|
|
$this->redirectToUri($this->configurationManager->getContentObject()->typoLink_URL([
|
|
|
|
'parameter' => 't3://page?uid=current',
|
|
|
|
'additionalParams' => '&' . http_build_query([
|
|
|
|
$namespace => [
|
2023-06-07 08:56:42 +02:00
|
|
|
'search' => array_filter($this->request->getArgument('search')),
|
2022-11-22 12:58:36 +01:00
|
|
|
],
|
|
|
|
]),
|
|
|
|
]));
|
2019-07-18 13:44:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|