From 03fa01ac7b036820ee232d893ec63241918c6012 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 28 Sep 2014 14:26:40 -0400 Subject: Improve automatic actions (check for compatible events/actions/parameters) --- app/Action/TaskAssignColorUser.php | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'app/Action/TaskAssignColorUser.php') diff --git a/app/Action/TaskAssignColorUser.php b/app/Action/TaskAssignColorUser.php index dad46bf9..00680186 100644 --- a/app/Action/TaskAssignColorUser.php +++ b/app/Action/TaskAssignColorUser.php @@ -13,24 +13,17 @@ use Model\Task; class TaskAssignColorUser extends Base { /** - * Task model - * - * @accesss private - * @var \Model\Task - */ - private $task; - - /** - * Constructor + * Get the list of compatible events * * @access public - * @param integer $project_id Project id - * @param \Model\Task $task Task model instance + * @return array */ - public function __construct($project_id, Task $task) + public function getCompatibleEvents() { - parent::__construct($project_id); - $this->task = $task; + return array( + Task::EVENT_CREATE, + Task::EVENT_ASSIGNEE_CHANGE, + ); } /** @@ -62,7 +55,7 @@ class TaskAssignColorUser extends Base } /** - * Execute the action + * Execute the action (change the task color) * * @access public * @param array $data Event data dictionary @@ -70,16 +63,23 @@ class TaskAssignColorUser extends Base */ public function doAction(array $data) { - if ($data['owner_id'] == $this->getParam('user_id')) { - - $this->task->update(array( - 'id' => $data['task_id'], - 'color_id' => $this->getParam('color_id'), - ), false); + $values = array( + 'id' => $data['task_id'], + 'color_id' => $this->getParam('color_id'), + ); - return true; - } + return $this->task->update($values, false); + } - return 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['owner_id'] == $this->getParam('user_id'); } } -- cgit v1.2.3