Newer
Older
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
<?php
/**
* search.php - contains Resources_SearchController
*
* 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 Moritz Strohm <strohm@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @copyright 2017-2019
* @category Stud.IP
* @since 4.5
*/
/**
* Resources_SearchController contains search actions for resources.
*/
class Resources_SearchController extends AuthenticatedController
{
public function rooms_action()
{
if (!$GLOBALS['perm']->have_perm('autor')) {
throw new AccessDeniedException();
}
PageLayout::setTitle(
_('Raumsuche')
);
if (Navigation::hasItem('/search/rooms')) {
Navigation::activateItem('/search/rooms');
}
//Build sidebar:
$sidebar = Sidebar::get();
$room_search_widget = new RoomSearchWidget(
URLHelper::getLink(
'dispatch.php/resources/search/rooms'
)
);
$sidebar->addWidget($room_search_widget);
$resource_tree_widget = new RoomSearchTreeWidget(
Location::findAll()
);
$search_ressource = explode('_', Request::get('special__building_location'));
if ($room_search_widget->searchResetRequested() || count($search_ressource) != 2) {
$resource_tree_widget->setCurrentResourceId();
} else {
$resource_tree_widget->setCurrentResourceId($search_ressource[1]);
}
$sidebar->addWidget($resource_tree_widget);
$this->current_user = User::findCurrent();
Moritz Strohm
committed
$room_clipboard_widget = new RoomClipboardWidget();
$sidebar->addWidget($room_clipboard_widget);
$this->clipboard_widget_id = $room_clipboard_widget->getClipboardWidgetId();
$this->tree_selected_resource = Request::get('tree_selected_resource');
$this->form_submitted = false;
if ($this->tree_selected_resource) {
$resource = Resource::find($this->tree_selected_resource);
if (!$resource) {
PageLayout::postError(
_('Die gewählte Ressource wurde nicht in der Datenbank gefunden!')
);
return;
}
$resource = $resource->getDerivedClassInstance();
if ($resource) {
$this->redirect(
$resource->getActionURL('show')
);
}
} else {
$this->form_submitted = $room_search_widget->searchRequested();
$this->rooms = $room_search_widget->getResults();
$messages = PageLayout::getMessages();
$this->has_errors = false;
foreach ($messages as $message) {
if ($message->class == 'error') {
$this->has_errors = true;
}
PageLayout::postMessage($message);
}
Moritz Strohm
committed
$this->booking_plan_action_params = [];
if ($this->form_submitted) {
$actions = new ShareWidget();
$actions->addCopyableLink(
_('URL zur Suche kopieren'),
$_SERVER['REQUEST_URI'],
Icon::create('group')
);
$sidebar->addWidget($actions);
Moritz Strohm
committed
//Check if the time range criteria has been set.
//If so, set the begin date as parameter for the
//booking plan action URL.
$criteria = $room_search_widget->getSelectedCriteria();
if (isset($criteria['special__time_range']) && $criteria['special__time_range']) {
$begin = $criteria['special__time_range']['range']['begin'];
if ($begin instanceof DateTime) {
$this->booking_plan_action_params['defaultDate'] = $begin->format('Y-m-d');
}
}
}