diff options
author | msquare <msquare@notrademark.de> | 2017-12-29 19:06:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-29 19:06:23 +0100 |
commit | 372f474dbcf7524cc10aff0be0bb39c1a90df1f4 (patch) | |
tree | 3870eaeaa468caeee9c24f63f0f942a7548aba3b /includes/view/User_view.php | |
parent | 14584b96114d2fcb0dabe49a9c857ff241421cc8 (diff) | |
parent | 4579509b0e21d33ae27ecb5910fdc1d31b1e027a (diff) |
Merge pull request #407 from engelsystem/feature-work-log
Feature work log
Diffstat (limited to 'includes/view/User_view.php')
-rw-r--r-- | includes/view/User_view.php | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/includes/view/User_view.php b/includes/view/User_view.php index fff2952e..36ac36c3 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -356,7 +356,7 @@ function User_view_myshift($shift, $user_source, $its_me) . glyph('time') . date('H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']), - 'duration' => round(($shift['end'] - $shift['start']) / 3600, 2) . ' h', + 'duration' => sprintf('%.2f', round(($shift['end'] - $shift['start']) / 3600, 2)) . ' h', 'room' => Room_name_render($shift), 'shift_info' => $shift_info, 'comment' => '' @@ -408,22 +408,30 @@ function User_view_myshift($shift, $user_source, $its_me) * @param bool $its_me * @return array */ -function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin) +function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin, $user_worklogs, $admin_user_worklog_privilege) { $myshifts_table = []; $timesum = 0; foreach ($shifts as $shift) { - $myshifts_table[] = User_view_myshift($shift, $user_source, $its_me); + $myshifts_table[$shift['start']] = User_view_myshift($shift, $user_source, $its_me); if (!$shift['freeloaded']) { $timesum += ($shift['end'] - $shift['start']); } } + if($its_me || $admin_user_worklog_privilege) { + foreach($user_worklogs as $worklog) { + $myshifts_table[$worklog['work_timestamp']] = User_view_worklog($worklog, $admin_user_worklog_privilege); + $timesum += $worklog['work_hours'] * 3600; + } + } + if (count($myshifts_table) > 0) { + ksort($myshifts_table); $myshifts_table[] = [ 'date' => '<b>' . _('Sum:') . '</b>', - 'duration' => '<b>' . round($timesum / 3600, 2) . ' h</b>', + 'duration' => '<b>' . sprintf('%.2f', round($timesum / 3600, 2)) . ' h</b>', 'room' => '', 'shift_info' => '', 'comment' => '', @@ -432,7 +440,7 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi if (config('enable_tshirt_size', false) && ($its_me || $tshirt_admin)) { $myshifts_table[] = [ 'date' => '<b>' . _('Your t-shirt score') . '™:</b>', - 'duration' => '<b>' . $tshirt_score . '</b>', + 'duration' => '<b>' . sprintf('%.2f', $tshirt_score) . ' h</b>', 'room' => '', 'shift_info' => '', 'comment' => '', @@ -444,6 +452,43 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi } /** + * Renders table entry for user work log + * @param UserWorkLog $worklog + * @param bool $admin_user_worklog_privilege + */ +function User_view_worklog($worklog, $admin_user_worklog_privilege) { + $actions = ''; + if($admin_user_worklog_privilege) { + $actions = table_buttons([ + button( + user_worklog_edit_link($worklog), + glyph('edit') . _('edit'), + 'btn-xs' + ), + button( + user_worklog_delete_link($worklog), + glyph('trash') . _('delete'), + 'btn-xs' + ) + ]); + } + + return [ + 'date' => glyph('calendar') . date('Y-m-d', $worklog['work_timestamp']), + 'duration' => '<b>' . sprintf('%.2f', $worklog['work_hours']) . ' h</b>', + 'room' => '', + 'shift_info' => _('Work log entry'), + 'comment' => $worklog['comment'] . '<br>' + . sprintf( + _('Added by %s at %s'), + User_Nick_render(User($worklog['user_id'])), + date('Y-m-d H:i', $worklog['created_timestamp']) + ), + 'actions' => $actions + ]; +} + +/** * Renders view for a single user * * @param array $user_source @@ -466,12 +511,14 @@ function User_view( $shifts, $its_me, $tshirt_score, - $tshirt_admin + $tshirt_admin, + $admin_user_worklog_privilege, + $user_worklogs ) { $user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']); $myshifts_table = ''; if($its_me || $admin_user_privilege) { - $my_shifts = User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin); + $my_shifts = User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin, $user_worklogs, $admin_user_worklog_privilege); if(count($my_shifts) > 0) { $myshifts_table = table([ 'date' => _('Day & time'), @@ -514,6 +561,10 @@ function User_view( ), glyph('cutlery') . _('Edit vouchers') ) : '', + $admin_user_worklog_privilege ? button( + user_worklog_add_link($user_source), + glyph('list') . _('Add work log') + ) : '', $its_me ? button( page_link_to('user_settings'), glyph('list-alt') . _('Settings') |