diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-07-23 22:50:20 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-07-23 22:50:20 -0400 |
commit | 5884c65a02a13dd396525d0b8d1720d1c062a96e (patch) | |
tree | c480362ec790adbd2fe331164ac5b5494316e15f /app/Model | |
parent | 24555080fd3ca8607f0a798b5a0e4be98ff131f8 (diff) |
Remove SubtaskTimeTrackingSubscriber
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/SubtaskModel.php | 15 | ||||
-rw-r--r-- | app/Model/SubtaskStatusModel.php | 3 | ||||
-rw-r--r-- | app/Model/SubtaskTimeTrackingModel.php | 23 |
3 files changed, 35 insertions, 6 deletions
diff --git a/app/Model/SubtaskModel.php b/app/Model/SubtaskModel.php index 568e27a4..608ffce7 100644 --- a/app/Model/SubtaskModel.php +++ b/app/Model/SubtaskModel.php @@ -173,6 +173,7 @@ class SubtaskModel extends Base $subtask_id = $this->db->table(self::TABLE)->persist($values); if ($subtask_id !== false) { + $this->subtaskTimeTrackingModel->updateTaskTimeTracking($values['task_id']); $this->queueManager->push($this->subtaskEventJob->withParams($subtask_id, self::EVENT_CREATE)); } @@ -183,17 +184,21 @@ class SubtaskModel extends Base * Update * * @access public - * @param array $values Form values - * @param bool $fire_events If true, will be called an event + * @param array $values + * @param bool $fire_event * @return bool */ - public function update(array $values, $fire_events = true) + public function update(array $values, $fire_event = true) { $this->prepare($values); $result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); - if ($result && $fire_events) { - $this->queueManager->push($this->subtaskEventJob->withParams($values['id'], self::EVENT_UPDATE, $values)); + if ($result) { + $this->subtaskTimeTrackingModel->updateTaskTimeTracking($values['task_id']); + + if ($fire_event) { + $this->queueManager->push($this->subtaskEventJob->withParams($values['id'], self::EVENT_UPDATE, $values)); + } } return $result; diff --git a/app/Model/SubtaskStatusModel.php b/app/Model/SubtaskStatusModel.php index 26cbb67d..c99d6055 100644 --- a/app/Model/SubtaskStatusModel.php +++ b/app/Model/SubtaskStatusModel.php @@ -63,8 +63,11 @@ class SubtaskStatusModel extends Base if (empty($subtask['user_id']) && $this->userSession->isLogged()) { $values['user_id'] = $this->userSession->getId(); + $subtask['user_id'] = $values['user_id']; } + $this->subtaskTimeTrackingModel->toggleTimer($subtask_id, $subtask['user_id'], $status); + return $this->subtaskModel->update($values) ? $status : false; } diff --git a/app/Model/SubtaskTimeTrackingModel.php b/app/Model/SubtaskTimeTrackingModel.php index 062e594a..3b1b97e4 100644 --- a/app/Model/SubtaskTimeTrackingModel.php +++ b/app/Model/SubtaskTimeTrackingModel.php @@ -160,6 +160,28 @@ class SubtaskTimeTrackingModel extends Base } /** + * Start or stop timer according to subtask status + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @param integer $status + * @return boolean + */ + public function toggleTimer($subtask_id, $user_id, $status) + { + if ($this->configModel->get('subtask_time_tracking') == 1) { + if ($status == SubtaskModel::STATUS_INPROGRESS) { + return $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $user_id); + } elseif ($status == SubtaskModel::STATUS_DONE) { + return $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $user_id); + } + } + + return false; + } + + /** * Log start time * * @access public @@ -252,7 +274,6 @@ class SubtaskTimeTrackingModel extends Base { $subtask = $this->subtaskModel->getById($subtask_id); - // Fire the event subtask.update return $this->subtaskModel->update(array( 'id' => $subtask['id'], 'time_spent' => $subtask['time_spent'] + $time_spent, |