diff options
author | msquare <msquare@notrademark.de> | 2017-12-23 11:59:13 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2017-12-23 11:59:13 +0100 |
commit | fbbea4eb5f8e72386a78c3b4639147b6e82a8535 (patch) | |
tree | 2d4b4b6f0aee8c69c3c9828cd03d292b5fefb8ae /includes/controller/public_dashboard_controller.php | |
parent | 16a8b0e2fabe3dc632ae2e8dfcf9cc7a6f0c6aaa (diff) |
add show on dashboard flag for angeltypes
Diffstat (limited to 'includes/controller/public_dashboard_controller.php')
-rw-r--r-- | includes/controller/public_dashboard_controller.php | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/includes/controller/public_dashboard_controller.php b/includes/controller/public_dashboard_controller.php index 3cd85a50..4a36ea42 100644 --- a/includes/controller/public_dashboard_controller.php +++ b/includes/controller/public_dashboard_controller.php @@ -12,7 +12,14 @@ function public_dashboard_controller() 'hours-to-work' => stats_hours_to_work() ]; - $free_shifts = Shifts_free(time(), time() + 12 * 60 * 60); + $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); + if(count($free_shift['needed_angels']) > 0) { + $free_shifts[] = $free_shift; + } + } return [ _('Public Dashboard'), @@ -21,6 +28,62 @@ function public_dashboard_controller() } /** + * Gathers informations for free shifts to display. + * + * @param array $shift + */ +function public_dashboard_controller_free_shift($shift) +{ + $shifttype = ShiftType($shift['shifttype_id']); + $room = Room($shift['RID']); + + $free_shift = [ + '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'], + 'title' => $shift['title'], + 'room_name' => $room['Name'], + 'needed_angels' => [] + ]; + + if (time() + 3 * 60 * 60 > $shift['start']) { + $free_shift['style'] = 'warning'; + } + if (time() > $shift['start']) { + $free_shift['style'] = 'danger'; + } + + $free_shift['needed_angels'] = public_dashboard_needed_angels($shift['NeedAngels']); + + return $free_shift; +} + +/** + * Gathers informations for needed angels on dashboard + * + * @param array $needed_angels + */ +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[] = [ + 'need' => $need, + 'angeltype_name' => $angeltype['name'] + ]; + } + } + } + return $result; +} + +/** * Returns url to public dashboard */ function public_dashboard_link() |