diff --git a/Classes/Domain/Model/Dto/DateDemand.php b/Classes/Domain/Model/Dto/DateDemand.php index d7ab294..9faf436 100644 --- a/Classes/Domain/Model/Dto/DateDemand.php +++ b/Classes/Domain/Model/Dto/DateDemand.php @@ -80,6 +80,11 @@ class DateDemand */ protected $considerDate = false; + /** + * @var string + */ + protected $queryCallback = ''; + public static function createFromRequestValues( array $submittedValues, array $settings @@ -110,6 +115,7 @@ class DateDemand $instance->setSortBy($settings['sortByDate'] ?? ''); $instance->setSortOrder($settings['sortOrder'] ?? ''); + $instance->setQueryCallback($settings['queryCallback'] ?? ''); if (!empty($settings['limit'])) { $instance->setLimit($settings['limit']); @@ -275,4 +281,14 @@ class DateDemand { $this->considerDate = $considerDate; } + + public function getQueryCalback(): string + { + return $this->queryCallback; + } + + public function setQueryCallback(string $queryCallback): void + { + $this->queryCallback = $queryCallback; + } } diff --git a/Classes/Domain/Model/Dto/DateDemandFactory.php b/Classes/Domain/Model/Dto/DateDemandFactory.php index 0c5dc1a..11f0c11 100644 --- a/Classes/Domain/Model/Dto/DateDemandFactory.php +++ b/Classes/Domain/Model/Dto/DateDemandFactory.php @@ -47,6 +47,7 @@ class DateDemandFactory ): void { $this->contentObjectRenderer = $contentObjectRenderer; } + public function fromSettings(array $settings): DateDemand { $demand = new DateDemand(); @@ -75,6 +76,9 @@ class DateDemandFactory if (!empty($settings['limit'])) { $demand->setLimit($settings['limit']); } + if (!empty($settings['queryCallback'])) { + $demand->setQueryCallback($settings['queryCallback']); + } return $demand; } diff --git a/Classes/Domain/Repository/DateRepository.php b/Classes/Domain/Repository/DateRepository.php index 9177368..06fe0fe 100644 --- a/Classes/Domain/Repository/DateRepository.php +++ b/Classes/Domain/Repository/DateRepository.php @@ -2,6 +2,7 @@ namespace Wrm\Events\Domain\Repository; +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface; @@ -14,6 +15,16 @@ use Wrm\Events\Service\CategoryService; class DateRepository extends Repository { + /** + * @var Context + */ + protected $context; + + public function injectContext(Context $context): void + { + $this->context = $context; + } + public function findByUids(string $uids): QueryResult { $uids = explode(',', $uids); @@ -80,7 +91,12 @@ class DateRepository extends Repository } if ($demand->getStart() === null && $demand->getEnd() === null) { - $now = new \DateTime('now', new \DateTimeZone('Europe/Berlin')); + $now = $this->context->getPropertyFromAspect( + 'date', + 'full', + new \DateTimeImmutable() + ); + $now = $now->modify('midnight'); $constraints['nowAndFuture'] = $query->logicalOr([ $query->greaterThanOrEqual('start', $now), $query->greaterThanOrEqual('end', $now) @@ -97,6 +113,12 @@ class DateRepository extends Repository $query->setOrderings([$demand->getSortBy() => $demand->getSortOrder()]); + $callback = $demand->getQueryCalback(); + if ($callback !== '') { + $params = ['query' => &$query]; + GeneralUtility::callUserFunction($callback, $params, $this); + } + return $query; }