mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-22 02:36:09 +01:00
Apply stdWrap to date demand settings
Move to a dedicated factory for easier re use. Add dependencies and apply stdWrap to properties. That allows to dynamically set values like dates by using stdWrap features. E.g.: settings { end { strtotime = midnight +1 day } } Relates: #9505
This commit is contained in:
parent
809ef032f4
commit
bc6aa4d359
2 changed files with 95 additions and 27 deletions
|
@ -8,6 +8,7 @@ use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||||
use Wrm\Events\Domain\Model\Date;
|
use Wrm\Events\Domain\Model\Date;
|
||||||
use Wrm\Events\Domain\Model\Dto\DateDemand;
|
use Wrm\Events\Domain\Model\Dto\DateDemand;
|
||||||
|
use Wrm\Events\Domain\Model\Dto\DateDemandFactory;
|
||||||
use Wrm\Events\Domain\Repository\CategoryRepository;
|
use Wrm\Events\Domain\Repository\CategoryRepository;
|
||||||
use Wrm\Events\Domain\Repository\DateRepository;
|
use Wrm\Events\Domain\Repository\DateRepository;
|
||||||
use Wrm\Events\Domain\Repository\RegionRepository;
|
use Wrm\Events\Domain\Repository\RegionRepository;
|
||||||
|
@ -18,6 +19,11 @@ use Wrm\Events\Service\DataProcessingForModels;
|
||||||
*/
|
*/
|
||||||
class DateController extends AbstractController
|
class DateController extends AbstractController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var DateDemandFactory
|
||||||
|
*/
|
||||||
|
protected $demandFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var dateRepository
|
* @var dateRepository
|
||||||
*/
|
*/
|
||||||
|
@ -54,10 +60,12 @@ class DateController extends AbstractController
|
||||||
* @param CategoryRepository $categoryRepository
|
* @param CategoryRepository $categoryRepository
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
DateDemandFactory $demandFactory,
|
||||||
RegionRepository $regionRepository,
|
RegionRepository $regionRepository,
|
||||||
DateRepository $dateRepository,
|
DateRepository $dateRepository,
|
||||||
CategoryRepository $categoryRepository
|
CategoryRepository $categoryRepository
|
||||||
) {
|
) {
|
||||||
|
$this->demandFactory = $demandFactory;
|
||||||
$this->regionRepository = $regionRepository;
|
$this->regionRepository = $regionRepository;
|
||||||
$this->dateRepository = $dateRepository;
|
$this->dateRepository = $dateRepository;
|
||||||
$this->categoryRepository = $categoryRepository;
|
$this->categoryRepository = $categoryRepository;
|
||||||
|
@ -73,6 +81,10 @@ class DateController extends AbstractController
|
||||||
|
|
||||||
protected function initializeAction(): void
|
protected function initializeAction(): void
|
||||||
{
|
{
|
||||||
|
$contentObject = $this->configurationManager->getContentObject();
|
||||||
|
if ($contentObject !== null) {
|
||||||
|
$this->demandFactory->setContentObjectRenderer($contentObject);
|
||||||
|
}
|
||||||
$this->dataProcessing->setConfigurationManager($this->configurationManager);
|
$this->dataProcessing->setConfigurationManager($this->configurationManager);
|
||||||
$this->pluginSettings = $this->configurationManager->getConfiguration(
|
$this->pluginSettings = $this->configurationManager->getConfiguration(
|
||||||
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
|
||||||
|
@ -90,8 +102,9 @@ class DateController extends AbstractController
|
||||||
) {
|
) {
|
||||||
$demand = $this->createDemandFromSearch();
|
$demand = $this->createDemandFromSearch();
|
||||||
} else {
|
} else {
|
||||||
$demand = $this->createDemandFromSettings();
|
$demand = $this->demandFactory->fromSettings($this->settings);
|
||||||
}
|
}
|
||||||
|
$dates = $this->dateRepository->findByDemand($demand);
|
||||||
$this->view->assign('dates', $this->dateRepository->findByDemand($demand));
|
$this->view->assign('dates', $this->dateRepository->findByDemand($demand));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,32 +142,6 @@ class DateController extends AbstractController
|
||||||
$this->view->assign('date', $date);
|
$this->view->assign('date', $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
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']);
|
|
||||||
$demand->setHighlight((bool)$this->settings['highlight']);
|
|
||||||
if (!empty($this->settings['start'])) {
|
|
||||||
$demand->setStart((int)$this->settings['start']);
|
|
||||||
}
|
|
||||||
if (!empty($this->settings['end'])) {
|
|
||||||
$demand->setEnd((int)$this->settings['end']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($this->settings['limit'])) {
|
|
||||||
$demand->setLimit($this->settings['limit']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $demand;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createDemandFromSearch(): DateDemand
|
protected function createDemandFromSearch(): DateDemand
|
||||||
{
|
{
|
||||||
$arguments = $this->request->getArguments() ?? [];
|
$arguments = $this->request->getArguments() ?? [];
|
||||||
|
|
81
Classes/Domain/Model/Dto/DateDemandFactory.php
Normal file
81
Classes/Domain/Model/Dto/DateDemandFactory.php
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wrm\Events\Domain\Model\Dto;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
|
||||||
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||||
|
|
||||||
|
class DateDemandFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var TypoScriptService
|
||||||
|
*/
|
||||||
|
private $typoScriptService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var contentObjectRenderer
|
||||||
|
*/
|
||||||
|
private $contentObjectRenderer;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
TypoScriptService $typoScriptService
|
||||||
|
) {
|
||||||
|
$this->typoScriptService = $typoScriptService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContentObjectRenderer(
|
||||||
|
ContentObjectRenderer $contentObjectRenderer
|
||||||
|
): void {
|
||||||
|
$this->contentObjectRenderer = $contentObjectRenderer;
|
||||||
|
}
|
||||||
|
public function fromSettings(array $settings): DateDemand
|
||||||
|
{
|
||||||
|
$demand = new DateDemand();
|
||||||
|
|
||||||
|
if ($this->contentObjectRenderer instanceof ContentObjectRenderer) {
|
||||||
|
$typoScriptSettings = $this->typoScriptService->convertPlainArrayToTypoScriptArray($settings);
|
||||||
|
foreach (array_keys($settings) as $settingName) {
|
||||||
|
$settings[$settingName] = $this->contentObjectRenderer->stdWrapValue($settingName, $typoScriptSettings, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$demand->setRegion((string)$settings['region']);
|
||||||
|
$demand->setCategories((string)$settings['categories']);
|
||||||
|
$categoryCombination = (int)$settings['categoryCombination'] === 1 ? 'or' : 'and';
|
||||||
|
$demand->setCategoryCombination($categoryCombination);
|
||||||
|
$demand->setIncludeSubCategories((bool)$settings['includeSubcategories']);
|
||||||
|
$demand->setSortBy((string)$settings['sortByDate']);
|
||||||
|
$demand->setSortOrder((string)$settings['sortOrder']);
|
||||||
|
$demand->setHighlight((bool)$settings['highlight']);
|
||||||
|
if (!empty($settings['start'])) {
|
||||||
|
$demand->setStart((int)$settings['start']);
|
||||||
|
}
|
||||||
|
if (!empty($settings['end'])) {
|
||||||
|
$demand->setEnd((int)$settings['end']);
|
||||||
|
}
|
||||||
|
if (!empty($settings['limit'])) {
|
||||||
|
$demand->setLimit($settings['limit']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $demand;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue