diff --git a/app/controllers/course/room_requests.php b/app/controllers/course/room_requests.php index 0b06cbb3981a4e2a3f11d69a28723cfe462bbfd3..cd82c2d78c51435636cd452f5e008065b2b12cd1 100644 --- a/app/controllers/course/room_requests.php +++ b/app/controllers/course/room_requests.php @@ -600,27 +600,69 @@ class Course_RoomRequestsController extends AuthenticatedController null ]; } + $this->matching_rooms = []; if (!$this->room_name && !$this->selected_properties) { //Load all requestable rooms: - $this->available_rooms = RoomManager::findRooms( + $this->matching_rooms = RoomManager::findRooms( '', null, null, [], - $this->request->getTimeIntervals(), + [], 'name ASC, mkdate ASC' ); } else { //Search rooms by the selected properties: - $this->available_rooms = RoomManager::findRooms( + $this->matching_rooms = RoomManager::findRooms( $this->room_name, null, null, $search_properties, - $this->request->getTimeIntervals(), + [], 'name ASC, mkdate ASC' ); } + $this->available_room_icons = []; + $request_time_intervals = $this->request->getTimeIntervals(); + $request_date_amount = count($request_time_intervals); + foreach ($this->matching_rooms as $room) { + $request_dates_booked = 0; + foreach ($request_time_intervals as $interval) { + $booked = ResourceBookingInterval::countBySql( + 'resource_id = :room_id + AND + (begin BETWEEN :begin AND :end + OR end BETWEEN :begin AND :end)', + [ + 'room_id' => $room->id, + 'begin' => $interval['begin'], + 'end' => $interval['end'] + ] + ) > 0; + if ($booked) { + $request_dates_booked++; + } + } + if ($request_dates_booked == 0) { + $this->available_room_icons[$room->id] = + Icon::create('check-circle', Icon::ROLE_STATUS_GREEN)->asImg( + [ + 'class' => 'text-bottom', + 'title' => _('freier Raum') + ] + ); + $this->available_rooms[] = $room; + } elseif ($request_dates_booked < $request_time_intervals) { + $this->available_room_icons[$room->id] = + Icon::create('exclaim-circle', Icon::ROLE_STATUS_YELLOW)->asImg( + [ + 'class' => 'text-bottom', + 'title' => _('teilweise belegter Raum') + ] + ); + $this->available_rooms[] = $room; + } + } if (Request::isPost()) { CSRFProtection::verifyUnsafeRequest(); @@ -971,4 +1013,4 @@ class Course_RoomRequestsController extends AuthenticatedController } $this->redirect('course/room_requests/index'); } -} \ No newline at end of file +} diff --git a/app/views/course/room_requests/request_select_room.php b/app/views/course/room_requests/request_select_room.php index b3df28126e303a5a762d1b9547ba90fa14946e2e..37e28c3606d9820605ee678f947bfd9e18f7a08c 100644 --- a/app/views/course/room_requests/request_select_room.php +++ b/app/views/course/room_requests/request_select_room.php @@ -32,19 +32,7 @@ <? foreach ($available_rooms as $room): ?> <div class="flex-row"> <label class="horizontal"> - <? if ($overlaps[$room->id] <= 0.0): ?> - <?= Icon::create('check-circle', Icon::ROLE_STATUS_GREEN)->asImg( - ['class' => 'text-bottom'] - ) ?> - <? elseif ($overlaps[$room->id] >= 1.0): ?> - <?= Icon::create('decline-circle', Icon::ROLE_STATUS_RED)->asImg( - ['class' => 'text-bottom'] - ) ?> - <? else: ?> - <?= Icon::create('exclaim-circle', Icon::ROLE_STATUS_YELLOW)->asImg( - ['class' => 'text-bottom'] - ) ?> - <? endif ?> + <?= $available_room_icons[$room->id] ?> <input type="radio" name="selected_room_id" data-activates="button[type='submit'][name='select_room']" value="<?= htmlReady($room->id) ?>">