diff options
| author | Moritz Strohm <strohm@data-quest.de> | 2025-05-13 06:22:39 +0000 |
|---|---|---|
| committer | Moritz Strohm <strohm@data-quest.de> | 2025-05-13 06:22:39 +0000 |
| commit | 8f3977db7c34481a90de28eb76e56b293b941089 (patch) | |
| tree | 37091b92be93515193d596898405dd56cf96a342 /lib | |
| parent | 95baa5eeb68b0c298ddc005aaa8f1c4e4091d825 (diff) | |
ResourceBooking::validate: skip exceptions independent of their time range, fixes #5181
Closes #5181
Merge request studip/studip!4114
(cherry picked from commit c0e48592ef765d3a007f60031adb697afb28204c)
9e6179b8 ResourceBooking::validate: move the start of a recurring booking if an overlap occurs in the past
e3c21449 Revert "ResourceBooking::validate: move the start of a recurring booking if an...
ae1baa16 ResourceBooking::validate: skip exceptions independent of their time range
cf771ff4 added code improvement
Co-authored-by: Moritz Strohm <strohm@data-quest.de>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/models/resources/ResourceBooking.class.php | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/models/resources/ResourceBooking.class.php b/lib/models/resources/ResourceBooking.class.php index 158d4d1..88a55d1 100644 --- a/lib/models/resources/ResourceBooking.class.php +++ b/lib/models/resources/ResourceBooking.class.php @@ -511,24 +511,24 @@ class ResourceBooking extends SimpleORMap implements PrivacyObject, Studip\Calen $time_intervals = $this->calculateTimeIntervals(true); $time_interval_overlaps = []; - $existing_deleted_intervals = []; + $exceptions = []; if (!$this->isNew()) { - $existing_deleted_intervals = array_filter( - $this->getTimeIntervals(), - function ($i): bool { - return !$i->takes_place; - } + // Calculate the shift in time of this booking: + $exceptions = ResourceBookingInterval::findAndMapBySQL( + function (ResourceBookingInterval $interval): string { + // Store the date of the exception: + return date('Ymd', $interval->begin); + }, + "`booking_id` = :booking_id AND `takes_place` = 0", + ['booking_id' => $this->id] ); } foreach ($time_intervals as $time_interval) { - foreach ($existing_deleted_intervals as $deleted_interval) { - if ( - $time_interval['begin']->getTimestamp() == $deleted_interval['begin'] - && $time_interval['end']->getTimestamp() == $deleted_interval['end'] - ) { - continue 2; - } + if (in_array($time_interval['begin']->format('Ymd'), $exceptions)) { + //Skip this time interval, since it is an exception. + continue; } + $is_locked = $derived_resource->isLocked( $time_interval['begin'], $time_interval['end'], |
