From e034e414e80feb25b497172d07eeaa7b6486467d Mon Sep 17 00:00:00 2001 From: Moritz Strohm Date: Mon, 9 Sep 2024 15:33:40 +0000 Subject: add repetition from monday until friday for resource bookings, re #2013 Merge request studip/studip!2539 --- app/controllers/resources/booking.php | 40 +++++++++++++++------- app/views/resources/booking/_add_edit_form.php | 6 ++++ .../6.0.1.1_add_weekdays_to_resource_bookings.php | 26 ++++++++++++++ lib/models/resources/BrokenResource.php | 3 +- lib/models/resources/Building.php | 3 +- lib/models/resources/Location.php | 3 +- lib/models/resources/Resource.php | 8 ++++- lib/models/resources/ResourceBooking.php | 39 ++++++++++++++++++--- lib/models/resources/ResourceLabel.php | 3 +- 9 files changed, 109 insertions(+), 22 deletions(-) create mode 100644 db/migrations/6.0.1.1_add_weekdays_to_resource_bookings.php diff --git a/app/controllers/resources/booking.php b/app/controllers/resources/booking.php index a4722ed..5373519 100644 --- a/app/controllers/resources/booking.php +++ b/app/controllers/resources/booking.php @@ -309,7 +309,8 @@ class Resources_BookingController extends AuthenticatedController $repetition_interval = null, $notification_enabled = false, $included_room_parts = [], - $overwrite_bookings = false + $overwrite_bookings = false, + $weekdays = '' ) { $result = [ @@ -352,7 +353,8 @@ class Resources_BookingController extends AuthenticatedController $booking_type == ResourceBooking::TYPE_LOCK ? $overwrite_bookings : false - ) + ), + $weekdays ); } else { $matching_bookings = ResourceBooking::findByResourceAndTimeRanges( @@ -397,7 +399,8 @@ class Resources_BookingController extends AuthenticatedController $booking_type == ResourceBooking::TYPE_LOCK ? $overwrite_bookings : false - ) + ), + $weekdays ); } } @@ -423,6 +426,7 @@ class Resources_BookingController extends AuthenticatedController } $a->repetition_interval = $repetition_interval->format('P%YY%MM%DD'); $a->repeat_end = $repetition_end->getTimestamp(); + $a->weekdays = $weekdays; } try { @@ -466,7 +470,8 @@ class Resources_BookingController extends AuthenticatedController $booking_type == ResourceBooking::TYPE_LOCK ? $overwrite_bookings : false - ) + ), + $weekdays ); $result['bookings'] = [$booking]; } catch (Exception $e) { @@ -1033,8 +1038,12 @@ class Resources_BookingController extends AuthenticatedController $this->repetition_style = 'monthly'; $this->repetition_interval = $interval->m; } else if (($interval->d % 7) == 0) { - $this->repetition_style = 'weekly'; - $this->repetition_interval = $interval->d / 7; + $this->repetition_style = 'daily'; + if ($this->booking->weekdays === '12345') { + $this->repetition_interval = 'workdays'; + } else { + $this->repetition_interval = $interval->d / 7; + } } else { $this->repetition_style = 'daily'; $this->repetition_interval = $interval->d; @@ -1125,17 +1134,21 @@ class Resources_BookingController extends AuthenticatedController intval($this->end->format('s')) ); if ($this->repetition_style) { - if ($this->repetition_style == 'daily' && $this->repetition_interval) { - $this->repetition_date_interval = new DateInterval( - 'P' . intval($this->repetition_interval) . 'D' - ); + if ($this->repetition_style === 'daily' && $this->repetition_interval) { + if ($this->repetition_interval === 'workdays') { + $this->repetition_date_interval = new DateInterval('P7D'); + } else { + $this->repetition_date_interval = new DateInterval( + 'P' . intval($this->repetition_interval) . 'D' + ); + } } - if ($this->repetition_style == 'weekly' && $this->repetition_interval) { + if ($this->repetition_style === 'weekly' && $this->repetition_interval) { $this->repetition_date_interval = new DateInterval( 'P' . intval($this->repetition_interval) . 'W' ); } - if ($this->repetition_style == 'monthly') { + if ($this->repetition_style === 'monthly') { $this->repetition_date_interval = new DateInterval( 'P1M' ); @@ -1413,7 +1426,8 @@ class Resources_BookingController extends AuthenticatedController ? $this->other_room_parts[$resource->id] : [] ), - $this->overwrite_bookings + $this->overwrite_bookings, + $this->repetition_interval === 'workdays' ? '12345' : '' ); $errors = array_merge($errors, $results['errors']); $room_part_errors = array_merge( diff --git a/app/views/resources/booking/_add_edit_form.php b/app/views/resources/booking/_add_edit_form.php index f982c37..8b921ad 100644 --- a/app/views/resources/booking/_add_edit_form.php +++ b/app/views/resources/booking/_add_edit_form.php @@ -374,6 +374,12 @@ : '' ?>> +