You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.6 KiB
PHTML

<?php
use Engelsystem\ShiftsFilter;
8 years ago
use Engelsystem\ShiftsFilterRenderer;
/**
* Room controllers for managing everything room related.
*/
/**
* View a room with its shifts.
*
* @return array
*/
8 years ago
function room_controller()
{
global $privileges;
8 years ago
if (!in_array('view_rooms', $privileges)) {
8 years ago
redirect(page_link_to());
}
8 years ago
$request = request();
$room = load_room(false);
if ($room['show'] != 'Y' && !in_array('admin_rooms', $privileges)) {
redirect(page_link_to());
}
8 years ago
$all_shifts = Shifts_by_room($room);
$days = [];
foreach ($all_shifts as $shift) {
$day = date('Y-m-d', $shift['start']);
8 years ago
if (!in_array($day, $days)) {
8 years ago
$days[] = $day;
}
}
8 years ago
$shiftsFilter = new ShiftsFilter(
true,
[$room['RID']],
AngelType_ids()
);
$selected_day = date('Y-m-d');
8 years ago
if (!empty($days)) {
8 years ago
$selected_day = $days[0];
}
if ($request->has('shifts_filter_day')) {
$selected_day = $request->input('shifts_filter_day');
8 years ago
}
$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'));
8 years ago
8 years ago
$shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
$shiftsFilterRenderer->enableDaySelection($days);
8 years ago
8 years ago
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
8 years ago
8 years ago
return [
8 years ago
$room['Name'],
Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
];
}
/**
* Dispatch different room actions.
*
* @return array
*/
8 years ago
function rooms_controller()
{
$request = request();
$action = $request->input('action');
if (!$request->has('action')) {
$action = 'list';
8 years ago
}
8 years ago
switch ($action) {
8 years ago
case 'view':
return room_controller();
case 'list':
default:
redirect(page_link_to('admin_rooms'));
8 years ago
}
}
/**
* @param array $room
* @return string
*/
8 years ago
function room_link($room)
{
return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
}
/**
* @param array $room
* @return string
*/
8 years ago
function room_edit_link($room)
{
return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
}
/**
* Loads room by request param room_id
*
* @param bool $onlyVisible
* @return array
*/
function load_room($onlyVisible = true)
8 years ago
{
8 years ago
if (!test_request_int('room_id')) {
8 years ago
redirect(page_link_to());
}
8 years ago
$room = Room(request()->input('room_id'), $onlyVisible);
8 years ago
if ($room == null) {
redirect(page_link_to());
}
8 years ago
8 years ago
return $room;
}