engelsystem/includes/controller/rooms_controller.php

122 lines
2.6 KiB
PHP
Raw Normal View History

2014-12-22 17:55:20 +01:00
<?php
use Engelsystem\ShiftsFilter;
2017-01-02 15:43:36 +01:00
use Engelsystem\ShiftsFilterRenderer;
/**
* Room controllers for managing everything room related.
*/
/**
* View a room with its shifts.
2017-01-03 03:22:48 +01:00
*
* @return array
*/
2017-01-02 03:57:23 +01:00
function room_controller()
{
global $privileges;
2017-01-02 15:43:36 +01:00
if (!in_array('view_rooms', $privileges)) {
2017-01-02 03:57:23 +01:00
redirect(page_link_to());
}
2017-01-02 15:43:36 +01:00
$request = request();
$room = load_room(false);
if ($room['show'] != 'Y' && !in_array('admin_rooms', $privileges)) {
redirect(page_link_to());
}
2017-01-02 03:57:23 +01:00
$all_shifts = Shifts_by_room($room);
$days = [];
foreach ($all_shifts as $shift) {
2017-01-03 14:12:17 +01:00
$day = date('Y-m-d', $shift['start']);
2017-01-02 15:43:36 +01:00
if (!in_array($day, $days)) {
2017-01-02 03:57:23 +01:00
$days[] = $day;
}
}
2017-01-02 15:43:36 +01:00
$shiftsFilter = new ShiftsFilter(
true,
[$room['RID']],
AngelType_ids()
);
2017-01-03 14:12:17 +01:00
$selected_day = date('Y-m-d');
2017-01-02 15:43:36 +01:00
if (!empty($days)) {
2017-01-02 03:57:23 +01:00
$selected_day = $days[0];
}
if ($request->has('shifts_filter_day')) {
$selected_day = $request->input('shifts_filter_day');
2017-01-02 03:57:23 +01:00
}
2017-01-03 14:12:17 +01:00
$shiftsFilter->setStartTime(parse_date('Y-m-d H:i', $selected_day . ' 00:00'));
$shiftsFilter->setEndTime(parse_date('Y-m-d H:i', $selected_day . ' 23:59'));
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
$shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
$shiftsFilterRenderer->enableDaySelection($days);
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
return [
2017-01-02 15:43:36 +01:00
$room['Name'],
Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
];
}
/**
* Dispatch different room actions.
2017-01-03 03:22:48 +01:00
*
* @return array
*/
2017-01-02 03:57:23 +01:00
function rooms_controller()
{
$request = request();
$action = $request->input('action');
if (!$request->has('action')) {
$action = 'list';
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
switch ($action) {
2017-01-02 15:43:36 +01:00
case 'view':
return room_controller();
2017-01-03 03:22:48 +01:00
case 'list':
default:
redirect(page_link_to('admin_rooms'));
2017-01-02 15:43:36 +01:00
}
}
2014-12-22 17:55:20 +01:00
2017-01-03 03:22:48 +01:00
/**
* @param array $room
* @return string
*/
2017-01-02 03:57:23 +01:00
function room_link($room)
{
return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
}
2017-01-03 03:22:48 +01:00
/**
* @param array $room
* @return string
*/
2017-01-02 03:57:23 +01:00
function room_edit_link($room)
{
return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
2014-12-22 17:55:20 +01:00
}
/**
* Loads room by request param room_id
2017-01-03 03:22:48 +01:00
*
* @param bool $onlyVisible
2017-01-03 03:22:48 +01:00
* @return array
*/
function load_room($onlyVisible = true)
2017-01-02 03:57:23 +01:00
{
2017-01-02 15:43:36 +01:00
if (!test_request_int('room_id')) {
2017-01-02 03:57:23 +01:00
redirect(page_link_to());
}
2017-01-02 15:43:36 +01:00
$room = Room(request()->input('room_id'), $onlyVisible);
2017-01-02 03:57:23 +01:00
if ($room == null) {
redirect(page_link_to());
}
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
return $room;
}