diff options
author | Christian Wolter <wolter@b1-systems.de> | 2018-01-22 19:54:03 +0100 |
---|---|---|
committer | fguillot <fred@kanboard.net> | 2018-01-22 10:54:03 -0800 |
commit | fba52083085733dd5c891839123d0c1845ef119a (patch) | |
tree | 10937f709f4ad056bc31dd877b6962f6a6bc1aa9 /app | |
parent | e76ac1d0442300ef4e38ff792e36e92d2ff681e3 (diff) |
Add action to change color once start date is reached
Diffstat (limited to 'app')
-rw-r--r-- | app/Action/TaskAssignColorOnStartDate.php | 100 | ||||
-rw-r--r-- | app/ServiceProvider/ActionProvider.php | 2 |
2 files changed, 102 insertions, 0 deletions
diff --git a/app/Action/TaskAssignColorOnStartDate.php b/app/Action/TaskAssignColorOnStartDate.php new file mode 100644 index 00000000..39817845 --- /dev/null +++ b/app/Action/TaskAssignColorOnStartDate.php @@ -0,0 +1,100 @@ +<?php + +namespace Kanboard\Action; + +use Kanboard\Model\TaskModel; + + +/** + * Assign a color when preset start date is reached + * + * @package Kanboard\Action + * @author Christian Wolter + */ +class TaskAssignColorOnStartDate extends Base +{ + /** + * Get action description + * + * @access public + * @return string + */ + public function getDescription() + { + return t('Assign automatically a color when preset start date is reached'); + } + + /** + * Get the list of compatible events + * + * @access public + * @return array + */ + public function getCompatibleEvents() + { + return array( + TaskModel::EVENT_DAILY_CRONJOB, + ); + } + + /** + * Get the required parameter for the action + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'color_id' => t('Color'), + ); + } + + /** + * Get all tasks + * + * @access public + * @return array + */ + + public function getEventRequiredParameters() + { + return array('tasks'); + } + + /** + * 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) + { + $results = array(); + + foreach ($data['tasks'] as $task) { + if ($task['date_started'] <= time() && $task['date_started'] > 0 && $task['color_id'] != $this->getParam('color_id')) { + $values = array( + 'id' => $task['id'], + 'color_id' => $this->getParam('color_id'), + ); + $results[] = $this->taskModificationModel->update($values, false); + } + } + + return in_array(true, $results, true); + } + + /** + * 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 count($data['tasks']) > 0; + } +} diff --git a/app/ServiceProvider/ActionProvider.php b/app/ServiceProvider/ActionProvider.php index 73d7f171..99a69247 100644 --- a/app/ServiceProvider/ActionProvider.php +++ b/app/ServiceProvider/ActionProvider.php @@ -5,6 +5,7 @@ namespace Kanboard\ServiceProvider; use Pimple\Container; use Pimple\ServiceProviderInterface; use Kanboard\Action\TaskAssignColorOnDueDate; +use Kanboard\Action\TaskAssignColorOnStartDate; use Kanboard\Action\TaskAssignColorPriority; use Kanboard\Action\TaskAssignDueDateOnCreation; use Kanboard\Action\TaskMoveColumnClosed; @@ -100,6 +101,7 @@ class ActionProvider implements ServiceProviderInterface $container['actionManager']->register(new TaskAssignColorOnDueDate($container)); $container['actionManager']->register(new SubtaskTimerMoveTaskColumn($container)); $container['actionManager']->register(new StopSubtaskTimerMoveTaskColumn($container)); + $container['actionManager']->register(new TaskAssignColorOnStartDate($container)); return $container; } |