diff options
Diffstat (limited to 'includes/view')
-rw-r--r-- | includes/view/PublicDashboard_view.php | 2 | ||||
-rw-r--r-- | includes/view/UserWorkLog_view.php | 96 | ||||
-rw-r--r-- | includes/view/User_view.php | 67 |
3 files changed, 156 insertions, 9 deletions
diff --git a/includes/view/PublicDashboard_view.php b/includes/view/PublicDashboard_view.php index 83cf0e5f..6fef8f54 100644 --- a/includes/view/PublicDashboard_view.php +++ b/includes/view/PublicDashboard_view.php @@ -68,7 +68,7 @@ function public_dashboard_view($stats, $free_shifts) function public_dashboard_shift_render($shift) { $panel_body = glyph('time') . $shift['start'] . ' - ' . $shift['end']; - $panel_body .= ' (' . $shift['duration'] . ' h)'; + $panel_body .= ' (' . $shift['duration'] . ' h)'; $panel_body .= '<br>' . glyph('tasks') . $shift['shifttype_name']; if (!empty($shift['title'])) { diff --git a/includes/view/UserWorkLog_view.php b/includes/view/UserWorkLog_view.php new file mode 100644 index 00000000..79c049b3 --- /dev/null +++ b/includes/view/UserWorkLog_view.php @@ -0,0 +1,96 @@ +<?php + +/** + * Delete work log entry. + * @param User $user_source + * @param UserWorkLog $userWorkLog + */ +function UserWorkLog_delete_view($user_source, $userWorkLog) +{ + return page_with_title(UserWorkLog_delete_title(), [ + info(sprintf(_('Do you want to delete the worklog entry for %s?'), User_Nick_render($user_source)), true), + buttons([ + button(user_link($user_source), glyph('remove') . _('cancel')), + button(user_worklog_delete_link($userWorkLog, [ + 'confirmed' => 1 + ]), glyph('ok') . _('delete'), 'btn-danger') + ]) + ]); +} + +/** + * Title for work log delete. + */ +function UserWorkLog_delete_title() +{ + return _('Delete work log entry'); +} + +/** + * Render edit table. + * + * @param User $user_source + * @param UserWorkLog $userWorkLog + */ +function UserWorkLog_edit_form($user_source, $userWorkLog) +{ + return form([ + form_info(_('User'), User_Nick_render($user_source)), + form_date('work_timestamp', _('Work date'), $userWorkLog['work_timestamp'], null, time()), + form_text('work_hours', _('Work hours'), $userWorkLog['work_hours']), + form_text('comment', _('Comment'), $userWorkLog['comment']), + form_submit('submit', _('Save')) + ]); +} + +/** + * Form for edit a user work log entry. + * + * @param User $user_source + * @param UserWorkLog $userWorkLog + */ +function UserWorkLog_edit_view($user_source, $userWorkLog) +{ + return page_with_title(UserWorkLog_edit_title(), [ + buttons([ + button(user_link($user_source), _('back')) + ]), + msg(), + UserWorkLog_edit_form($user_source, $userWorkLog) + ]); +} + +/** + * Form for adding a user work log entry. + * + * @param User $user_source + * @param UserWorkLog $userWorkLog + */ +function UserWorkLog_add_view($user_source, $userWorkLog) +{ + return page_with_title(UserWorkLog_add_title(), [ + buttons([ + button(user_link($user_source), _('back')) + ]), + msg(), + UserWorkLog_edit_form($user_source, $userWorkLog) + ]); +} + +/** + * Title text for editing work log entry. + */ +function UserWorkLog_edit_title() +{ + return _('Edit work log entry'); +} + +/** + * Title text for adding work log entry. + */ +function UserWorkLog_add_title() +{ + return _('Add work log entry'); +} + +?>
\ No newline at end of file diff --git a/includes/view/User_view.php b/includes/view/User_view.php index fff2952e..2f53e641 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -299,7 +299,7 @@ function User_shift_state_render($user) if (time() < $halfway) { return '<span class="text-danger moment-countdown" data-timestamp="' . $nextShift['start'] . '">' - . _('Shift starts %c') + . _('Shift started %c') . '</span>'; } @@ -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', ($shift['end'] - $shift['start']) / 3600) . ' h', 'room' => Room_name_render($shift), 'shift_info' => $shift_info, 'comment' => '' @@ -368,7 +368,7 @@ function User_view_myshift($shift, $user_source, $its_me) if ($shift['freeloaded']) { $myshift['duration'] = '<p class="text-danger">' - . round(-($shift['end'] - $shift['start']) / 3600 * 2, 2) . ' h' + . round(-($shift['end'] - $shift['start']) / 3600 * 2, 2) . ' h' . '</p>'; if (in_array('user_shifts_admin', $privileges)) { $myshift['comment'] .= '<br />' @@ -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' => '', @@ -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']) . '</b>', + 'room' => '', + 'shift_info' => _('Work log entry'), + 'comment' => $worklog['comment'] . '<br>' + . sprintf( + _('Added by %s at %s'), + User_Nick_render(User($worklog['created_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') |