summaryrefslogtreecommitdiff
path: root/app/Api/Procedure/TaskFileProcedure.php
diff options
context:
space:
mode:
authorJLGC @monolinux <monolinux@junglacode.org>2016-08-15 23:13:16 -0500
committerJLGC @monolinux <monolinux@junglacode.org>2016-08-15 23:13:16 -0500
commit683c0464093f6a7976236c68653c2a2cc5dae280 (patch)
treebf176ecd82415cc4952eea071b7d264dd5fd68b4 /app/Api/Procedure/TaskFileProcedure.php
parentb1e795fc5b45369f7b9b565b1e106d2673361977 (diff)
parent5f82a942c0011bf91947b2c1d627c0907bda0c92 (diff)
Merge https://github.com/kanboard/kanboard
Diffstat (limited to 'app/Api/Procedure/TaskFileProcedure.php')
-rw-r--r--app/Api/Procedure/TaskFileProcedure.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/app/Api/Procedure/TaskFileProcedure.php b/app/Api/Procedure/TaskFileProcedure.php
new file mode 100644
index 00000000..bd006578
--- /dev/null
+++ b/app/Api/Procedure/TaskFileProcedure.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace Kanboard\Api\Procedure;
+
+use Kanboard\Api\Authorization\ProjectAuthorization;
+use Kanboard\Api\Authorization\TaskAuthorization;
+use Kanboard\Api\Authorization\TaskFileAuthorization;
+use Kanboard\Core\ObjectStorage\ObjectStorageException;
+
+/**
+ * Task File API controller
+ *
+ * @package Kanboard\Api\Procedure
+ * @author Frederic Guillot
+ */
+class TaskFileProcedure extends BaseProcedure
+{
+ public function getTaskFile($file_id)
+ {
+ TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTaskFile', $file_id);
+ return $this->taskFileModel->getById($file_id);
+ }
+
+ public function getAllTaskFiles($task_id)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTaskFiles', $task_id);
+ return $this->taskFileModel->getAll($task_id);
+ }
+
+ public function downloadTaskFile($file_id)
+ {
+ TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'downloadTaskFile', $file_id);
+
+ try {
+ $file = $this->taskFileModel->getById($file_id);
+
+ if (! empty($file)) {
+ return base64_encode($this->objectStorage->get($file['path']));
+ }
+ } catch (ObjectStorageException $e) {
+ $this->logger->error($e->getMessage());
+ }
+
+ return '';
+ }
+
+ public function createTaskFile($project_id, $task_id, $filename, $blob)
+ {
+ ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createTaskFile', $project_id);
+
+ try {
+ return $this->taskFileModel->uploadContent($task_id, $filename, $blob);
+ } catch (ObjectStorageException $e) {
+ $this->logger->error(__METHOD__.': '.$e->getMessage());
+ return false;
+ }
+ }
+
+ public function removeTaskFile($file_id)
+ {
+ TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeTaskFile', $file_id);
+ return $this->taskFileModel->remove($file_id);
+ }
+
+ public function removeAllTaskFiles($task_id)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeAllTaskFiles', $task_id);
+ return $this->taskFileModel->removeAll($task_id);
+ }
+}