engelsystem/includes/controller/public_dashboard_controller...

100 lines
2.5 KiB
PHP
Raw Normal View History

2017-12-11 22:26:36 +01:00
<?php
/**
* Loads all data for the public dashboard
2017-12-25 23:12:52 +01:00
*
* @return array
2017-12-11 22:26:36 +01:00
*/
function public_dashboard_controller()
{
2017-12-12 21:57:57 +01:00
$stats = [
'needed-3-hours' => stats_angels_needed_three_hours(),
2017-12-25 23:12:52 +01:00
'needed-night' => stats_angels_needed_for_nightshifts(),
2017-12-12 21:57:57 +01:00
'angels-working' => stats_currently_working(),
2017-12-25 23:12:52 +01:00
'hours-to-work' => stats_hours_to_work()
2017-12-12 21:57:57 +01:00
];
2017-12-25 23:12:52 +01:00
$free_shifts_source = Shifts_free(time(), time() + 12 * 60 * 60);
$free_shifts = [];
foreach ($free_shifts_source as $shift) {
$free_shift = public_dashboard_controller_free_shift($shift);
2017-12-25 23:12:52 +01:00
if (count($free_shift['needed_angels']) > 0) {
$free_shifts[] = $free_shift;
}
}
2017-12-25 23:12:52 +01:00
2017-12-11 22:26:36 +01:00
return [
__('Public Dashboard'),
2017-12-12 21:57:57 +01:00
public_dashboard_view($stats, $free_shifts)
2017-12-11 22:26:36 +01:00
];
}
/**
2017-12-25 21:29:00 +01:00
* Gathers information for free shifts to display.
*
2017-12-25 23:12:52 +01:00
* @param array $shift
* @return array
*/
function public_dashboard_controller_free_shift($shift)
{
$shifttype = ShiftType($shift['shifttype_id']);
$room = Room($shift['RID']);
2017-12-25 23:12:52 +01:00
$free_shift = [
2017-12-25 23:12:52 +01:00
'SID' => $shift['SID'],
'style' => 'default',
'start' => date('H:i', $shift['start']),
'end' => date('H:i', $shift['end']),
'duration' => round(($shift['end'] - $shift['start']) / 3600),
'shifttype_name' => $shifttype['name'],
2017-12-25 23:12:52 +01:00
'title' => $shift['title'],
'room_name' => $room['Name'],
'needed_angels' => []
];
2017-12-25 23:12:52 +01:00
if (time() + 3 * 60 * 60 > $shift['start']) {
$free_shift['style'] = 'warning';
}
if (time() > $shift['start']) {
$free_shift['style'] = 'danger';
}
2017-12-25 23:12:52 +01:00
$free_shift['needed_angels'] = public_dashboard_needed_angels($shift['NeedAngels']);
2017-12-25 23:12:52 +01:00
return $free_shift;
}
/**
2017-12-25 21:29:00 +01:00
* Gathers information for needed angels on dashboard
*
2017-12-25 23:12:52 +01:00
* @param array $needed_angels
* @return array
*/
function public_dashboard_needed_angels($needed_angels)
{
$result = [];
foreach ($needed_angels as $needed_angel) {
$need = $needed_angel['count'] - $needed_angel['taken'];
if ($need > 0) {
$angeltype = AngelType($needed_angel['TID']);
if ($angeltype['show_on_dashboard']) {
$result[] = [
2017-12-25 23:12:52 +01:00
'need' => $need,
'angeltype_name' => $angeltype['name']
];
}
}
}
return $result;
}
/**
* Returns url to public dashboard
2017-12-25 23:12:52 +01:00
*
* @return string
*/
function public_dashboard_link()
{
return page_link_to('public-dashboard');
}