summaryrefslogtreecommitdiff
path: root/app/Api/Procedure/SubtaskProcedure.php
diff options
context:
space:
mode:
authori00171 <anton.delitsch@implema.se>2016-06-26 18:35:25 +0200
committeri00171 <anton.delitsch@implema.se>2016-06-26 18:35:25 +0200
commit47039d32c84ba699867920d2c3cb47a34b199b9d (patch)
tree4fbc2ec34889baeab00085e0509055dca7daee6a /app/Api/Procedure/SubtaskProcedure.php
parent911be6ed00c1ece5d9ef2c16e80899bb7bffad67 (diff)
parentc110dffefe259c13e60193fb81ebb9d4b79504de (diff)
Merge branch 'master' of https://github.com/fguillot/kanboard
Diffstat (limited to 'app/Api/Procedure/SubtaskProcedure.php')
-rw-r--r--app/Api/Procedure/SubtaskProcedure.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/app/Api/Procedure/SubtaskProcedure.php b/app/Api/Procedure/SubtaskProcedure.php
new file mode 100644
index 00000000..e2400912
--- /dev/null
+++ b/app/Api/Procedure/SubtaskProcedure.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Kanboard\Api\Procedure;
+
+use Kanboard\Api\Authorization\SubtaskAuthorization;
+use Kanboard\Api\Authorization\TaskAuthorization;
+
+/**
+ * Subtask API controller
+ *
+ * @package Kanboard\Api\Procedure
+ * @author Frederic Guillot
+ */
+class SubtaskProcedure extends BaseProcedure
+{
+ public function getSubtask($subtask_id)
+ {
+ SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSubtask', $subtask_id);
+ return $this->subtaskModel->getById($subtask_id);
+ }
+
+ public function getAllSubtasks($task_id)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllSubtasks', $task_id);
+ return $this->subtaskModel->getAll($task_id);
+ }
+
+ public function removeSubtask($subtask_id)
+ {
+ SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeSubtask', $subtask_id);
+ return $this->subtaskModel->remove($subtask_id);
+ }
+
+ public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createSubtask', $task_id);
+
+ $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->subtaskValidator->validateCreation($values);
+ return $valid ? $this->subtaskModel->create($values) : false;
+ }
+
+ public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateSubtask', $task_id);
+
+ $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->subtaskValidator->validateApiModification($values);
+ return $valid && $this->subtaskModel->update($values);
+ }
+}