diff options
| author | Moritz Strohm <strohm@data-quest.de> | 2025-10-15 14:36:36 +0000 |
|---|---|---|
| committer | Moritz Strohm <strohm@data-quest.de> | 2025-10-15 14:36:36 +0000 |
| commit | 894dd34eed77192d955c32783bc4d874c0716c2c (patch) | |
| tree | 1392ef4e57089884b6fc3a781770e2f4972a7115 /app | |
| parent | daa69a8c4fcd32862019f7eda32f367433c7d449 (diff) | |
copied code from clipboard booking plan REST-API route into resources/ajax/get_clipboard_booking_plan action, fixes #5864
Closes #5864
Merge request studip/studip!4464
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/resources/ajax.php | 87 | ||||
| -rw-r--r-- | app/views/room_management/planning/index.php | 2 |
2 files changed, 88 insertions, 1 deletions
diff --git a/app/controllers/resources/ajax.php b/app/controllers/resources/ajax.php index 18b3b4d..2d7c27b 100644 --- a/app/controllers/resources/ajax.php +++ b/app/controllers/resources/ajax.php @@ -474,6 +474,93 @@ class Resources_AjaxController extends AuthenticatedController $this->render_json($event_data); } + public function get_clipboard_booking_plan_action($clipboard_id) + { + $clipboard = \Clipboard::find($clipboard_id); + + if (!empty($_SESSION['selected_clipboard_id'])) { + $clipboard = Clipboard::find($_SESSION['selected_clipboard_id']); + } + if (!$clipboard) { + throw new Exception('Clipboard object not found!'); + } + + $current_user = User::findCurrent(); + + //Permission check: + if ($clipboard->user_id !== $current_user->id) { + throw new AccessDeniedException(); + } + + $display_requests = Request::bool('display_requests'); + $display_all_requests = Request::bool('display_all_requests'); + + //Try the ISO format first: YYYY-MM-DDTHH:MM:SS±ZZ:ZZ + $start = Request::getDateTime('start', DateTime::RFC3339); + $end = Request::getDateTime('end', DateTime::RFC3339); + + if (!$start || !$end) { + $start_str = Request::get('start'); + $end_str = Request::get('end'); + $start = new \DateTime(); + $end = new \DateTime(); + //Assume the local timezone and use the Y-m-d format: + $date_regex = '/[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])/'; + if (preg_match($date_regex, $start_str)) { + //$begin is specified in the date formay YYYY-MM-DD: + $start_parts = explode('-', $start_str); + $start->setDate( + $start_parts[0], + $start_parts[1], + $start_parts[2] + ); + $start->setTime(0,0,0); + } else { + $start->setTimestamp($start_str); + } + //Now we do the same for $end_timestamp: + if (preg_match($date_regex, $end_str)) { + //$begin is specified in the date formay YYYY-MM-DD: + $end_parts = explode('-', $end_str); + $end->setDate( + $end_parts[0], + $end_parts[1], + $end_parts[2] + ); + $end->setTime(23,59,59); + } else { + $end->setTimestamp($end_str); + } + } + + $rooms = Room::findMany($clipboard->getAllRangeIds('Room')); + + $booking_types = Request::getArray('booking_types'); + + //Room permission check: + $plan_objects = []; + foreach ($rooms as $room) { + if ($room->bookingPlanVisibleForuser($current_user)) { + $plan_objects = array_merge( + $plan_objects, + \ResourceManager::getBookingPlanObjects( + $room, + [ + [ + 'begin' => $start->getTimestamp(), + 'end' => $end->getTimestamp() + ] + ], + $booking_types, + $display_all_requests ? 'all' : $display_requests + ) + ); + } + } + + $this->render_json(\Studip\Fullcalendar::createData($plan_objects, $start, $end)); + } + public function get_clipboard_semester_plan_action($clipboard_id = null) { if (!$clipboard_id) { diff --git a/app/views/room_management/planning/index.php b/app/views/room_management/planning/index.php index 4bdee32..7289733 100644 --- a/app/views/room_management/planning/index.php +++ b/app/views/room_management/planning/index.php @@ -56,7 +56,7 @@ 'eventSources' => [ [ 'url' => URLHelper::getLink( - 'dispatch.php/resources/ajax/get_clipboard_semester_plan/' . $clipboard->id + 'dispatch.php/resources/ajax/get_clipboard_booking_plan/' . $clipboard->id ), 'method' => 'GET', 'extraParams' => [ |
