From e8d60870099e5ef7c47ed8f8859515069763514e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michaela=20Br=C3=BCckner?= <brueckner@data-quest.de> Date: Tue, 16 Aug 2022 13:18:54 +0200 Subject: [PATCH] first step: select a room, re #1327 --- app/controllers/course/room_requests.php | 107 ++++++++++++++++-- .../_new_request_form_footer.php | 29 +++++ .../room_requests/_new_request_header.php | 19 ++++ ...d_by_property.php => find_by_category.php} | 0 .../course/room_requests/find_by_roomname.php | 28 ++++- .../course/room_requests/new_request.php | 11 +- .../room_requests/request_select_room.php | 3 +- 7 files changed, 180 insertions(+), 17 deletions(-) create mode 100644 app/views/course/room_requests/_new_request_form_footer.php rename app/views/course/room_requests/{find_by_property.php => find_by_category.php} (100%) diff --git a/app/controllers/course/room_requests.php b/app/controllers/course/room_requests.php index 3b8d4c272ce..e92011b5f8e 100644 --- a/app/controllers/course/room_requests.php +++ b/app/controllers/course/room_requests.php @@ -258,6 +258,7 @@ class Course_RoomRequestsController extends AuthenticatedController _('Hier können Sie Angaben zu gewünschten Raumeigenschaften machen.') ); + // create a new request $this->request_id = $request_id; if (Request::submitted('request_id')) { $this->request_id = Request::get('request_id'); @@ -267,10 +268,15 @@ class Course_RoomRequestsController extends AuthenticatedController } $this->request = null; - $this->request = RoomRequest::find(Request::get('request_id')); - $this->available_room_categories = ResourceCategory::findByClass_name( - 'Room' - ); + $this->request = RoomRequest::find(Request::get('request_id')) ? RoomRequest::find(Request::get('request_id')) : new RoomRequest($this->request_id); + + // TODO no idea why we need this and what it does + $this->request->setRangeFields('course', [Context::getId()]); + $this->request_time_intervals = $this->request->getTimeIntervals(); + + + + $this->available_room_categories = ResourceCategory::findByClass_name('Room'); } @@ -279,15 +285,27 @@ class Course_RoomRequestsController extends AuthenticatedController $this->request_id = $request_id; if (Request::isPost()) { - CSRFProtection::verifyUnsafeRequest(); - $this->room_name = Request::get('room_name'); - $this->category_id = Request::get('category_id'); + CSRFProtection::verifyUnsafeRequest(); + $this->room_name = Request::get('room_name'); + $this->search_by_roomname = Request::submitted('search_by_name'); + $this->category_id = Request::get('category_id'); + $this->search_by_category = Request::submitted('select_properties'); - if ($this->room_name != null) { + // user looks for a special room OR for room within a selected category + if ($this->room_name != null && $this->search_by_roomname != null) { $_SESSION[$request_id]['room_name'] = $this->room_name; $this->redirect( 'course/room_requests/find_by_roomname/' . $this->request_id ); + } else if ($this->category_id != null && $this->search_by_category != null ) { + $_SESSION[$request_id]['room_category'] = $this->catgeory_id; + $this->redirect( + 'course/room_requests/find_by_category/' . $this->request_id + ); + } else { + $this->redirect( + 'course/room_requests/new_request/' . $this->request_id + ); } } @@ -296,6 +314,77 @@ class Course_RoomRequestsController extends AuthenticatedController public function find_by_roomname_action($request_id) { $this->request_id = $request_id; + $this->room_name = $_SESSION[$request_id]['room_name']; + $this->available_rooms = RoomManager::findRooms( + $this->room_name, + null, + null, + null, + [], + 'name ASC, mkdate ASC' + ); + + // small icons before room name to show whether they are bookable or not + $this->available_room_icons = $this->getRoomBookingIcons($this->available_rooms, $this->request_id); + + + } + + private function getRoomBookingIcons($available_rooms, $request_id) + { + $this->request_id = $request_id; + + $this->available_room_icons = []; + $this->request = RoomRequest::find($this->request_id) ? RoomRequest::find($this->request_id) : new RoomRequest($this->request_id); + + // TODO set range fields for other + $this->request->setRangeFields('course', [Context::getId()]); + $request_time_intervals = $this->request->getTimeIntervals(); + + foreach ($available_rooms as $room) { + $request_dates_booked = 0; + foreach ($request_time_intervals as $interval) { + $booked = ResourceBookingInterval::countBySql( + 'resource_id = :room_id AND begin < :end AND end > :begin', + [ + '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') + ] + ); + $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') + ] + ); + $available_rooms[] = $room; + } + } + return $this->available_room_icons; + } + + + + + public function find_by_category_action($request_id) + { + } @@ -391,7 +480,6 @@ class Course_RoomRequestsController extends AuthenticatedController ); return; } - if (Request::isPost()) { CSRFProtection::verifyUnsafeRequest(); $this->room_name = Request::get('room_name'); @@ -680,6 +768,7 @@ class Course_RoomRequestsController extends AuthenticatedController ); } $this->available_room_icons = []; + $request_time_intervals = $this->request->getTimeIntervals(); $request_date_amount = count($request_time_intervals); foreach ($this->matching_rooms as $room) { diff --git a/app/views/course/room_requests/_new_request_form_footer.php b/app/views/course/room_requests/_new_request_form_footer.php new file mode 100644 index 00000000000..31f72e42139 --- /dev/null +++ b/app/views/course/room_requests/_new_request_form_footer.php @@ -0,0 +1,29 @@ +<footer data-dialog-button> + <? if ($room_search_button) : ?> + <?= \Studip\Button::create( + _('Räume suchen'), + 'search_rooms', + [ + 'title' => _('Startet die Suche von Räumen anhand der gewählten Eigenschaften.') + ] + ) ?> + <? endif ?> + <? if ($room_select_button) : ?> + <?= \Studip\Button::create(_('Raum auswählen'), 'select_room') ?> + <? endif ?> + <? if ($save_buttons) : ?> + <?= \Studip\Button::create(_('Speichern'), 'save_and_close') ?> + <? endif ?> + <? if ($select_properties_button) : ?> + <?= \Studip\Button::create(_('Eigenschaften wählen'), 'select_properties') ?> + <? endif ?> + <?= \Studip\LinkButton::createCancel( + _('Abbrechen'), + $controller->link_for('course/room_requests/index/' . $course_id), + [ + 'title' => _('Abbrechen') + ] + ) ?> +</footer> +</form> +<?= $step ?> diff --git a/app/views/course/room_requests/_new_request_header.php b/app/views/course/room_requests/_new_request_header.php index 757578635ab..1f27c74390c 100644 --- a/app/views/course/room_requests/_new_request_header.php +++ b/app/views/course/room_requests/_new_request_header.php @@ -2,3 +2,22 @@ _('Geben Sie den gewünschten Raum und/oder Raumeigenschaften an. Ihre Raumanfrage wird von der zuständigen Raumvergabe bearbeitet.'), [_('<strong>Achtung:</strong> Um später einen passenden Raum für Ihre Veranstaltung zu bekommen, geben Sie bitte immer die gewünschten Eigenschaften mit an!')] )?> + +<section class="resources-grid"> + <section class="contentbox"> + <header><h1><?= _('Anfrage') ?></h1></header> + <section> + <?= htmlready($request->getTypeString(), 1, 1) ?> + <? if ($request->getType() == 'course'): ?> + <? + $dates = $request->getDateString(true); + ?> + <?= tooltipHtmlIcon(implode('<br>', $dates)) ?> + <? endif ?> + </section> + </section> + <section class="contentbox"> + <header><h1><?= _('Bearbeitungsstatus') ?></h1></header> + <section></section> + </section> +</section> diff --git a/app/views/course/room_requests/find_by_property.php b/app/views/course/room_requests/find_by_category.php similarity index 100% rename from app/views/course/room_requests/find_by_property.php rename to app/views/course/room_requests/find_by_category.php diff --git a/app/views/course/room_requests/find_by_roomname.php b/app/views/course/room_requests/find_by_roomname.php index a28cc3c539b..50b9986e499 100644 --- a/app/views/course/room_requests/find_by_roomname.php +++ b/app/views/course/room_requests/find_by_roomname.php @@ -8,7 +8,6 @@ <?= $this->render_partial( 'course/room_requests/_new_request_header') ?> - <?= $request_id ?> <?= var_dump($_SESSION[$request_id]) ?> <section class="resources-grid"> <div> @@ -84,9 +83,34 @@ </span> </label> + <? if ($available_rooms) : ?> + <label><?= _('Passende Räume') ?> + <section class="selectbox"> + <? foreach ($available_rooms as $room): ?> + <div class="flex-row"> + <label class="horizontal"> + <?= $available_room_icons[$room->id] ?> + <input type="radio" name="selected_room_id" + data-activates="button[type='submit'][name='select_room']" + value="<?= htmlReady($room->id) ?>"> + <?= htmlReady(mb_substr($room->name, 0, 50)); ?> + <? if ($room->properties): ?> + <? $property_names = $room->getInfolabelPrperties() + ->pluck('fullname') ?> + <?= tooltipIcon(implode("\n", $property_names)) ?> + <? endif ?> + </label> + </div> + <? endforeach ?> + </section> + </label> + <? else : ?> + <?= MessageBox::info(_('Es wurden keine passenden Räume gefunden!')) ?> + <? endif ?> + </fieldset> </div> </section> -<?= $this->render_partial('course/room_requests/_request_form_footer') ?> +<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => 1]) ?> <? endif ?> diff --git a/app/views/course/room_requests/new_request.php b/app/views/course/room_requests/new_request.php index e1b554d730e..3b5dcef3bdc 100644 --- a/app/views/course/room_requests/new_request.php +++ b/app/views/course/room_requests/new_request.php @@ -9,9 +9,10 @@ 'course/room_requests/_new_request_header') ?> <?= $request_id ?> -<?= var_dump($request) ?> -<?= $room_name ?> -<section class="resources-grid"> + <br/> + <?= var_dump($request_time_intervals) ?> + + <section class="resources-grid"> <div> <fieldset> <legend><?= _('Wünschbare Eigenschaften') ?></legend> @@ -45,7 +46,7 @@ [ 'type' => 'image', 'class' => 'text-bottom', - 'name' => 'select_properties', + 'name' => 'search_by_category', 'value' => _('Raumtyp auswählen'), 'style' => 'margin-left: 0.2em; margin-top: 0.6em;' ] @@ -89,5 +90,5 @@ </div> </section> -<?= $this->render_partial('course/room_requests/_request_form_footer') ?> +<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => 0]) ?> <? endif ?> diff --git a/app/views/course/room_requests/request_select_room.php b/app/views/course/room_requests/request_select_room.php index 37e28c3606d..097e136a1e7 100644 --- a/app/views/course/room_requests/request_select_room.php +++ b/app/views/course/room_requests/request_select_room.php @@ -26,7 +26,8 @@ <div> <? if ($available_rooms) : ?> <section class="contentbox"> - <header><h1><?= _('Passende Räume') ?></h1></header> + <header><h1><?= _('Passende Räume') ?> <?= count($available_rooms) ?> + </h1></header> <section class="selectbox"> <fieldset> <? foreach ($available_rooms as $room): ?> -- GitLab