From b24b1e7e4e5ee0551ee56aa0f21c4425b479db2e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 4 Feb 2015 22:19:32 -0500 Subject: Add subtasks restrictions and time tracking --- app/Model/SubTask.php | 32 +++++++++++++++- app/Model/SubtaskTimeTracking.php | 80 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 app/Model/SubtaskTimeTracking.php (limited to 'app/Model') diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php index 3fccad47..dd243b1f 100644 --- a/app/Model/SubTask.php +++ b/app/Model/SubTask.php @@ -223,12 +223,42 @@ class SubTask extends Base $values = array( 'id' => $subtask['id'], 'status' => ($subtask['status'] + 1) % 3, - 'task_id' => $subtask['task_id'], ); return $this->update($values); } + /** + * Get the subtask in progress for this user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getSubtaskInProgress($user_id) + { + return $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->findOne(); + } + + /** + * Return true if the user have a subtask in progress + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function hasSubtaskInProgress($user_id) + { + return $this->config->get('subtask_restriction') == 1 && + $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->count() === 1; + } + /** * Remove * diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php new file mode 100644 index 00000000..5c8a7c81 --- /dev/null +++ b/app/Model/SubtaskTimeTracking.php @@ -0,0 +1,80 @@ +db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.subtask_id', + self::TABLE.'.end', + self::TABLE.'.start', + SubTask::TABLE.'.task_id', + SubTask::TABLE.'.title AS subtask_title', + Task::TABLE.'.title AS task_title', + Task::TABLE.'.project_id' + ) + ->join(SubTask::TABLE, 'id', 'subtask_id') + ->join(Task::TABLE, 'id', 'task_id', SubTask::TABLE) + ->eq(self::TABLE.'.user_id', $user_id); + } + + /** + * Log start time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logStartTime($subtask_id, $user_id) + { + return $this->db + ->table(self::TABLE) + ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time())); + } + + /** + * Log end time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logEndTime($subtask_id, $user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('subtask_id', $subtask_id) + ->eq('user_id', $user_id) + ->eq('end', 0) + ->update(array( + 'end' => time() + )); + } +} -- cgit v1.2.3