diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-05-23 21:44:33 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-05-23 21:44:33 -0400 |
commit | e32f26d048249b84166542d6442efdf202ff44fd (patch) | |
tree | 1868c5e83cec5ea8b821ad8a2036543aa37e5adb /app/Api/Subtask.php | |
parent | c9ba525bab06eff76b1d5fb8701848d0e3990122 (diff) |
API refactoring
Diffstat (limited to 'app/Api/Subtask.php')
-rw-r--r-- | app/Api/Subtask.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/app/Api/Subtask.php b/app/Api/Subtask.php new file mode 100644 index 00000000..2e6c30f2 --- /dev/null +++ b/app/Api/Subtask.php @@ -0,0 +1,64 @@ +<?php + +namespace Api; + +/** + * Subtask API controller + * + * @package api + * @author Frederic Guillot + */ +class Subtask extends Base +{ + public function getSubtask($subtask_id) + { + return $this->subtask->getById($subtask_id); + } + + public function getAllSubtasks($task_id) + { + return $this->subtask->getAll($task_id); + } + + public function removeSubtask($subtask_id) + { + return $this->subtask->remove($subtask_id); + } + + public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) + { + $values = array( + 'title' => $title, + 'task_id' => $task_id, + 'user_id' => $user_id, + 'time_estimated' => $time_estimated, + 'time_spent' => $time_spent, + 'status' => $status, + ); + + list($valid,) = $this->subtask->validateCreation($values); + return $valid ? $this->subtask->create($values) : false; + } + + public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) + { + $values = array( + 'id' => $id, + 'task_id' => $task_id, + 'title' => $title, + 'user_id' => $user_id, + 'time_estimated' => $time_estimated, + 'time_spent' => $time_spent, + 'status' => $status, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + list($valid,) = $this->subtask->validateApiModification($values); + return $valid && $this->subtask->update($values); + } +} |