Add unit test for subtask time tracking

This commit is contained in:
Frederic Guillot
2015-02-08 13:46:38 -05:00
parent 696cd9535c
commit 813b7c4c00
4 changed files with 185 additions and 6 deletions

View File

@@ -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)
));
}
}