diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/controller/user_worklog_controller.php | 6 | ||||
-rw-r--r-- | includes/model/UserWorkLog_model.php | 78 | ||||
-rw-r--r-- | includes/model/User_model.php | 4 | ||||
-rw-r--r-- | includes/pages/admin_active.php | 8 | ||||
-rw-r--r-- | includes/view/UserWorkLog_view.php | 3 | ||||
-rw-r--r-- | includes/view/User_view.php | 15 |
6 files changed, 70 insertions, 44 deletions
diff --git a/includes/controller/user_worklog_controller.php b/includes/controller/user_worklog_controller.php index ba91534b..bd62c83c 100644 --- a/includes/controller/user_worklog_controller.php +++ b/includes/controller/user_worklog_controller.php @@ -69,6 +69,12 @@ function user_worklog_from_request($userWorkLog) $valid = true; + $userWorkLog['work_timestamp'] = parse_date('Y-m-d H:i', $request->input('work_timestamp') . ' 00:00'); + if ($userWorkLog['work_timestamp'] == null) { + $valid = false; + error(_('Please enter work date.')); + } + $userWorkLog['work_hours'] = $request->input('work_hours'); if (! preg_match("/[0-9]+(\.[0-9]+)?/", $userWorkLog['work_hours'])) { $valid = false; diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index 55e135ca..36442943 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -3,23 +3,32 @@ use Engelsystem\Database\Db; /** * Load a single work log entry. - * @param int $user_worklog_id + * + * @param int $user_worklog_id */ -function UserWorkLog($user_worklog_id) { - return Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [$user_worklog_id]); +function UserWorkLog($user_worklog_id) +{ + return Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [ + $user_worklog_id + ]); } /** * Returns all work log entries for a user. - * @param User $user + * + * @param User $user */ -function UserWorkLogsForUser($user) { - return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [$user['UID']]); +function UserWorkLogsForUser($user) +{ + return Db::select("SELECT * FROM `UserWorkLog` WHERE `user_id`=? ORDER BY `created_timestamp`", [ + $user['UID'] + ]); } /** * Delete a work log entry. - * @param UserWorkLog $userWorkLog + * + * @param UserWorkLog $userWorkLog */ function UserWorkLog_delete($userWorkLog) { @@ -28,42 +37,40 @@ function UserWorkLog_delete($userWorkLog) $userWorkLog['id'] ]); - engelsystem_log(sprintf('Delete work log for %s, %s hours, %s', - User_Nick_render($user_source), - $userWorkLog['work_hours'], - $userWorkLog['comment'])); + engelsystem_log(sprintf('Delete work log for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment'])); return $result; } /** * Update work log entry (only work hours and comment) - * @param UserWorkLog $userWorkLog + * + * @param UserWorkLog $userWorkLog */ function UserWorkLog_update($userWorkLog) { $user_source = User($userWorkLog['user_id']); - + $result = Db::update("UPDATE `UserWorkLog` SET + `work_timestamp`=?, `work_hours`=?, `comment`=? WHERE `id`=?", [ - $userWorkLog['work_hours'], - $userWorkLog['comment'], - $userWorkLog['id'] - ]); - - engelsystem_log(sprintf('Updated work log for %s, %s hours, %s', - User_Nick_render($user_source), + $userWorkLog['work_timestamp'], $userWorkLog['work_hours'], - $userWorkLog['comment'])); + $userWorkLog['comment'], + $userWorkLog['id'] + ]); + + engelsystem_log(sprintf('Updated work log for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment'])); return $result; } /** * Create a new work log entry - * @param UserWorkLog $userWorkLog + * + * @param UserWorkLog $userWorkLog */ function UserWorkLog_create($userWorkLog) { @@ -73,23 +80,22 @@ function UserWorkLog_create($userWorkLog) $result = Db::insert("INSERT INTO `UserWorkLog` ( `user_id`, + `work_timestamp`, `work_hours`, `comment`, `created_user_id`, `created_timestamp` ) - VALUES (?, ?, ?, ?, ?)", [ - $userWorkLog['user_id'], - $userWorkLog['work_hours'], - $userWorkLog['comment'], - $user['UID'], - time() - ]); - - engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', - User_Nick_render($user_source), + VALUES (?, ?, ?, ?, ?, ?)", [ + $userWorkLog['user_id'], + $userWorkLog['work_timestamp'], $userWorkLog['work_hours'], - $userWorkLog['comment'])); + $userWorkLog['comment'], + $user['UID'], + time() + ]); + + engelsystem_log(sprintf('Added work log entry for %s, %s hours, %s', User_Nick_render($user_source), $userWorkLog['work_hours'], $userWorkLog['comment'])); return $result; } @@ -101,8 +107,14 @@ function UserWorkLog_create($userWorkLog) */ function UserWorkLog_new($user) { + $work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', time())); + $event_config = EventConfig(); + if (! empty($event_config['buildup_start_date'])) { + $work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', $event_config['buildup_start_date'])); + } return [ 'user_id' => $user['UID'], + 'work_timestamp' => $work_date, 'work_hours' => 0, 'comment' => '' ]; diff --git a/includes/model/User_model.php b/includes/model/User_model.php index b398cefe..5a31e7b8 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -42,8 +42,10 @@ function User_tshirt_score($user) { FROM `User` LEFT JOIN `UserWorkLog` ON `User`.`UID` = `UserWorkLog`.`user_id` WHERE `User`.`UID` = ? + AND `UserWorkLog`.`work_timestamp` < ? ',[ - $user['UID'] + $user['UID'], + time() ]); return $result_shifts['tshirt_score'] + $result_worklog['tshirt_score']; diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 18553159..f3a28061 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -59,7 +59,8 @@ function admin_active() `User`.*, COUNT(`ShiftEntry`.`id`) AS `shift_count`, (%s + ( - SELECT SUM(`work_hours`) * 3600 FROM `UserWorkLog` WHERE `user_id`=`User`.`UID` + SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`User`.`UID` + AND `work_timestamp` < %s )) AS `shift_length` FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` @@ -71,6 +72,7 @@ function admin_active() %s ', $shift_sum_formula, + time(), $limit )); $user_nicks = []; @@ -143,7 +145,8 @@ function admin_active() `User`.*, COUNT(`ShiftEntry`.`id`) AS `shift_count`, (%s + ( - SELECT SUM(`work_hours`) * 3600 FROM `UserWorkLog` WHERE `user_id`=`User`.`UID` + SELECT COALESCE(SUM(`work_hours`) * 3600, 0) FROM `UserWorkLog` WHERE `user_id`=`User`.`UID` + AND `work_timestamp` < %s )) AS `shift_length` FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` ' @@ -154,6 +157,7 @@ function admin_active() %s ', $shift_sum_formula, + time(), $limit )); $matched_users = []; diff --git a/includes/view/UserWorkLog_view.php b/includes/view/UserWorkLog_view.php index 86a367ae..79c049b3 100644 --- a/includes/view/UserWorkLog_view.php +++ b/includes/view/UserWorkLog_view.php @@ -36,9 +36,10 @@ 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', _('Add')) + form_submit('submit', _('Save')) ]); } diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 82df1851..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' => '' @@ -413,7 +413,7 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi $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']); @@ -422,15 +422,16 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi if($its_me || $admin_user_worklog_privilege) { foreach($user_worklogs as $worklog) { - $myshifts_table[] = User_view_worklog($worklog, $admin_user_worklog_privilege); + $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' => '', @@ -439,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' => '', @@ -473,8 +474,8 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege) { } return [ - 'date' => '', - 'duration' => '<b>' . $worklog['work_hours'] . ' h</b>', + '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>' |