Skip to content

Commit

Permalink
add option "gt 6 months"
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Feb 12, 2024
1 parent 479af8e commit d12fce5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Controller/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ public function all()
'30days' => '30 Tage',
'3months' => '3 Monate',
'6months' => '6 Monate',
'gt6months' => '> 6 Monate',
];
$this->set('timeRangeOptions', $timeRangeOptions);

Expand Down
18 changes: 15 additions & 3 deletions src/Model/Table/EventsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d12fce5

Please sign in to comment.