diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-05-04 22:52:08 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-05-04 22:52:08 -0400 |
commit | d5c95e8240639975f61f726e9722900a8d54611f (patch) | |
tree | 3bf55bda241616303e859b0aa8f829133f290a15 /app/Action/TaskAssignColorPriority.php | |
parent | 1e1c127a8548b65751eb332bf8edf5842d14d468 (diff) |
Added automated action to change task color based on the priority
Diffstat (limited to 'app/Action/TaskAssignColorPriority.php')
-rw-r--r-- | app/Action/TaskAssignColorPriority.php | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/app/Action/TaskAssignColorPriority.php b/app/Action/TaskAssignColorPriority.php new file mode 100644 index 00000000..2e24f9ef --- /dev/null +++ b/app/Action/TaskAssignColorPriority.php @@ -0,0 +1,95 @@ +<?php + +namespace Kanboard\Action; + +use Kanboard\Model\Task; + +/** + * Assign a color to a priority + * + * @package action + * @author Frederic Guillot + */ +class TaskAssignColorPriority extends Base +{ + /** + * Get automatic action description + * + * @access public + * @return string + */ + public function getDescription() + { + return t('Assign automatically a color based on a priority'); + } + + /** + * Get the list of compatible events + * + * @access public + * @return array + */ + public function getCompatibleEvents() + { + return array( + Task::EVENT_CREATE_UPDATE, + ); + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'color_id' => t('Color'), + 'priority' => t('Priority'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'priority', + ); + } + + /** + * Execute the action (change the task color) + * + * @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'], + 'color_id' => $this->getParam('color_id'), + ); + + return $this->taskModification->update($values, false); + } + + /** + * 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['priority'] == $this->getParam('priority'); + } +} |