diff options
| author | Moritz Strohm <strohm@data-quest.de> | 2024-02-16 12:29:13 +0000 |
|---|---|---|
| committer | Moritz Strohm <strohm@data-quest.de> | 2024-02-16 12:29:13 +0000 |
| commit | 4a7b51b24e7e656a253df0b4be325edfda2235ef (patch) | |
| tree | 7799cce35575297d427904622bfdafe357591a60 | |
| parent | 1ef1f7a264e39cb112188a86326b1e96e9874906 (diff) | |
resources/export/bookings: take bookings that span over multiple days into account, fixes #3038
Closes #3038
Merge request studip/studip!2425
| -rw-r--r-- | app/controllers/resources/export.php | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/app/controllers/resources/export.php b/app/controllers/resources/export.php index 488cff5..0f85f71 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)) { |
