aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/course/room_requests.php
blob: c7586f66d686aa9f664051577011364f774e47ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<?php
# Lifter010: TODO
/**
 * room_requests.php - administration of room requests
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      André Noack <noack@data-quest.de>
 * @author      Moritz Strohm <strohm@data-quest.de>
 * @author      Michaela Brückner <brueckner@data-quest.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @package     admin
 */

class Course_RoomRequestsController extends AuthenticatedController
{
    protected $_autobind = true;

    /**
     * Common tasks for all actions
     *
     * @param string $action Called action
     * @param array  $args   Possible arguments
     */
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        if (!Config::get()->RESOURCES_ALLOW_ROOM_REQUESTS) {
            throw new AccessDeniedException(
                _('Das Erstellen von Raumanfragen ist nicht erlaubt!')
            );
        }

        $this->current_user = User::findCurrent();
        $this->user_is_global_resource_admin = ResourceManager::userHasGlobalPermission(
            $this->current_user,
            '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)
        ) {
            throw new Trails\Exception(400);
        }

        PageLayout::setHelpKeyword('Basis.VeranstaltungenVerwaltenAendernVonZeitenUndTerminen');
        $pagetitle .= Course::find($this->course_id)->getFullName() . ' - ';
        $pagetitle .= _('Verwalten von Raumanfragen');
        PageLayout::setTitle($pagetitle);

