From 813b7c4c0036a73c3bb5ef31f98e83cce2630e9e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 8 Feb 2015 13:46:38 -0500 Subject: Add unit test for subtask time tracking --- app/Model/SubtaskTimeTracking.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php index 3104dc20..5b58dfe2 100644 --- a/app/Model/SubtaskTimeTracking.php +++ b/app/Model/SubtaskTimeTracking.php @@ -43,6 +43,21 @@ class SubtaskTimeTracking extends Base ->eq(self::TABLE.'.user_id', $user_id); } + /** + * Get all recorded time slots for a given user + * + * @access public + * @param integer $user_id User id + * @return array + */ + public function getUserTimesheet($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->findAll(); + } + /** * Log start time * @@ -140,9 +155,17 @@ class SubtaskTimeTracking extends Base ->eq('end', 0) ->findOneColumn('start'); + $time_spent = $this->db + ->table(Subtask::TABLE) + ->eq('id', $subtask_id) + ->findOneColumn('time_spent'); + return $start_time && $this->db - ->getConnection() - ->exec('UPDATE '.Subtask::TABLE.' SET time_spent=time_spent+'.round((time() - $start_time) / 3600, 1).' WHERE id='.$subtask_id); + ->table(Subtask::TABLE) + ->eq('id', $subtask_id) + ->update(array( + 'time_spent' => $time_spent + round((time() - $start_time) / 3600, 1) + )); } } -- cgit v1.2.3