From db8ecf47bc85a04f7c7e5901fd1c84d2e3db86e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Mon, 24 Jul 2023 02:07:37 +0200 Subject: [PATCH] fix select to avoid getting all events as upcoming/recent --- src/Repository/EventRepository.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Repository/EventRepository.php b/src/Repository/EventRepository.php index e40e083..18a8d63 100644 --- a/src/Repository/EventRepository.php +++ b/src/Repository/EventRepository.php @@ -90,9 +90,14 @@ class EventRepository private function selectUpcomingAndRecent(Select $select, DateTime $from, int $days) { - $select->where(function (Select $select) use ($from, $days) { - $select->where('start', '<', (clone $from)->add(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s')); - $select->orWhere('end', '>', (clone $from)->sub(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s')); - }); + $select + ->where(function (Select $select) use ($from, $days) { + $select->where('start', '<', (clone $from)->add(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s')); + $select->where('end', '>', $from->format('Y-m-d H:i:s')); + }) + ->orWhere(function (Select $select) use ($from, $days) { + $select->where('end', '>', (clone $from)->sub(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s')); + $select->where('start', '<', $from->format('Y-m-d H:i:s')); + }); } }