summaryrefslogtreecommitdiff
path: root/app/Api/Procedure/TaskExternalLinkProcedure.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/TaskExternalLinkProcedure.php
parentb1e795fc5b45369f7b9b565b1e106d2673361977 (diff)
parent5f82a942c0011bf91947b2c1d627c0907bda0c92 (diff)
Merge https://github.com/kanboard/kanboard
Diffstat (limited to 'app/Api/Procedure/TaskExternalLinkProcedure.php')
-rw-r--r--app/Api/Procedure/TaskExternalLinkProcedure.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/app/Api/Procedure/TaskExternalLinkProcedure.php b/app/Api/Procedure/TaskExternalLinkProcedure.php
new file mode 100644
index 00000000..05ec6906
--- /dev/null
+++ b/app/Api/Procedure/TaskExternalLinkProcedure.php
@@ -0,0 +1,106 @@
+<?php
+
+namespace Kanboard\Api\Procedure;
+
+use Kanboard\Api\Authorization\TaskAuthorization;
+use Kanboard\Core\ExternalLink\ExternalLinkManager;
+use Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound;
+
+/**
+ * Task External Link API controller
+ *
+ * @package Kanboard\Api\Procedure
+ * @author Frederic Guillot
+ */
+class TaskExternalLinkProcedure extends BaseProcedure
+{
+ public function getExternalTaskLinkTypes()
+ {
+ return $this->externalLinkManager->getTypes();
+ }
+
+ public function getExternalTaskLinkProviderDependencies($providerName)
+ {
+ try {
+ return $this->externalLinkManager->getProvider($providerName)->getDependencies();
+ } catch (ExternalLinkProviderNotFound $e) {
+ $this->logger->error(__METHOD__.': '.$e->getMessage());
+ return false;
+ }
+ }
+
+ public function getExternalTaskLinkById($task_id, $link_id)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getExternalTaskLink', $task_id);
+ return $this->taskExternalLinkModel->getById($link_id);
+ }
+
+ public function getAllExternalTaskLinks($task_id)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getExternalTaskLinks', $task_id);
+ return $this->taskExternalLinkModel->getAll($task_id);
+ }
+
+ public function createExternalTaskLink($task_id, $url, $dependency, $type = ExternalLinkManager::TYPE_AUTO, $title = '')
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createExternalTaskLink', $task_id);
+
+ try {
+ $provider = $this->externalLinkManager
+ ->setUserInputText($url)
+ ->setUserInputType($type)
+ ->find();
+
+ $link = $provider->getLink();
+
+ $values = array(
+ 'task_id' => $task_id,
+ 'title' => $title ?: $link->getTitle(),
+ 'url' => $link->getUrl(),
+ 'link_type' => $provider->getType(),
+ 'dependency' => $dependency,
+ );
+
+ list($valid, $errors) = $this->externalLinkValidator->validateCreation($values);
+
+ if (! $valid) {
+ $this->logger->error(__METHOD__.': '.var_export($errors));
+ return false;
+ }
+
+ return $this->taskExternalLinkModel->create($values);
+ } catch (ExternalLinkProviderNotFound $e) {
+ $this->logger->error(__METHOD__.': '.$e->getMessage());
+ }
+
+ return false;
+ }
+
+ public function updateExternalTaskLink($task_id, $link_id, $title = null, $url = null, $dependency = null)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateExternalTaskLink', $task_id);
+
+ $link = $this->taskExternalLinkModel->getById($link_id);
+ $values = $this->filterValues(array(
+ 'title' => $title,
+ 'url' => $url,
+ 'dependency' => $dependency,
+ ));
+
+ $values = array_merge($link, $values);
+ list($valid, $errors) = $this->externalLinkValidator->validateModification($values);
+
+ if (! $valid) {
+ $this->logger->error(__METHOD__.': '.var_export($errors));
+ return false;
+ }
+
+ return $this->taskExternalLinkModel->update($values);
+ }
+
+ public function removeExternalTaskLink($task_id, $link_id)
+ {
+ TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeExternalTaskLink', $task_id);
+ return $this->taskExternalLinkModel->remove($link_id);
+ }
+}