aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-11-14 15:59:29 +0100
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2024-11-14 16:00:00 +0100
commit0cd2632cb7017951f166ff2ebea9b9638e2f52dc (patch)
treeb920dd84ab30375e7c86dd4dda00f8062ea3484d
parent85a06aefd4bf3d1f206ce4331934fdd28dd07fa5 (diff)
revert #4821 on main, re #4821
-rw-r--r--app/controllers/course/room_requests.php361
-rw-r--r--app/controllers/resources/room_request.php1
-rw-r--r--lib/models/resources/ResourceRequest.php13
3 files changed, 170 insertions, 205 deletions
diff --git a/app/controllers/course/room_requests.php b/app/controllers/course/room_requests.php
index d3b29a9..79758d6 100644
--- a/app/controllers/course/room_requests.php
+++ b/app/controllers/course/room_requests.php
@@ -20,6 +20,9 @@ class Course_RoomRequestsController extends AuthenticatedController
{
/**
* Common tasks for all actions
+ *
+ * @param string $action Called action
+ * @param array $args Possible arguments
*/
public function before_filter(&$action, &$args)
{
@@ -33,22 +36,21 @@ class Course_RoomRequestsController extends AuthenticatedController
'admin'
);
$this->course_id = Request::option('cid', $args[0] ?? null);
-
+ $pagetitle = '';
//Navigation in der Veranstaltung:
if (Navigation::hasItem('/course/admin/room_requests')) {
Navigation::activateItem('/course/admin/room_requests');
}
- if (
- !get_object_type($this->course_id, ['sem'])
- || SeminarCategories::GetBySeminarId($this->course_id)->studygroup_mode
- || !$GLOBALS['perm']->have_studip_perm('tutor', $this->course_id)
+ if (!get_object_type($this->course_id, ['sem']) ||
+ SeminarCategories::GetBySeminarId($this->course_id)->studygroup_mode ||
+ !$GLOBALS['perm']->have_studip_perm("tutor", $this->course_id)
) {
throw new Trails\Exception(400);
}
PageLayout::setHelpKeyword('Basis.VeranstaltungenVerwaltenAendernVonZeitenUndTerminen');
- $pagetitle = Course::find($this->course_id)->getFullName() . ' - ';
+ $pagetitle .= Course::find($this->course_id)->getFullName() . ' - ';
$pagetitle .= _('Verwalten von Raumanfragen');
PageLayout::setTitle($pagetitle);
@@ -103,8 +105,9 @@ class Course_RoomRequestsController extends AuthenticatedController
*/
public function info_action($request_id)
{
- $this->request = RoomRequest::find($request_id);
- $this->render_template('course/room_requests/_request.php');
+ $request = RoomRequest::find($request_id);
+ $this->request = $request;
+ $this->render_template('course/room_requests/_request.php', null);
}
/**
@@ -123,24 +126,31 @@ class Course_RoomRequestsController extends AuthenticatedController
_('Hier können Sie Angaben zu gewünschten Raumeigenschaften machen.')
);
- $this->request_id = Request::option(
- 'request_id',
- $request_id ?: md5(uniqid(RoomRequest::class))
- );
+ $this->request_id = $request_id;
+
+ if (Request::submitted('request_id')) {
+ $this->request_id = Request::get('request_id');
+ }
+ if (!$this->request_id) {
+ $this->request_id = md5(uniqid('RoomRequest'));
+ }
// e.g. cycle, course, date
$this->request_range = Request::get('range_str');
// multiple dates
- $this->request_range_ids = Request::getArray('range_ids') ?: $this->fromSession('range_ids') ?? [];
+ $this->request_range_ids = Request::getArray('range_ids') ?: $_SESSION[$this->request_id]['range_ids'] ?? [];
// a single date or whole course
$this->request_range_id = Request::get('range_id', Context::getId());
- $this->toSession('range', $this->request_range ?: $this->fromSession('range') ?? null);
- $this->toSession('range_ids', $this->request_range_ids ?: [$this->request_range_id]);
+ $this->init_session();
+ $_SESSION[$this->request_id]['range'] = $this->request_range ?: $_SESSION[$this->request_id]['range'] ?? null;
+ $_SESSION[$this->request_id]['range_ids'] = $this->request_range_ids ?: [$this->request_range_id];
// look for existing request or create a new one
- $this->request = $this->getRequestObject($this->request_id);
+ $this->request = new RoomRequest($this->request_id);
+ // time ranges (start date, end date)
+ $this->request->setRangeFields($_SESSION[$this->request_id]['range'], $_SESSION[$this->request_id]['range_ids']);
$this->request_time_intervals = $this->request->getTimeIntervals();
}
@@ -165,20 +175,23 @@ class Course_RoomRequestsController extends AuthenticatedController
$this->category_id = Request::get('category_id');
$this->search_by_category = Request::submitted('search_by_category');
- $this->toSession('room_category_id', $this->category_id);
+ if (!isset($_SESSION[$request_id])) {
+ $_SESSION[$request_id] = [];
+ }
+ $_SESSION[$request_id]['room_category_id'] = $this->category_id;
$this->room_name = Request::get('room_name');
$this->search_by_roomname = Request::submitted('search_by_name');
- $this->toSession('room_name', $this->room_name);
+ $_SESSION[$request_id]['room_name'] = $this->room_name;
// user selects a room category OR enters a room name
if ($this->category_id !== null && $this->search_by_category) {
- $this->toSession('search_by', 'category');
+ $_SESSION[$request_id]['search_by'] = 'category';
$this->redirect(
- 'course/room_requests/request_find_available_properties/' . $this->request_id . '/' . $this->step
+ 'course/room_requests/request_find_available_properties/' . $this->request_id . '/' . $this->step . '/category'
);
} elseif ($this->room_name && $this->search_by_roomname) {
- $this->toSession('search_by', 'roomname');
+ $_SESSION[$request_id]['search_by'] = 'roomname';
$this->redirect(
'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/' . $this->step . '/roomname'
);
@@ -205,14 +218,15 @@ class Course_RoomRequestsController extends AuthenticatedController
}
$this->request_id = $request_id;
$this->step = (int)$step;
- $this->room_name = $this->fromSession('room_name');
+ $this->room_name = $_SESSION[$request_id]['room_name'];
- $this->request = $this->getRequestObject($this->request_id);
+ $this->request = new RoomRequest($this->request_id);
+ $this->request->setRangeFields($_SESSION[$this->request_id]['range'], $_SESSION[$this->request_id]['range_ids'] ?? []);
- $search_properties = $this->fromSession('selected_properties');
+ $search_properties = $_SESSION[$request_id]['selected_properties'] ?? [];
- if ($this->fromSession('room_category_id')) {
- $search_properties['room_category_id'] = $this->fromSession('room_category_id');
+ if (!empty($_SESSION[$request_id]['room_category_id'])) {
+ $search_properties['room_category_id'] = $_SESSION[$request_id]['room_category_id'];
}
if (!empty($search_properties['seats'])) {
@@ -237,23 +251,20 @@ class Course_RoomRequestsController extends AuthenticatedController
$this->available_room_icons = $this->getRoomBookingIcons($this->available_rooms);
// selected room and its category
- $this->selected_room = Resource::find($this->fromSession('room_id') ?: $this->request->resource_id);
+ $this->selected_room = Resource::find($_SESSION[$request_id]['room_id'] ?: $this->request->resource_id);
- $this->selected_room_category_id = $this->selected_room->category_id ?? $this->fromSession('room_category_id');
+ $this->selected_room_category_id = $this->selected_room->category_id ?? $_SESSION[$request_id]['room_category_id'] ?? null;
$this->category = $this->selected_room_category_id ? ResourceCategory::find($this->selected_room_category_id) : null;
- $this->toSession('room_category_id', $this->fromSession('room_category_id') ?? $this->selected_room->category_id ?? null);
+ $_SESSION[$request_id]['room_category_id'] = $_SESSION[$request_id]['room_category_id'] ?? $this->selected_room->category_id ?? null;
// after selecting a room, go to next step or stay here if no room was selected at all
if (Request::submitted('select_room')) {
$this->selected_room_id = Request::get('selected_room_id');
$room = Room::find($this->selected_room_id);
-
- $this->toSession([
- 'room_id' => $this->selected_room_id,
- 'room_category_id' => $room->category_id,
- 'select_room' => true,
- ]);
+ $_SESSION[$request_id]['room_id'] = $this->selected_room_id;
+ $_SESSION[$request_id]['room_category_id'] = $room->category_id;
+ $_SESSION[$request_id]['select_room'] = true;
$this->redirect(
'course/room_requests/request_check_properties/' . $this->request_id
);
@@ -262,23 +273,21 @@ class Course_RoomRequestsController extends AuthenticatedController
// we might also search for new rooms and stay within step 1
else if (Request::get('room_name') && Request::submitted('search_by_name')) {
- $this->toSession('room_name', Request::get('room_name'));
+ $_SESSION[$request_id]['room_name'] = Request::get('room_name');
$this->redirect(
'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/' . $this->step
);
return;
}
else if (Request::get('category_id') && Request::submitted('select_properties')) {
- $this->toSession([
- 'search_by' => 'category',
- 'room_category_id' => Request::get('category_id'),
- ]);
+ $_SESSION[$request_id]['search_by'] = 'category';
+ $_SESSION[$request_id]['room_category_id'] = Request::get('category_id');
$this->redirect(
'course/room_requests/request_find_available_properties/' . $this->request_id . '/' . $this->step
);
return;
} else if (Request::submitted('reset_category')) {
- $this->clearSession();
+ $this->init_session();
$this->redirect('course/room_requests/new_request');
return;
}
@@ -288,38 +297,36 @@ class Course_RoomRequestsController extends AuthenticatedController
if (!empty(Request::getArray('selected_properties'))) {
$this->selected_properties = Request::getArray('selected_properties');
} else {
- $this->selected_properties = $this->fromSession('selected_properties');
+ $this->selected_properties = $_SESSION[$request_id]['selected_properties'];
}
- $this->toSession('selected_properties', $this->selected_properties);
- if ($this->fromSession('search_by') === 'roomname') {
- $this->selected_properties = $this->fromSession('selected_properties');
- $this->room = Room::find($this->fromSession('room_id'));
- if (!isset($this->selected_properties['seats'])) {
+ $_SESSION[$request_id]['selected_properties'] = $this->selected_properties;
+ if ($_SESSION[$request_id]['search_by'] === 'roomname') {
+ $this->selected_properties = $_SESSION[$request_id]['selected_properties'] ?? null;
+ $this->room = Room::find($_SESSION[$request_id]['room_id']);
+ if (!isset($_SESSION[$request_id]['selected_properties']['seats'])) {
$this->selected_properties['seats'] = $this->course->admission_turnout ?? Config::get()->RESOURCES_ROOM_REQUEST_DEFAULT_SEATS;
}
- $this->toSession([
- 'selected_properties' => $this->selected_properties,
- 'room_category_id' => $this->selected_room_category_id,
- ]);
+ $_SESSION[$request_id]['selected_properties']['seats'] = $this->selected_properties['seats'];
+ $_SESSION[$request_id]['room_category_id'] = $this->selected_room_category_id;
} else {
// let's find all the properties belonging to the selected category
- $this->room_category_id = $this->fromSession('room_category_id');
+ $this->room_category_id = $_SESSION[$request_id]['room_category_id'];
}
if ($this->category) {
$this->available_properties = $this->category->getRequestableProperties();
}
- $this->preparation_time = $this->fromSession('preparation_time');
- $this->comment = $this->fromSession('comment');
- $this->request->category_id = $this->fromSession('room_category_id');
+ $this->preparation_time = $_SESSION[$request_id]['preparation_time'] ?? null;
+ $this->comment = $_SESSION[$request_id]['comment'] ?? null;
+ $this->request->category_id = $_SESSION[$request_id]['room_category_id'];
// finally we want to show a summary
if (Request::submitted('show_summary')) {
$this->selected_room_id = Request::get('selected_room_id');
- $this->toSession('room_id', $this->selected_room_id);
+ $_SESSION[$request_id]['room_id'] = $this->selected_room_id;
$room = Room::find($this->selected_room_id);
if ($room) {
- $this->toSession('room_category_id', $room->category_id);
+ $_SESSION[$request_id]['room_category_id'] = $room->category_id;
}
$this->redirect('course/room_requests/request_show_summary/' . $this->request_id );
}
@@ -342,27 +349,33 @@ class Course_RoomRequestsController extends AuthenticatedController
$this->request_id = $request_id;
$this->step = (int)$step;
- $this->request = $this->getRequestObject($this->request_id);
+ $this->request = new RoomRequest($this->request_id);
+ $this->request->setRangeFields(
+ $_SESSION[$this->request_id]['range'] ?? null,
+ $_SESSION[$this->request_id]['range_ids'] ?? null
+ );
// let's find all the properties belonging to the selected category
- $this->room_category_id = $this->fromSession('room_category_id') ?? $this->request->category_id;
- $this->room_name = $this->fromSession('room_name');
- $this->selected_room = Resource::find($this->fromSession('room_id') ?? $this->request->resource_id ?? null);
+ $this->room_category_id = $_SESSION[$request_id]['room_category_id'] ?: $this->request->category_id;
+ $this->room_name = $_SESSION[$request_id]['room_name'] ?? '';
+ $this->selected_room = Resource::find($_SESSION[$request_id]['room_id'] ?: $this->request->resource_id);
$this->category = $this->room_category_id ? ResourceCategory::find($this->room_category_id) : '';
$this->available_properties = $this->room_category_id ? $this->category->getRequestableProperties() : '';
- $this->selected_properties = $this->fromSession('selected_properties');
+ $this->selected_properties = $_SESSION[$request_id]['selected_properties'] ?? [];
$this->course = Course::find($this->course_id);
- $this->selected_properties['seats'] = $this->fromSession('selected_properties')['seats']
+ $this->selected_properties['seats'] = $_SESSION[$request_id]['selected_properties']['seats']
?? $this->course->admission_turnout
?: Config::get()->RESOURCES_ROOM_REQUEST_DEFAULT_SEATS;
- $this->preparation_time = $this->fromSession('preparation_time');
- $this->comment = $this->fromSession('comment');
-
+ $this->preparation_time = $_SESSION[$request_id]['preparation_time'] ?? null;
+ $this->comment = $_SESSION[$request_id]['comment'] ?? null;
// when searching for a room name, list found room
- if ($this->room_name) {
+ if (
+ isset($_SESSION[$request_id]['room_name'])
+ && $_SESSION[$request_id]['room_name'] !== ''
+ ) {
$search_properties['room_category_id'] = $this->room_category_id;
$search_properties['seats'] = [
1,
@@ -404,86 +417,79 @@ class Course_RoomRequestsController extends AuthenticatedController
if (Request::submitted('select_room')) {
$this->selected_room_id = Request::get('selected_room_id');
$room = Room::find($this->selected_room_id);
- $this->toSession([
- 'room_id' => $this->selected_room_id,
- 'room_category_id' => $room->category_id,
- 'select_room' => true,
- ]);
-
+ $_SESSION[$request_id]['room_id'] = $this->selected_room_id;
+ $_SESSION[$request_id]['room_category_id'] = $room->category_id;
+ $_SESSION[$request_id]['select_room'] = true;
+ $this->step = 2;
+ $this->request = new RoomRequest($this->request_id);
$this->redirect(
'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/' . $this->step
);
} else if (Request::get('room_name') && Request::submitted('search_by_name')) {
$this->category_id = Request::get('category_id');
-
- $this->toSession([
- 'selected_properties' => $this->selected_properties,
- 'room_category_id' => $this->category_id,
- 'room_name' => Request::get('room_name'),
- ]);
+ $_SESSION[$request_id]['selected_properties'] = $this->selected_properties;
+ $_SESSION[$request_id]['room_category_id'] = $this->category_id;
+ $_SESSION[$request_id]['comment'] = $this->comment;
+ $_SESSION[$request_id]['room_name'] = Request::get('room_name');
+ $this->request = new RoomRequest($this->request_id);
$this->redirect(
- 'course/room_requests/request_find_available_properties/' . $this->request_id . '/1'
+ 'course/room_requests/request_find_available_properties/' . $this->request_id . '/1/category'
);
} else if (Request::submitted('search_rooms')) {
$this->category_id = Request::get('category_id');
-
- $this->toSession([
- 'room_category_id' => $this->category_id,
- 'selected_properties' => $this->selected_properties,
- 'room_name' => '',
- ]);
+ $_SESSION[$request_id]['room_category_id'] = $this->category_id;
+ $_SESSION[$request_id]['selected_properties'] = $this->selected_properties;
+ $_SESSION[$request_id]['room_name'] = '';
// no min number of seats
if (
- (
- !isset($this->selected_properties['seats'])
- || $this->selected_properties['seats'] < 1
- )
- && $this->fromSession('search_by') === 'category'
+ (!$_SESSION[$request_id]['selected_properties']['seats'] || $_SESSION[$request_id]['selected_properties']['seats'] < 1)
+ && $_SESSION[$request_id]['search_by'] === 'category'
) {
PageLayout::postError(
_('Die Mindestanzahl der Sitzplätze beträgt 1!')
);
$this->redirect(
- 'course/room_requests/request_find_available_properties/' . $this->request_id . '/1'
+ 'course/room_requests/request_find_available_properties/' . $request_id . '/1/category'
);
} else {
+ $this->step = 2;
+ $this->request = new RoomRequest($this->request_id);
$this->redirect(
- 'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/2'
+ 'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/' . $this->step
);
}
} else if (Request::submitted('reset_category')) {
//Delete all selected properties from the session since the category is reset
- $this->clearSession();
+ $this->init_session();
$this->redirect('course/room_requests/request_find_available_properties/' . $this->request_id . '/1');
} else if (Request::submitted('search_by_category')) {
if (Request::get('category_id') === '0') {
- $this->clearSession('room_category_id');
+ $_SESSION[$request_id]['room_category_id'] = '';
} else {
- $this->toSession('room_category_id', Request::get('category_id'));
+ $_SESSION[$request_id]['room_category_id'] = Request::get('category_id');
}
+
$this->redirect(
- 'course/room_requests/request_find_available_properties/' . $this->request_id . '/1'
+ 'course/room_requests/request_find_available_properties/' . $this->request_id . '/1' . '/category'
);
} else if (Request::submitted('show_summary')) {
+ $this->request = new RoomRequest($this->request_id);
$this->selected_room_id = Request::get('selected_room_id');
$room = Room::find($this->selected_room_id);
-
- $this->toSession([
- 'room_id' => $this->selected_room_id,
- 'room_category_id' => $room->category_id ?? $this->fromSession('room_category_id'),
- 'selected_properties' => $this->selected_properties,
- ]);
-
+ $_SESSION[$request_id]['room_id'] = $this->selected_room_id;
+ $_SESSION[$request_id]['room_category_id'] = $room->category_id ?? $_SESSION[$request_id]['room_category_id'];
+ $_SESSION[$request_id]['selected_properties'] = $this->selected_properties;
$this->redirect('course/room_requests/request_show_summary/' . $this->request_id );
} else {
- $room = Room::find($this->fromSession('room_id'));
- $this->toSession('room_category_id', $room->category_id);
-
+ $room = Room::find($_SESSION[$request_id]['room_id']);
+ $this->step = 2;
+ $this->request = new RoomRequest($this->request_id);
+ $_SESSION[$request_id]['room_category_id'] = $room->category_id;
$this->redirect(
- 'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/2'
+ 'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/' . $this->step
);
}
@@ -493,6 +499,8 @@ class Course_RoomRequestsController extends AuthenticatedController
* Show a summary of all request properties before storing; we have the possibility of going back and
* editing if necessary. This action is also used for editing a request via action menu
* @param String $request_id ID of the request
+ * @return void
+ *
*/
public function request_show_summary_action($request_id)
{
@@ -506,40 +514,39 @@ class Course_RoomRequestsController extends AuthenticatedController
$this->step = 3;
if (Request::submitted('clear_cache')) {
- $this->clearSession();
+ $_SESSION[$request_id] = [];
}
- $this->request = $this->getRequestObject($request_id);
+ $this->request = new RoomRequest($this->request_id);
+ $this->request->setRangeFields(
+ $_SESSION[$this->request_id]['range'] ?? '',
+ $_SESSION[$this->request_id]['range_ids'] ?? []
+ );
- $this->selected_room_category = ResourceCategory::find($this->fromSession('room_category_id') ?? $this->request->category_id);
- $this->selected_room = Resource::find($this->fromSession('room_id') ?? $this->request->resource_id);
+ $this->selected_room_category = ResourceCategory::find($_SESSION[$request_id]['room_category_id'] ?? $this->request->category_id);
+ $this->selected_room = Resource::find($_SESSION[$request_id]['room_id'] ?? $this->request->resource_id);
- $this->room_id = $this->fromSession('room_id') ?? $this->request->resource_id;
+ $this->room_id = $_SESSION[$request_id]['room_id'] ?? $this->request->resource_id;
$this->available_properties = $this->selected_room_category->getRequestableProperties();
- $this->selected_properties = $this->fromSession('selected_properties');
+ $this->selected_properties = $_SESSION[$request_id]['selected_properties'] ?? [];
$this->request_properties = $this->request->properties;
// either properties from stored request or those from session
- if (
- count($this->request_properties) > 0
- && count($this->fromSession('selected_properties')) === 0
- ) {
+ if ($this->request_properties && empty($_SESSION[$request_id]['selected_properties'])) {
foreach ($this->request_properties as $property) {
$this->selected_properties[$property->name] = $property->state;
}
- $this->toSession('selected_properties', $this->selected_properties);
+ $_SESSION[$request_id]['selected_properties'] = $this->selected_properties;
}
$this->preparation_time = intval($this->request->preparation_time / 60);
$this->reply_lecturers = $this->request->reply_recipients === ResourceRequest::REPLY_LECTURER;
$this->comment = $this->request->comment;
- $this->toSession([
- 'search_by' => $this->selected_room ? 'roomname' : 'category',
- 'room_category_id' => $this->selected_room_category->id,
- 'room_id' => $this->selected_room->id ?? null,
- ]);
+ $_SESSION[$request_id]['search_by'] = $this->selected_room ? 'roomname' : 'category';
+ $_SESSION[$request_id]['room_category_id'] = $this->selected_room_category->id;
+ $_SESSION[$request_id]['room_id'] = $this->selected_room ? $this->selected_room->id : '';
}
public function store_request_action($request_id)
@@ -551,11 +558,16 @@ class Course_RoomRequestsController extends AuthenticatedController
}
$this->request_id = $request_id;
- $this->request = $this->getRequestObject($this->request_id);
+ $this->request = new RoomRequest($this->request_id);
+ $this->request->setRangeFields($_SESSION[$this->request_id]['range'], $_SESSION[$this->request_id]['range_ids']);
if (Request::isPost()) {
CSRFProtection::verifyUnsafeRequest();
+ if ($this->request->isNew()) {
+ $this->request->user_id = $this->current_user->id;
+ }
+
$this->preparation_time = Request::int('preparation_time', 0);
$this->request->preparation_time = $this->preparation_time * 60;
$this->request->comment = Request::get('comment');
@@ -565,10 +577,11 @@ class Course_RoomRequestsController extends AuthenticatedController
} else {
$this->request->reply_recipients = ResourceRequest::REPLY_REQUESTER;
}
- $this->request->category_id = $this->fromSession('room_category_id') ?? $this->request->category_id;
+ $this->request->category_id = $_SESSION[$request_id]['room_category_id'] ?: $this->request->category_id;
- $this->request->resource_id = $this->fromSession('room_id') ?? $this->request->resource_id;
+ $this->request->resource_id = $_SESSION[$request_id]['room_id'] ?: $this->request->resource_id;
$this->request->course_id = Context::getId();
+ $this->request->last_modified_by = $this->current_user->id;
if ($this->request->closed != ResourceRequest::STATE_OPEN) {
PageLayout::postInfo(_('Die Raumanfrage wurde wieder geöffnet und damit erneut gestellt.'));
@@ -578,14 +591,16 @@ class Course_RoomRequestsController extends AuthenticatedController
$this->request->store();
//Store the properties:
- foreach ($this->fromSession('selected_properties') as $name => $state) {
- if (!empty($state)) {
- $this->request->setProperty($name, $state);
+ if (isset($_SESSION[$request_id]['selected_properties'])) {
+ foreach ($_SESSION[$request_id]['selected_properties'] as $name => $state) {
+ if (!empty($state)) {
+ $this->request->setProperty($name, $state);
+ }
}
}
// once stored, we can delete the session data for this request
- $this->clearSession();
+ $_SESSION[$this->request_id] = [];
PageLayout::postSuccess(_('Die Anfrage wurde gespeichert!'));
$this->relocate('course/timesrooms/');
@@ -636,77 +651,39 @@ class Course_RoomRequestsController extends AuthenticatedController
/**
* delete one room request
*/
- public function delete_action(RoomRequest $request)
+ public function delete_action($request_id)
{
+ $request = RoomRequest::find($request_id);
+ if (!$request) {
+ throw new Trails\Exception(403);
+ }
if (Request::isGet()) {
- PageLayout::postQuestion(
- sprintf(
- _('Möchten Sie die Raumanfrage "%s" löschen?'),
- htmlReady($request->getTypeString())
- ),
- $this->url_for('course/room_requests/delete/' . $request->id)
- );
+ PageLayout::postQuestion(sprintf(
+ _('Möchten Sie die Raumanfrage "%s" löschen?'),
+ htmlReady($request->getTypeString())), $this->url_for('course/room_requests/delete/' . $request_id));
} else {
CSRFProtection::verifyUnsafeRequest();
- if (Request::submitted('yes') && $request->delete()) {
- PageLayout::postSuccess("Die Raumanfrage wurde gelöscht.");
+ if (Request::submitted('yes')) {
+ if ($request->delete()) {
+ PageLayout::postSuccess("Die Raumanfrage wurde gelöscht.");
+ }
}
}
$this->redirect('course/timesrooms/index');
}
-
- private function fromSession(string $key): mixed
- {
- if (!isset($this->request_id)) {
- throw new RuntimeException('Request ID not set.');
- }
-
- $defaults = [
- 'range_ids' => [],
- 'select_room' => false,
- 'selected_properties' => [],
- ];
- return $_SESSION[$this->request_id][$key] ?? $defaults[$key] ?? null;
- }
-
- private function toSession(array|string $data, mixed $value = null): void
- {
- if (!isset($this->request_id)) {
- throw new RuntimeException('Request ID not set.');
- }
-
- if (!is_array($data) && func_num_args() === 2) {
- $data = [$data => $value];
- }
-
- foreach ($data as $key => $value) {
- $_SESSION[$this->request_id][$key] = $value;
- }
- }
-
- private function clearSession(string $key = null): void
- {
- if (!isset($this->request_id)) {
- throw new RuntimeException('Request ID not set.');
- }
-
- if ($key === null) {
- unset($_SESSION[$this->request_id]);
- } elseif (isset($_SESSION[$this->request_id][$key])) {
- unset($_SESSION[$this->request_id][$key]);
- }
- }
-
- private function getRequestObject(?string $request_id): RoomRequest
+ private function init_session()
{
- $request = new RoomRequest($request_id);
-
- $request->setRangeFields(
- $this->fromSession('range'),
- $this->fromSession('range_ids')
+ $_SESSION[$this->request_id] = array_merge(
+ $_SESSION[$this->request_id] ?? [],
+ [
+ 'search_by' => '',
+ 'room_category_id' => '',
+ 'room_id' => '',
+ 'room_name' => '',
+ 'select_room' => false,
+ 'selected_properties' => [],
+ ]
);
-
- return $request;
}
}
diff --git a/app/controllers/resources/room_request.php b/app/controllers/resources/room_request.php
index 113c5d3..7f7cdbe 100644
--- a/app/controllers/resources/room_request.php
+++ b/app/controllers/resources/room_request.php
@@ -1816,6 +1816,7 @@ class Resources_RoomRequestController extends AuthenticatedController
$this->reply_comment = Request::get('reply_comment');
$this->request->reply_comment = $this->reply_comment;
$this->request->closed = '3';
+ $this->request->last_modified_by = $this->current_user->id;
if ($this->request->isDirty()) {
if ($this->request->store()) {
$this->show_form = false;
diff --git a/lib/models/resources/ResourceRequest.php b/lib/models/resources/ResourceRequest.php
index b0334a4..ed10e69 100644
--- a/lib/models/resources/ResourceRequest.php
+++ b/lib/models/resources/ResourceRequest.php
@@ -134,7 +134,6 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
$config['registered_callbacks']['before_store'][] = 'validate';
}
$config['registered_callbacks']['after_create'][] = 'cbLogNewRequest';
- $config['registered_callbacks']['before_store'][] = 'cbBeforeStore';
$config['registered_callbacks']['after_store'][] = 'cbAfterStore';
$config['registered_callbacks']['after_delete'][] = 'cbAfterDelete';
@@ -548,18 +547,6 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
}
/**
- * A callback method that sets the users connection before store.
- */
- public function cbBeforeStore()
- {
- if ($this->isNew() && !$this->user_id) {
- $this->user_id = User::findCurrent()->id;
- }
-
- $this->last_modified_by = User::findCurrent()->id;
- }
-
- /**
* A callback method that send a mail
* when a new request has been udpated.
*/