        $this->available_room_categories = ResourceCategory::findByClass_name(Room::class);
        $this->step = 0;
        $this->max_preparation_time = Config::get()->RESOURCES_MAX_PREPARATION_TIME;
    }

    /**
     * Display the list of room requests
     */
    public function index_action()
    {
        $this->url_params = [];
        if (Request::get('origin') !== null) {
            $this->url_params['origin'] = Request::get('origin');
        }

        $this->room_requests = RoomRequest::findBySQL(
            'course_id = :course_id
            ORDER BY course_id, metadate_id, termin_id',
            [
                'course_id' => $this->course_id
            ]
        );
        $this->request_id = Request::option('request_id');

        $actions = new ActionsWidget();
        $actions->addLink(
            _('Neue Raumanfrage erstellen'),
            $this->url_for('course/room_requests/new'),
            Icon::create('add', 'clickable')
        );
        Sidebar::get()->addWidget($actions);

        if ($GLOBALS['perm']->have_studip_perm('admin', $this->course_id)) {
            $widget = new CourseManagementSelectWidget();
            Sidebar::Get()->addWidget($widget);
        }
    }


    /**
     * Show information about a request
     *
     * @param String $request_id Id of the request
     */
    public function info_action($request_id)
    {
        $request = RoomRequest::find($request_id);
        $this->request = $request;
        $this->render_template('course/room_requests/_request.php', null);
    }

    /**
     * Start point to creating a new request
     */
    public function new_request_action($request_id = '')
    {
        Helpbar::get()->addPlainText(
            _('Information'),
            _('Hier können Sie Angaben zu gewünschten Raumeigenschaften machen.')
        );

        $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') ?: $_SESSION[$this->request_id]['range_ids'] ?? [];
        // a single date or whole course
        $this->request_range_id = Request::get('range_id', Context::getId());

        $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 = 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();
    }

    /**
     * Step 1: Either selecting a room category or searching for a room name initially
     * @param String $request_id ID of the request
     */
    public function request_first_step_action($request_id)
    {
        $this->request_id = $request_id;

        if (Request::isPost()) {
            CSRFProtection::verifyUnsafeRequest();

            $this->step = 1;

            $this->category_id = Request::get('category_id');
            $this->search_by_category = Request::submitted('search_by_category');
            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');
            $_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) {
                $_SESSION[$request_id]['search_by'] = 'category';
                $this->redirect(
                    'course/room_requests/request_find_available_properties/' . $this->request_id . '/' . $this->step . '/category'
                );
            } elseif ($this->room_name && $this->search_by_roomname) {
                $_SESSION[$request_id]['search_by'] = 'roomname';
                $this->redirect(
                    'course/room_requests/request_find_matching_rooms/' . $this->request_id . '/' . $this->step . '/roomname'
                );
            } else {
                $this->redirect(
                    'course/room_requests/new_request/' . $this->request_id
                );
            }
        }
    }

    /**
     * Searching for (a) matching room(s) via room name, e.g. 'hör%'
     * @param String $request_id ID of the request
     * @param String $step
     * @return void
     */
    public function request_find_matching_rooms_action($request_id, $step)
    {
        $this->request_id = $request_id;
        $this->step = (int)$step;
        $this->room_name = $_SESSION[$request_id]['room_name'];

        $this->request = new RoomRequest($this->request_id);
        $this->request->setRangeFields($_SESSION[$this->request_id]['range'], $_SESSION[$this->request_id]['range_ids'] ?? []);

        $search_properties = $_SESSION[$request_id]['selected_properties'] ?? [];

        if (!empty($_SESSION[$request_id]['room_category_id'])) {
            $search_properties['room_category_id'] = $_SESSION[$request_id]['room_category_id'];
        }

        if (!empty($search_properties['seats'])) {
            //The seats property value is a minimum.
            $search_properties['seats'] = [
                $search_properties['seats'],
                null
            ];
        }

        // find rooms matching to selected properties
        $this->available_rooms = RoomManager::findRooms(
            $this->room_name,
            null,
            null,
            $search_properties,
            [],
            'name ASC, mkdate ASC'
        );

        // small icons in front of room name to show whether they are bookable or not
        $this->available_room_icons = $this->getRoomBookingIcons($this->available_rooms);

        // selected room and its category
        $this->selected_room = Resource::find($_SESSION[$request_id]['room_id'] ?: $this->request->resource_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;

        $_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);
            $_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
            );
            return;
        }

        // we might also search for new rooms and stay within step 1
        else if (Request::get('room_name') && Request::submitted('search_by_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')) {
            $_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->init_session();
            $this->redirect('course/room_requests/new_request');
            return;
        }

        // for step 2: after choosing a specific room OR searching via properties
        if ($this->step === 2) {
            if (!empty(Request::getArray('selected_properties'))) {
                $this->selected_properties = Request::getArray('selected_properties');
            } else {
                $this->selected_properties =  $_SESSION[$request_id]['selected_properties'];
            }
            $_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;
                }
                $_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 = $_SESSION[$request_id]['room_category_id'];
            }

            if ($this->category) {
                $this->available_properties = $this->category->getRequestableProperties();
            }
            $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');
                $_SESSION[$request_id]['room_id'] = $this->selected_room_id;
                $room = Room::find($this->selected_room_id);
                if ($room) {
                    $_SESSION[$request_id]['room_category_id'] = $room->category_id;
                }
                $this->redirect('course/room_requests/request_show_summary/' . $this->request_id );
            }
        }
    }

    /**
     * Searching for (a) matching room(s) by initially selecting a room category, e.g. 'Hörsaal'
     * @param String $request_id ID of the request
     * @param String $step
     * @return void
     */
    public function request_find_available_properties_action($request_id, $step)
    {
        $this->request_id = $request_id;
        $this->step = (int)$step;

        $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 = $_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 = $_SESSION[$request_id]['selected_properties'] ?? [];

        $this->course = Course::find($this->course_id);
        $this->selected_properties['seats'] = $_SESSION[$request_id]['selected_properties']['seats']
            ?? $this->course->admission_turnout
            ?: Config::get()->RESOURCES_ROOM_REQUEST_DEFAULT_SEATS;

        $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 (
            isset($_SESSION[$request_id]['room_name'])
            && $_SESSION[$request_id]['room_name'] !== ''
        ) {
            $search_properties['room_category_id'] = $this->room_category_id;
            $search_properties['seats'] = [
                1,
                null
            ];

            $this->available_rooms = RoomManager::findRooms(
                $this->room_name,
                null,
                null,
                $search_properties,
                [],
                'name ASC, mkdate ASC'
            );

            // small icons in front of room name to show whether they are bookable or not
            $this->available_room_icons = $this->getRoomBookingIcons($this->available_rooms);
        }

    }

    /**
     * Check desired properties for a room category to go to step 2
     * @param String $request_id ID of the request
     * @return void
     *
     */
    public function request_check_properties_action($request_id)
    {
        $this->request_id = $request_id;
        $this->selected_properties = Request::getArray('selected_properties');
        // select a room, search for a room name or search for rooms matching properties
        if (Request::submitted('select_room')) {
            $this->selected_room_id = Request::get('selected_room_id');
            $room = Room::find($this->selected_room_id);
            $_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');
            $_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/category'
            );

        } else if (Request::submitted('search_rooms')) {
            $this->category_id = Request::get('category_id');
            $_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 (
                (!$_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/' . $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 . '/' . $this->step
                    );
            }
        } else if (Request::submitted('reset_category')) {
            //Delete all selected properties from the session since the category is reset
            $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') {
                $_SESSION[$request_id]['room_category_id'] = '';
            } else {
                $_SESSION[$request_id]['room_category_id'] = Request::get('category_id');
            }

            $this->redirect(
                '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);
            $_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($_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 . '/' . $this->step
            );
        }

    }

    /**
     * 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)
    {
        $this->request_id = $request_id;
        $this->step = 3;

        if (Request::submitted('clear_cache')) {
            $_SESSION[$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($_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 = $_SESSION[$request_id]['room_id'] ?? $this->request->resource_id;
        $this->available_properties = $this->selected_room_category->getRequestableProperties();

        $this->selected_properties = $_SESSION[$request_id]['selected_properties'] ?? [];
        $this->request_properties = $this->request->properties;

        // either properties from stored request or those from session
        if ($this->request_properties && empty($_SESSION[$request_id]['selected_properties'])) {
            foreach ($this->request_properties as $property) {
                $this->selected_properties[$property->name] = $property->state;
            }
            $_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;

        $_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)
    {
        $this->request_id = $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();

            $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');

            if (Request::get('reply_lecturers')) {
                $this->request->reply_recipients = ResourceRequest::REPLY_LECTURER;
            } else {
                $this->request->reply_recipients = ResourceRequest::REPLY_REQUESTER;
            }
            $this->request->category_id = $_SESSION[$request_id]['room_category_id'] ?: $this->request->category_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;

            $this->request->store();

            //Store the 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
            $_SESSION[$this->request_id] = [];

            PageLayout::postSuccess(_('Die Anfrage wurde gespeichert!'));
            $this->relocate('course/timesrooms/');
        }
    }

    /**
     * Store a request and its properties
     * @param string $request ID of the request
     * @param array $properties desired properties
     * @return void
     */
    private function storeRequest($request, $properties)
    {
        // once stored, we can delete the session data for this request
        $request->store();
        $_SESSION[$request->id] = [];

        //Store the properties:
        foreach ($properties as $name => $state) {
            $request->setProperty($name, $state);
        }
    }

    /**
     * @param Room[] $available_rooms
     * @return array
     */
    private function getRoomBookingIcons(array $available_rooms)
    {
        $icons = [];

        $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) {
                $icons[$room->id] = Icon::create('check-circle', Icon::ROLE_STATUS_GREEN)->asImg([
                    'class' => 'text-bottom',
                    'title' => _('freier Raum'),
                ]);
            } elseif ($request_dates_booked < count($request_time_intervals)) {
                $icons[$room->id] = Icon::create('exclaim-circle', Icon::ROLE_STATUS_YELLOW)->asImg([
                    'class' => 'text-bottom',
                    'title' => _('teilweise belegter Raum')
                ]);
            } else {
                $icons[$room->id] = Icon::create('exclaim-circle', Icon::ROLE_STATUS_RED)->asImg([
                    'class' => 'text-bottom',
                    'title' => _('belegter Raum')
                ]);
            }
        }
        return $icons;
    }

    /**
     * delete one room request
     */
    public function delete_action(RoomRequest $request)
    {
        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));
        } else {
            CSRFProtection::verifyUnsafeRequest();
            if (Request::submitted('yes')) {
                if ($request->delete()) {
                    PageLayout::postSuccess("Die Raumanfrage wurde gelöscht.");
                }
            }
        }

        $this->redirect('course/timesrooms/index');
    }

    private function init_session()
    {
        $_SESSION[$this->request_id] = array_merge(
            $_SESSION[$this->request_id] ?? [],
            [
                'search_by'           => '',
                'room_category_id'    => '',
                'room_id'             => '',
                'room_name'           => '',
                'select_room'         => false,
                'selected_properties' => [],
            ]
        );
    }
}