summaryrefslogtreecommitdiff
path: root/includes/view
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-12-29 19:06:23 +0100
committerGitHub <noreply@github.com>2017-12-29 19:06:23 +0100
commit372f474dbcf7524cc10aff0be0bb39c1a90df1f4 (patch)
tree3870eaeaa468caeee9c24f63f0f942a7548aba3b /includes/view
parent14584b96114d2fcb0dabe49a9c857ff241421cc8 (diff)
parent4579509b0e21d33ae27ecb5910fdc1d31b1e027a (diff)
Merge pull request #407 from engelsystem/feature-work-log
Feature work log
Diffstat (limited to 'includes/view')
-rw-r--r--includes/view/UserWorkLog_view.php96
-rw-r--r--includes/view/User_view.php65
2 files changed, 154 insertions, 7 deletions
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..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') . '&trade;:</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 &amp; 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')