diff options
| author | Christopher Geelen <christopher.geelen@vinotion.nl> | 2016-07-27 13:58:23 +0200 |
|---|---|---|
| committer | Christopher Geelen <christopher.geelen@vinotion.nl> | 2016-07-27 13:58:23 +0200 |
| commit | 24745182724ca69092554eb5946e31584420f68a (patch) | |
| tree | 386cdf7a8d7bf7ad2d80d938333bafbaf0fedcbc /app/Model/SubtaskStatusModel.php | |
| parent | 160c0b885eb4f1a1a1baa2b6b9fc6d99fdb80d0c (diff) | |
| parent | 9649f7ba82ba7fe6a470abfe9f65e214cc68fa34 (diff) | |
Merge remote-tracking branch 'upstream/master'
Conflicts:
app/Job/NotificationJob.php
Diffstat (limited to 'app/Model/SubtaskStatusModel.php')
| -rw-r--r-- | app/Model/SubtaskStatusModel.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/app/Model/SubtaskStatusModel.php b/app/Model/SubtaskStatusModel.php new file mode 100644 index 00000000..c99d6055 --- /dev/null +++ b/app/Model/SubtaskStatusModel.php @@ -0,0 +1,88 @@ +<?php + +namespace Kanboard\Model; + +use Kanboard\Core\Base; + +/** + * Class SubtaskStatusModel + * + * @package Kanboard\Model + * @author Frederic Guillot + */ +class SubtaskStatusModel extends Base +{ + /** + * 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(SubtaskModel::TABLE) + ->eq('status', SubtaskModel::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->configModel->get('subtask_restriction') == 1 && + $this->db->table(SubtaskModel::TABLE) + ->eq('status', SubtaskModel::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->exists(); + } + + /** + * Change the status of subtask + * + * @access public + * @param integer $subtask_id + * @return boolean|integer + */ + public function toggleStatus($subtask_id) + { + $subtask = $this->subtaskModel->getById($subtask_id); + $status = ($subtask['status'] + 1) % 3; + + $values = array( + 'id' => $subtask['id'], + 'status' => $status, + 'task_id' => $subtask['task_id'], + ); + + 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; + } + + /** + * Close all subtasks of a task + * + * @access public + * @param integer $task_id + * @return boolean + */ + public function closeAll($task_id) + { + return $this->db + ->table(SubtaskModel::TABLE) + ->eq('task_id', $task_id) + ->update(array('status' => SubtaskModel::STATUS_DONE)); + } +} |
