From fbbea4eb5f8e72386a78c3b4639147b6e82a8535 Mon Sep 17 00:00:00 2001 From: msquare Date: Sat, 23 Dec 2017 11:59:13 +0100 Subject: add show on dashboard flag for angeltypes --- includes/controller/angeltypes_controller.php | 1 + .../controller/public_dashboard_controller.php | 65 +++++++++++++++++++++- includes/model/AngelType_model.php | 19 +++++-- includes/model/Shifts_model.php | 2 +- includes/view/AngelTypes_view.php | 14 +++-- includes/view/PublicDashboard_view.php | 27 +++------ 6 files changed, 94 insertions(+), 34 deletions(-) (limited to 'includes') diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 621b5cbd..48b81b9f 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -141,6 +141,7 @@ function angeltype_edit_controller() $angeltype['restricted'] = $request->has('restricted'); $angeltype['no_self_signup'] = $request->has('no_self_signup'); + $angeltype['show_on_dashboard'] = $request->has('show_on_dashboard'); $angeltype['requires_driver_license'] = $request->has('requires_driver_license'); } 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'), @@ -20,6 +27,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 */ diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index bdfb0e6e..f6e2a9cf 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -18,7 +18,8 @@ function AngelType_new() 'requires_driver_license' => false, 'contact_name' => null, 'contact_dect' => null, - 'contact_email' => null + 'contact_email' => null, + 'show_on_dashboard' => true ]; } @@ -65,7 +66,8 @@ function AngelType_update($angeltype) `no_self_signup` = ?, `contact_name` = ?, `contact_dect` = ?, - `contact_email` = ? + `contact_email` = ?, + `show_on_dashboard` = ? WHERE `id` = ?', [ $angeltype['name'], @@ -76,6 +78,7 @@ function AngelType_update($angeltype) $angeltype['contact_name'], $angeltype['contact_dect'], $angeltype['contact_email'], + (int)$angeltype['show_on_dashboard'], $angeltype['id'], ] ); @@ -86,7 +89,8 @@ function AngelType_update($angeltype) . ($angeltype['requires_driver_license'] ? ', requires driver license' : '') . ', ' . $angeltype['contact_name'] . ', ' . $angeltype['contact_dect'] . ', ' - . $angeltype['contact_email'] + . $angeltype['contact_email'] . ', ' + . $angeltype['show_on_dashboard'] ); } @@ -107,9 +111,10 @@ function AngelType_create($angeltype) `no_self_signup`, `contact_name`, `contact_dect`, - `contact_email` + `contact_email`, + `show_on_dashboard` ) - VALUES (?, ?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ', [ $angeltype['name'], @@ -120,6 +125,7 @@ function AngelType_create($angeltype) $angeltype['contact_name'], $angeltype['contact_dect'], $angeltype['contact_email'], + $angeltype['show_on_dashboard'] ] ); @@ -130,7 +136,8 @@ function AngelType_create($angeltype) . ($angeltype['requires_driver_license'] ? ', requires driver license' : '') . ', ' . $angeltype['contact_name'] . ', ' . $angeltype['contact_dect'] . ', ' - . $angeltype['contact_email'] + . $angeltype['contact_email'] . ', ' + . $angeltype['show_on_dashboard'] ); return $angeltype; } diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index ad64e9b9..caca2a33 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -27,7 +27,7 @@ function Shifts_by_angeltype($angeltype) { } /** - * Returns every shift with needed angels in the given time range. + * Returns every shift with needed angels in the given time range. */ function Shifts_free($start, $end) { diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php index a8b34df8..a5c10a38 100644 --- a/includes/view/AngelTypes_view.php +++ b/includes/view/AngelTypes_view.php @@ -84,6 +84,10 @@ function AngelType_edit_view($angeltype, $supporter_mode) $supporter_mode ? form_info(_('Restricted'), $angeltype['restricted'] ? _('Yes') : _('No')) : form_checkbox('restricted', _('Restricted'), $angeltype['restricted']), + form_info( + '', + _('Restricted angel types can only be used by an angel if enabled by a supporter (double opt-in).') + ), $supporter_mode ? form_info(_('No Self Sign Up'), $angeltype['no_self_signup'] ? _('Yes') : _('No')) : form_checkbox('no_self_signup', _('No Self Sign Up'), $angeltype['no_self_signup']), @@ -92,12 +96,10 @@ function AngelType_edit_view($angeltype, $supporter_mode) : form_checkbox( 'requires_driver_license', _('Requires driver license'), - $angeltype['requires_driver_license'] - ), - form_info( - '', - _('Restricted angel types can only be used by an angel if enabled by a supporter (double opt-in).') - ), + $angeltype['requires_driver_license']), + $supporter_mode + ? form_info(_('Show on dashboard'), $angeltype['show_on_dashboard'] ? _('Yes') : _('No')) + : form_checkbox('show_on_dashboard', _('Show on dashboard'), $angeltype['show_on_dashboard']), form_textarea('description', _('Description'), $angeltype['description']), form_info('', _('Please use markdown for the description.')), heading(_('Contact'), 3), diff --git a/includes/view/PublicDashboard_view.php b/includes/view/PublicDashboard_view.php index 7ae434a2..30f63d63 100644 --- a/includes/view/PublicDashboard_view.php +++ b/includes/view/PublicDashboard_view.php @@ -51,35 +51,22 @@ function public_dashboard_view($stats, $free_shifts) */ function public_dashborad_shift_render($shift) { - $style = 'default'; - if (time() + 3 * 60 * 60 > $shift['start']) { - $style = 'warning'; - } - if (time() > $shift['start']) { - $style = 'danger'; - } - - $panel_body = glyph('time') . date('H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']); - $panel_body .= ' (' . round(($shift['end'] - $shift['start']) / 3600) . ' h)'; + $panel_body = glyph('time') . $shift['start'] . ' - ' . $shift['end']; + $panel_body .= ' (' . $shift['duration'] . ' h)'; - $panel_body .= '
' . glyph('tasks') . ShiftType($shift['shifttype_id'])['name']; + $panel_body .= '
' . glyph('tasks') . $shift['shifttype_name']; if (! empty($shift['title'])) { $panel_body .= ' (' . $shift['title'] . ')'; } - $panel_body .= '
' . glyph('map-marker') . Room($shift['RID'])['Name']; + $panel_body .= '
' . glyph('map-marker') . $shift['room_name']; - foreach ($shift['NeedAngels'] as $needed_angels) { - $need = $needed_angels['count'] - $needed_angels['taken']; - if ($need > 0) { - $panel_body .= '
' . glyph('user') . '' . $need . ' × ' . AngelType($needed_angels['TID'])['name'] . ''; - } + foreach ($shift['needed_angels'] as $needed_angels) { + $panel_body .= '
' . glyph('user') . '' . $needed_angels['need'] . ' × ' . $needed_angels['angeltype_name'] . ''; } - // $panel_body = '' . $panel_body . ''; - return div('col-md-3', [ - div('dashboard-panel panel panel-' . $style, [ + div('dashboard-panel panel panel-' . $shift['style'], [ div('panel-body', [ '', $panel_body -- cgit v1.2.3-54-g00ecf