diff options
Diffstat (limited to 'includes/model')
-rw-r--r-- | includes/model/UserWorkLog_model.php | 78 | ||||
-rw-r--r-- | includes/model/User_model.php | 4 |
2 files changed, 48 insertions, 34 deletions
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']; |