From c65ae5023fa094cdc1257d6160f05a900ae68772 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 16 Mar 2021 11:14:25 +0100 Subject: [PATCH] Allow integrator to set start or end for date via settings Respect start and end when creating demand from settings. That way integrator can configure it via TypoScript, or provide an FlexForm. Also the query was adjusted. It now respects a single value and doesn't need start and end. That way upcoming events can be created. Relates: #8581 --- Classes/Controller/DateController.php | 2 ++ Classes/Domain/Repository/DateRepository.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Classes/Controller/DateController.php b/Classes/Controller/DateController.php index 1a55ec9..2d74ef1 100644 --- a/Classes/Controller/DateController.php +++ b/Classes/Controller/DateController.php @@ -167,6 +167,8 @@ class DateController extends ActionController $demand->setSortBy((string)$this->settings['sortByDate']); $demand->setSortOrder((string)$this->settings['sortOrder']); $demand->setHighlight((int)$this->settings['highlight']); + $demand->setStart((string)$this->settings['start'] ?? ''); + $demand->setEnd((string)$this->settings['end'] ?? ''); if (!empty($this->settings['limit'])) { $demand->setLimit($this->settings['limit']); diff --git a/Classes/Domain/Repository/DateRepository.php b/Classes/Domain/Repository/DateRepository.php index 6ac94e9..6204037 100644 --- a/Classes/Domain/Repository/DateRepository.php +++ b/Classes/Domain/Repository/DateRepository.php @@ -80,14 +80,14 @@ class DateRepository extends Repository $constraints['userCategories'] = $query->in('event.categories.uid', $demand->getUserCategories()); } - if ($demand->getStart() !== '' && $demand->getEnd() != '') { - $constraints['daterange'] = $query->logicalAnd( - [ - $query->greaterThanOrEqual('start', $demand->getStart()), - $query->lessThanOrEqual('end', $demand->getEnd()) - ] - ); - } else { + if ($demand->getStart() !== '') { + $constraints['starts'] = $query->greaterThanOrEqual('start', $demand->getStart()); + } + if ($demand->getEnd() != '') { + $constraints['ends'] = $query->lessThanOrEqual('end', $demand->getEnd()); + } + + if ($demand->getStart() === '' && $demand->getEnd() === '') { $now = new \DateTime('now', new \DateTimeZone('Europe/Berlin')); $constraints['untilnow'] = $query->greaterThanOrEqual('start', $now); }