From 0d99c65b4b7dc2e2491c753b45f995fa40ff35eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michaela=20Br=C3=BCckner?= <brueckner@data-quest.de> Date: Sat, 20 Aug 2022 19:26:51 +0200 Subject: [PATCH] re #1327 --- app/controllers/course/room_requests.php | 48 +++++++++++++++---- .../_new_request_form_footer.php | 11 +---- .../room_requests/_room_with_properties.php | 8 ++++ .../course/room_requests/find_by_category.php | 4 +- .../course/room_requests/find_by_roomname.php | 16 +++++-- .../course/room_requests/new_request.php | 6 +-- .../room_requests/request_second_step.php | 1 + 7 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 app/views/course/room_requests/_room_with_properties.php create mode 100644 app/views/course/room_requests/request_second_step.php diff --git a/app/controllers/course/room_requests.php b/app/controllers/course/room_requests.php index c9c7a731fa5..907f6abe9f6 100644 --- a/app/controllers/course/room_requests.php +++ b/app/controllers/course/room_requests.php @@ -49,8 +49,9 @@ class Course_RoomRequestsController extends AuthenticatedController $pagetitle .= _('Verwalten von Raumanfragen'); PageLayout::setTitle($pagetitle); - $this->available_room_categories = ResourceCategory::findByClass_name('Room'); + $this->available_room_categories = ResourceCategory::findByClass_name('Room'); + $this->step = 0; } /** @@ -273,7 +274,7 @@ class Course_RoomRequestsController extends AuthenticatedController $this->request = null; $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 + // time ranges (start date, end date) $this->request->setRangeFields('course', [Context::getId()]); $this->request_time_intervals = $this->request->getTimeIntervals(); @@ -285,25 +286,28 @@ class Course_RoomRequestsController extends AuthenticatedController public function request_first_step_action($request_id) { $this->request_id = $request_id; + $this->step = 1; if (Request::isPost()) { CSRFProtection::verifyUnsafeRequest(); + // either search by room (name) or room category, then go to next step $this->room_name = Request::get('room_name'); + $_SESSION[$request_id]['room_name'] = $this->room_name; $this->search_by_roomname = Request::submitted('search_by_name'); $this->category_id = Request::get('category_id'); + $_SESSION[$request_id]['room_category'] = $this->category_id; $this->search_by_category = Request::submitted('search_by_category'); + // TODO do we need to delete one of these after step 0? // 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 + 'course/room_requests/find_by_roomname/' . $this->request_id . '/' . $this->step ); } else if ($this->category_id != null && $this->search_by_category != null ) { - $_SESSION[$request_id]['room_category'] = $this->category_id; $this->redirect( - 'course/room_requests/find_by_category/' . $this->request_id + 'course/room_requests/find_by_category/' . $this->request_id . '/' . $this->step ); } else { $this->redirect( @@ -314,10 +318,12 @@ class Course_RoomRequestsController extends AuthenticatedController } - public function find_by_roomname_action($request_id) + public function find_by_roomname_action($request_id, $step) { $this->request_id = $request_id; + $this->step = $step; $this->room_name = $_SESSION[$request_id]['room_name']; + $this->available_rooms = RoomManager::findRooms( $this->room_name, null, @@ -329,14 +335,28 @@ class Course_RoomRequestsController extends AuthenticatedController // 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); + $this->selected_room = Resource::find($_SESSION[$request_id]['room_id']); + + // after selecting a room, go to next step + if ((Request::submitted('request_second_step'))) { + $this->selected_room_id = Request::get('selected_room_id'); + $_SESSION[$request_id]['room_id'] = $this->selected_room_id; + $this->redirect( + 'course/room_requests/request_second_step/' . $this->request_id + ); + + } } - public function find_by_category_action($request_id) + public function find_by_category_action($request_id, $step) { $this->request_id = $request_id; + $this->step = $step; + $this->room_category_id = $_SESSION[$request_id]['room_category']; + $this->category = ResourceCategory::find($this->room_category_id); $this->request = RoomRequest::find($this->request_id) ? RoomRequest::find($this->request_id) : new RoomRequest($this->request_id); @@ -346,6 +366,18 @@ class Course_RoomRequestsController extends AuthenticatedController } + public function request_second_step_action($request_id) + { + $this->request_id = $request_id; + $this->step = 2; + //$this->selected_room = Resource::find($_SESSION[$request_id]['room_id']); + + $this->redirect( + 'course/room_requests/find_by_roomname/' . $this->request_id . '/' . $this->step + ); + + } + private function getRoomBookingIcons($available_rooms, $request_id) { $this->request_id = $request_id; diff --git a/app/views/course/room_requests/_new_request_form_footer.php b/app/views/course/room_requests/_new_request_form_footer.php index 202350097da..52ed700de33 100644 --- a/app/views/course/room_requests/_new_request_form_footer.php +++ b/app/views/course/room_requests/_new_request_form_footer.php @@ -4,20 +4,13 @@ _('Zurück'), $controller->link_for('course/room_requests/new_request/' . $request_id), [ - 'step' => $step, 'data-dialog' => 'size=big' ] ) ?> - <?= \Studip\LinkButton::create( - _('Raum auswählen und weiter'), - $controller->link_for('course/room_requests/new_request/' . $request_id), - [ - 'step' => $step +1, - 'data-dialog' => 'size=auto' - ] - ) ?> + <?= \Studip\Button::create(_('Raum auswählen und weiter'), 'request_second_step') ?> + <? endif ?> <?= \Studip\LinkButton::createCancel( diff --git a/app/views/course/room_requests/_room_with_properties.php b/app/views/course/room_requests/_room_with_properties.php new file mode 100644 index 00000000000..ad1bd7554b0 --- /dev/null +++ b/app/views/course/room_requests/_room_with_properties.php @@ -0,0 +1,8 @@ +<label><?= _('Ausgewählter Raum') ?></label> +<? if ($selected_room): ?> + <input type="hidden" name="selected_room_id" + value="<?= htmlReady($selected_room->id) ?>"> + <?= htmlReady($selected_room->name) ?> +<? endif ?> + +<?= var_dump($selected_room); ?> diff --git a/app/views/course/room_requests/find_by_category.php b/app/views/course/room_requests/find_by_category.php index f12239749a8..c2fdfd61bbf 100644 --- a/app/views/course/room_requests/find_by_category.php +++ b/app/views/course/room_requests/find_by_category.php @@ -1,5 +1,5 @@ <form method="post" name="room_request" class="default" - action="<?= $this->controller->link_for('course/room_requests/request_first_step/' . $request_id) ?>" + action="<?= $this->controller->link_for('course/room_requests/request_second_step/' . $request_id . '/' . $this->step) ?>" <?= Request::isXhr() ? 'data-dialog="size=big"' : ''?>> <input type="hidden" name="request_id" value="<?= htmlReady($request_id) ?>"> <?= CSRFProtection::tokenTag() ?> @@ -125,4 +125,4 @@ </section> -<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => 1]) ?> +<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => $step]) ?> diff --git a/app/views/course/room_requests/find_by_roomname.php b/app/views/course/room_requests/find_by_roomname.php index 50b9986e499..bcfaf79020a 100644 --- a/app/views/course/room_requests/find_by_roomname.php +++ b/app/views/course/room_requests/find_by_roomname.php @@ -1,5 +1,5 @@ <form method="post" name="room_request" class="default" - action="<?= $this->controller->link_for('course/room_requests/request_first_step/' . $request_id) ?>" + action="<?= $this->controller->link_for('course/room_requests/find_by_roomname/' . $request_id . '/' . $this->step) ?>" <?= Request::isXhr() ? 'data-dialog="size=big"' : ''?>> <input type="hidden" name="request_id" value="<?= htmlReady($request_id) ?>"> <?= CSRFProtection::tokenTag() ?> @@ -14,6 +14,10 @@ <fieldset> <legend><?= _('Wünschbare Eigenschaften') ?></legend> + <? if ($step == 2) : ?> + <?= $this->render_partial('course/room_requests/_room_with_properties') ?> + <? endif ?> + <? if ($available_room_categories): ?> <label> <?= _('Raumkategorie') ?> @@ -22,7 +26,7 @@ <option value=""><?= _('bitte auswählen') ?></option> <? foreach ($available_room_categories as $rc): ?> <option value="<?= htmlReady($rc->id) ?>" - <?= ($category_id == $rc->id) + <?= ($selected_room->category_id == $rc->id) ? 'selected="selected"' : '' ?>> <?= htmlReady($rc->name) ?> @@ -92,7 +96,10 @@ <?= $available_room_icons[$room->id] ?> <input type="radio" name="selected_room_id" data-activates="button[type='submit'][name='select_room']" - value="<?= htmlReady($room->id) ?>"> + value="<?= htmlReady($room->id) ?>" + <? if ($_SESSION[$request_id]['room_id'] == $room->id) echo 'checked' ?>> + + > <?= htmlReady(mb_substr($room->name, 0, 50)); ?> <? if ($room->properties): ?> <? $property_names = $room->getInfolabelPrperties() @@ -112,5 +119,6 @@ </div> </section> -<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => 1]) ?> + +<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => $step]) ?> <? endif ?> diff --git a/app/views/course/room_requests/new_request.php b/app/views/course/room_requests/new_request.php index 4a6fdbbccb3..cacf8937d7c 100644 --- a/app/views/course/room_requests/new_request.php +++ b/app/views/course/room_requests/new_request.php @@ -8,7 +8,7 @@ <?= $this->render_partial( 'course/room_requests/_new_request_header') ?> -Request ID: <?= $request_id ?> +<?= var_dump($_SESSION[$request_id]) ?> <br/> <section class="resources-grid"> <div> @@ -23,7 +23,7 @@ Request ID: <?= $request_id ?> <option value=""><?= _('bitte auswählen') ?></option> <? foreach ($available_room_categories as $rc): ?> <option value="<?= htmlReady($rc->id) ?>" - <?= ($category_id == $rc->id) + <?= ($_SESSION[$request_id]['room_category'] == $rc->id) ? 'selected="selected"' : '' ?>> <?= htmlReady($rc->name) ?> @@ -88,5 +88,5 @@ Request ID: <?= $request_id ?> </div> </section> -<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => 0]) ?> +<?= $this->render_partial('course/room_requests/_new_request_form_footer', ['step' => $step]) ?> <? endif ?> diff --git a/app/views/course/room_requests/request_second_step.php b/app/views/course/room_requests/request_second_step.php new file mode 100644 index 00000000000..b3d9bbc7f37 --- /dev/null +++ b/app/views/course/room_requests/request_second_step.php @@ -0,0 +1 @@ +<?php -- GitLab