From 6efac784fcc1a2e83bb7b43fc7841448b5975cba Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 24 Jun 2015 20:39:06 -0400 Subject: Add timer for subtasks and remove settings for subtask time tracking --- app/Model/SubtaskTimeTracking.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'app/Model/SubtaskTimeTracking.php') diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php index 93a698b6..51743198 100644 --- a/app/Model/SubtaskTimeTracking.php +++ b/app/Model/SubtaskTimeTracking.php @@ -19,6 +19,27 @@ class SubtaskTimeTracking extends Base */ const TABLE = 'subtask_time_tracking'; + /** + * Get query to check if a timer is started for the given user and subtask + * + * @access public + * @param integer $user_id User id + * @return string + */ + public function getTimerQuery($user_id) + { + return sprintf( + "SELECT %s FROM %s WHERE %s='%d' AND %s='0' AND %s=%s", + $this->db->escapeIdentifier('start'), + $this->db->escapeIdentifier(self::TABLE), + $this->db->escapeIdentifier('user_id'), + $user_id, + $this->db->escapeIdentifier('end'), + $this->db->escapeIdentifier('subtask_id'), + Subtask::TABLE.'.id' + ); + } + /** * Get query for user timesheet (pagination) * @@ -217,7 +238,7 @@ class SubtaskTimeTracking extends Base { return $this->db ->table(self::TABLE) - ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time())); + ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0)); } /** -- cgit v1.2.3