From 4a7b51b24e7e656a253df0b4be325edfda2235ef Mon Sep 17 00:00:00 2001 From: Moritz Strohm <strohm@data-quest.de> Date: Fri, 16 Feb 2024 12:29:13 +0000 Subject: [PATCH] resources/export/bookings: take bookings that span over multiple days into account, fixes #3038 Closes #3038 Merge request studip/studip!2425 --- app/controllers/resources/export.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/controllers/resources/export.php b/app/controllers/resources/export.php index 488cff5f54c..0f85f71ba59 100644 --- a/app/controllers/resources/export.php +++ b/app/controllers/resources/export.php @@ -359,10 +359,30 @@ class Resources_ExportController extends AuthenticatedController foreach ($intervals as $interval) { //Check the weekday of the interval first to avoid any other computation //if the weekday is not one of the selected weekdays. - $interval_weekday = date('N', $interval->begin); - if (!in_array($interval_weekday, $this->weekdays)) { - //The interval is not on one of the selected weekdays. - continue; + if (date('Ymd', $interval->begin) !== date('Ymd', $interval->end)) { + //The interval spans over multiple days. So the computation for the weekdays must + //take that into account. + $current_day = new DateTime(); + $current_day->setTimestamp($interval->begin); + $current_day->setTime(0,0,0); + $end = new DateTime(); + $end->setTimestamp($interval->end); + $interval_is_on_weekday = false; + while ($current_day <= $end && !$interval_is_on_weekday) { + $interval_is_on_weekday = in_array($current_day->format('N'), $this->weekdays); + $current_day = $current_day->add(new DateInterval('P1D')); + } + if (!$interval_is_on_weekday) { + //The interval does not take place on one of the weekdays that have been selected. + continue; + } + } else { + //The interval lies on one day. + $interval_weekday = date('N', $interval->begin); + if (!in_array($interval_weekday, $this->weekdays)) { + //The interval is not on one of the selected weekdays. + continue; + } } $booking = $interval->booking; if (!$booking instanceof ResourceBooking || !in_array($booking->booking_type, $types)) { -- GitLab