From d12fce521858c021ee2226ef248b71d94d992ff8 Mon Sep 17 00:00:00 2001 From: mrothauer Date: Mon, 12 Feb 2024 09:03:21 +0100 Subject: [PATCH] add option "gt 6 months" --- src/Controller/EventsController.php | 1 + src/Model/Table/EventsTable.php | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Controller/EventsController.php b/src/Controller/EventsController.php index 6211eaf6f..ce04ebd8f 100644 --- a/src/Controller/EventsController.php +++ b/src/Controller/EventsController.php @@ -584,6 +584,7 @@ public function all() '30days' => '30 Tage', '3months' => '3 Monate', '6months' => '6 Monate', + 'gt6months' => '> 6 Monate', ]; $this->set('timeRangeOptions', $timeRangeOptions); diff --git a/src/Model/Table/EventsTable.php b/src/Model/Table/EventsTable.php index 97c059ebe..a2f2c7542 100644 --- a/src/Model/Table/EventsTable.php +++ b/src/Model/Table/EventsTable.php @@ -89,16 +89,28 @@ public function getTimeRangeCondition($timeRange, $negate) { return function ($exp, $query) use ($timeRange, $negate) { $now = new \Cake\I18n\DateTime(); + $minDate = null; $maxDate = $now->addDays(30); if ($timeRange == '3months') { - $maxDate = $now->addDays(90); + $maxDate = $now->addMonths(3); } if ($timeRange == '6months') { - $maxDate = $now->addDays(180); + $maxDate = $now->addMonths(6); + } + if ($timeRange == 'gt6months') { + $minDate = $now->addDays(180); + $minDate = $now->addMonths(6); + $maxDate = null; + } + + if (!is_null($minDate)) { + $result = $exp->gte('Events.datumstart', $minDate, 'date'); + } + if (!is_null($maxDate)) { + $result = $exp->lte('Events.datumstart', $maxDate, 'date'); } - $result = $exp->lte('Events.datumstart', $maxDate, 'date'); if ($negate) { $result = $exp->not($result); }