2020-10-22 16:31:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace WerkraumMedia\Calendar\Controller\Frontend;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 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.
|
|
|
|
*/
|
|
|
|
|
2023-01-04 08:42:36 +01:00
|
|
|
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
|
2021-02-23 16:32:39 +01:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
2020-10-22 16:31:54 +02:00
|
|
|
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
|
|
|
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
|
2023-01-04 08:42:36 +01:00
|
|
|
use WerkraumMedia\Calendar\Domain\Model\Context;
|
|
|
|
use WerkraumMedia\Calendar\Domain\Model\ContextSpecificFactory;
|
2020-10-22 16:31:54 +02:00
|
|
|
use WerkraumMedia\Calendar\Domain\Model\Day;
|
2023-01-04 08:42:36 +01:00
|
|
|
use WerkraumMedia\Calendar\Domain\Model\ForeignDataFactory;
|
2020-10-22 16:31:54 +02:00
|
|
|
use WerkraumMedia\Calendar\Domain\Model\Month;
|
|
|
|
use WerkraumMedia\Calendar\Domain\Model\Week;
|
2021-02-23 13:04:29 +01:00
|
|
|
use WerkraumMedia\Calendar\Domain\Model\Year;
|
2021-02-23 16:32:39 +01:00
|
|
|
use WerkraumMedia\Calendar\Events\AssignTemplateVariables;
|
2020-10-22 16:31:54 +02:00
|
|
|
|
|
|
|
class CalendarController extends ActionController
|
|
|
|
{
|
2023-01-04 08:42:36 +01:00
|
|
|
/**
|
|
|
|
* @var ForeignDataFactory
|
|
|
|
*/
|
|
|
|
private $foreignDataFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var TypoScriptService
|
|
|
|
*/
|
|
|
|
private $typoScriptService;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
ForeignDataFactory $foreignDataFactory,
|
|
|
|
TypoScriptService $typoScriptService
|
|
|
|
) {
|
|
|
|
$this->foreignDataFactory = $foreignDataFactory;
|
|
|
|
$this->typoScriptService = $typoScriptService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function initializeAction()
|
|
|
|
{
|
|
|
|
if ($this->foreignDataFactory instanceof ContextSpecificFactory) {
|
|
|
|
$this->foreignDataFactory->setContext(
|
|
|
|
Context::createFromContentObjectRenderer($this->configurationManager->getContentObject())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 13:04:29 +01:00
|
|
|
public function initializeYearAction()
|
|
|
|
{
|
|
|
|
if ($this->request->hasArgument('year') === false) {
|
|
|
|
$this->request->setArguments([
|
|
|
|
'year' => [
|
2023-01-04 08:42:36 +01:00
|
|
|
'year' => $this->getDefaultArgumentValue('year'),
|
2021-02-23 13:04:29 +01:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arguments->getArgument('year')
|
|
|
|
->getPropertyMappingConfiguration()
|
|
|
|
->allowAllProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Extbase\IgnoreValidation("year")
|
|
|
|
*/
|
|
|
|
public function yearAction(Year $year)
|
|
|
|
{
|
2021-02-23 16:32:39 +01:00
|
|
|
$this->assignVariables([
|
2021-02-23 13:04:29 +01:00
|
|
|
'year' => $year,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-10-22 16:31:54 +02:00
|
|
|
public function initializeMonthAction()
|
|
|
|
{
|
|
|
|
if ($this->request->hasArgument('month') === false) {
|
|
|
|
$this->request->setArguments([
|
|
|
|
'month' => [
|
2023-01-04 08:42:36 +01:00
|
|
|
'month' => $this->getDefaultArgumentValue('month'),
|
|
|
|
'year' => $this->getDefaultArgumentValue('year'),
|
2020-10-22 16:31:54 +02:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arguments->getArgument('month')
|
|
|
|
->getPropertyMappingConfiguration()
|
|
|
|
->allowAllProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Extbase\IgnoreValidation("month")
|
|
|
|
*/
|
|
|
|
public function monthAction(Month $month)
|
|
|
|
{
|
2021-02-23 16:32:39 +01:00
|
|
|
$this->assignVariables([
|
2020-10-22 16:31:54 +02:00
|
|
|
'month' => $month,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function initializeWeekAction()
|
|
|
|
{
|
|
|
|
if ($this->request->hasArgument('week') === false) {
|
|
|
|
$this->request->setArguments([
|
|
|
|
'week' => [
|
2023-01-04 08:42:36 +01:00
|
|
|
'week' => $this->getDefaultArgumentValue('week'),
|
|
|
|
'year' => $this->getDefaultArgumentValue('year'),
|
2020-10-22 16:31:54 +02:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arguments->getArgument('week')
|
|
|
|
->getPropertyMappingConfiguration()
|
|
|
|
->allowAllProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Extbase\IgnoreValidation("week")
|
|
|
|
*/
|
|
|
|
public function weekAction(Week $week)
|
|
|
|
{
|
2021-02-23 16:32:39 +01:00
|
|
|
$this->assignVariables([
|
2020-10-22 16:31:54 +02:00
|
|
|
'week' => $week,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function initializeDayAction()
|
|
|
|
{
|
|
|
|
if ($this->request->hasArgument('day') === false) {
|
|
|
|
$this->request->setArguments([
|
2023-01-04 08:12:17 +01:00
|
|
|
'day' => [
|
2023-01-04 08:42:36 +01:00
|
|
|
'day' => $this->getDefaultArgumentValue('day'),
|
2023-01-04 08:12:17 +01:00
|
|
|
],
|
2020-10-22 16:31:54 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$propertyMappingConfiguration = $this->arguments->getArgument('day')
|
|
|
|
->getPropertyMappingConfiguration();
|
|
|
|
|
|
|
|
$propertyMappingConfiguration->allowAllProperties();
|
|
|
|
$propertyMappingConfiguration
|
|
|
|
->forProperty('day')
|
|
|
|
->setTypeConverterOption(
|
|
|
|
DateTimeConverter::class,
|
|
|
|
DateTimeConverter::CONFIGURATION_DATE_FORMAT,
|
|
|
|
'Y-m-d'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Extbase\IgnoreValidation("day")
|
|
|
|
*/
|
|
|
|
public function dayAction(Day $day)
|
|
|
|
{
|
2021-02-23 16:32:39 +01:00
|
|
|
$this->assignVariables([
|
2020-10-22 16:31:54 +02:00
|
|
|
'day' => $day,
|
|
|
|
]);
|
|
|
|
}
|
2021-02-23 16:32:39 +01:00
|
|
|
|
|
|
|
private function assignVariables(array $variables): void
|
|
|
|
{
|
2023-01-04 08:42:36 +01:00
|
|
|
$event = GeneralUtility::makeInstance(
|
|
|
|
AssignTemplateVariables::class,
|
|
|
|
$variables,
|
|
|
|
$this->request->getPluginName()
|
|
|
|
);
|
2021-02-23 16:32:39 +01:00
|
|
|
$this->eventDispatcher->dispatch($event);
|
|
|
|
$this->view->assignMultiple($event->getVariables());
|
|
|
|
}
|
2023-01-04 08:42:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks for TypoScript and transforms TypoScript into expected value.
|
|
|
|
* Allows to define defaults other than "now" for arguments.
|
|
|
|
*/
|
|
|
|
private function getDefaultArgumentValue(string $argumentName): string
|
|
|
|
{
|
|
|
|
$arguments = $this->typoScriptService->convertPlainArrayToTypoScriptArray(
|
|
|
|
$this->settings['arguments'] ?? []
|
|
|
|
);
|
|
|
|
|
|
|
|
$fallbackValues = [
|
|
|
|
'year' => date('Y'),
|
|
|
|
'month' => date('m'),
|
|
|
|
'week' => date('W'),
|
|
|
|
'day' => date('Y-m-d'),
|
|
|
|
];
|
|
|
|
|
|
|
|
$value = $this->configurationManager->getContentObject()->stdWrapValue(
|
|
|
|
$argumentName,
|
|
|
|
$arguments,
|
|
|
|
$fallbackValues[$argumentName]
|
|
|
|
);
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
2020-10-22 16:31:54 +02:00
|
|
|
}
|