summaryrefslogtreecommitdiff
path: root/app/Action
diff options
context:
space:
mode:
authorOlivier Maridat <olivier.maridat@trialog.com>2015-10-26 14:26:35 +0100
committerOlivier Maridat <olivier.maridat@trialog.com>2015-10-26 14:26:35 +0100
commit6d354e3ea9eb91f06c61f3dfeba64f3db7ec57d2 (patch)
tree3fe024a5ac68997c7995b5019d3bbe14aa561c33 /app/Action
parent06e9486c59831cdd1630647ea7474a39879a37da (diff)
Add new action: Assign automatically a category based on a link
Diffstat (limited to 'app/Action')
-rw-r--r--app/Action/TaskAssignCategoryLink.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/app/Action/TaskAssignCategoryLink.php b/app/Action/TaskAssignCategoryLink.php
new file mode 100644
index 00000000..8398facf
--- /dev/null
+++ b/app/Action/TaskAssignCategoryLink.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace Kanboard\Action;
+
+use Kanboard\Model\TaskLink;
+
+/**
+ * Set a category automatically according to a task link
+ *
+ * @package action
+ * @author Olivier Maridat
+ */
+class TaskAssignCategoryLink extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ TaskLink::EVENT_CREATE_UPDATE,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'category_id' => t('Category'),
+ 'link_id' => t('Link id'),
+ );
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'link_id',
+ );
+ }
+
+ /**
+ * Execute the action (change the category)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ $values = array(
+ 'id' => $data['task_id'],
+ 'category_id' => isset($data['category_id']) ? $data['category_id'] : $this->getParam('category_id'),
+ );
+
+ return $this->taskModification->update($values);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return $data['link_id'] == $this->getParam('link_id');
+ }
+}