events/Classes/Controller/DateController.php

197 lines
5.8 KiB
PHP
Raw Normal View History

<?php
namespace Wrm\Events\Controller;
use TYPO3\CMS\Core\Database\QueryGenerator;
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 TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use Wrm\Events\Domain\Model\Date;
use Wrm\Events\Domain\Model\Dto\DateDemand;
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\Service\DataProcessingForModels;
/**
* DateController
*/
class DateController extends ActionController
{
/**
* @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 QueryGenerator
*/
protected $queryGenerator;
/**
* @var DataProcessingForModels
*/
protected $dataProcessing;
/**
* @var array
*/
protected $pluginSettings;
2019-08-14 17:22:01 +02:00
/*
* @param RegionRepository $regionRepository
* @param DateRepository $dateRepository
2021-07-13 15:50:14 +02:00
* @param CategoryRepository $categoryRepository
*/
2019-08-14 17:22:01 +02:00
public function __construct(
RegionRepository $regionRepository,
2021-07-13 15:50:14 +02:00
DateRepository $dateRepository,
CategoryRepository $categoryRepository
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;
}
/**
* @param DataProcessingForModels $dataProcessing
*/
public function injectDataProcessingForModels(DataProcessingForModels $dataProcessing)
{
$this->dataProcessing = $dataProcessing;
}
/**
* Action initializer
*/
protected function initializeAction()
{
$this->dataProcessing->setConfigurationManager($this->configurationManager);
$this->pluginSettings = $this->configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
);
}
/**
* action list
*
* @return void
*/
public function listAction()
{
2021-07-13 15:50:14 +02:00
if (
($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->createDemandFromSettings();
}
2021-07-13 15:50:14 +02:00
$this->view->assign('dates', $this->dateRepository->findByDemand($demand));
}
2019-08-14 17:22:01 +02:00
/**
* @return void
*/
public function searchAction()
{
2021-07-13 15:50:14 +02:00
$arguments = GeneralUtility::_GET('tx_events_datelist') ?? [];
if (isset($arguments['events_search'])) {
$arguments += $arguments['events_search'];
unset($arguments['events_search']);
}
$this->view->assignMultiple([
'searchword' => $arguments['searchword'] ?? '',
'selRegion' => $arguments['region'] ?? '',
'start' => $arguments['start'] ?? '',
'end' => $arguments['end'] ?? '',
'considerDate' => $arguments['considerDate'] ?? '',
'demand' => DateDemand::createFromRequestValues($arguments, $this->settings),
'regions' => $this->regionRepository->findAll(),
'categories' => $this->categoryRepository->findAllCurrentlyAssigned(),
]);
2019-08-14 17:22:01 +02:00
}
/**
* action teaser
*
* @return void
*/
public function teaserAction()
{
$dates = $this->dateRepository->findByUids($this->settings['eventUids']);
$this->view->assign('dates', $dates);
}
/**
* action show
2021-07-13 15:50:14 +02:00
*
* @Extbase\IgnoreValidation("date")
*
* @param \Wrm\Events\Domain\Model\Date $date
* @return void
*/
public function showAction(Date $date)
{
$this->view->assign('date', $date);
}
/**
* @return DateDemand
*/
protected function createDemandFromSettings(): DateDemand
{
$demand = $this->objectManager->get(DateDemand::class);
$demand->setRegion((string)$this->settings['region']);
$demand->setCategories((string)$this->settings['categories']);
$categoryCombination = (int)$this->settings['categoryCombination'] === 1 ? 'or' : 'and';
$demand->setCategoryCombination($categoryCombination);
$demand->setIncludeSubCategories((bool)$this->settings['includeSubcategories']);
$demand->setSortBy((string)$this->settings['sortByDate']);
$demand->setSortOrder((string)$this->settings['sortOrder']);
2019-08-14 17:22:01 +02:00
$demand->setHighlight((int)$this->settings['highlight']);
$demand->setStart((string)$this->settings['start'] ?? '');
$demand->setEnd((string)$this->settings['end'] ?? '');
2019-08-14 17:22:01 +02:00
if (!empty($this->settings['limit'])) {
$demand->setLimit($this->settings['limit']);
}
2019-08-14 17:22:01 +02:00
return $demand;
}
/**
* @return DateDemand
*/
protected function createDemandFromSearch(): DateDemand
{
2021-07-13 15:50:14 +02:00
$arguments = $this->request->getArguments() ?? [];
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
);
}
}