diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-09-28 14:26:40 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-09-28 14:26:40 -0400 |
commit | 03fa01ac7b036820ee232d893ec63241918c6012 (patch) | |
tree | 295e82e6552ffb044554a11afa95318a4e180f87 /app/Model/Action.php | |
parent | 0c8de6a3f58cde2696ac276b3456f3577d312e2b (diff) |
Improve automatic actions (check for compatible events/actions/parameters)
Diffstat (limited to 'app/Model/Action.php')
-rw-r--r-- | app/Model/Action.php | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/app/Model/Action.php b/app/Model/Action.php index a0c992aa..6b1ebdad 100644 --- a/app/Model/Action.php +++ b/app/Model/Action.php @@ -37,7 +37,7 @@ class Action extends Base public function getAvailableActions() { return array( - 'TaskClose' => t('Close the task'), + 'TaskClose' => t('Close a task'), 'TaskAssignSpecificUser' => t('Assign the task to a specific user'), 'TaskAssignCurrentUser' => t('Assign the task to the person who does the action'), 'TaskDuplicateAnotherProject' => t('Duplicate the task to another project'), @@ -58,7 +58,6 @@ class Action extends Base { return array( Task::EVENT_MOVE_COLUMN => t('Move a task to another column'), - Task::EVENT_MOVE_POSITION => t('Move a task to another position in the same column'), Task::EVENT_UPDATE => t('Task modification'), Task::EVENT_CREATE => t('Task creation'), Task::EVENT_OPEN => t('Open a closed task'), @@ -70,6 +69,28 @@ class Action extends Base } /** + * Return the name and description of compatible actions + * + * @access public + * @param string $action_name Action name + * @return array + */ + public function getCompatibleEvents($action_name) + { + $action = $this->load($action_name, 0, ''); + $compatible_events = $action->getCompatibleEvents(); + $events = array(); + + foreach ($this->getAvailableEvents() as $event_name => $event_description) { + if (in_array($event_name, $compatible_events)) { + $events[$event_name] = $event_description; + } + } + + return $events; + } + + /** * Return actions and parameters for a given project * * @access public @@ -116,7 +137,7 @@ class Action extends Base foreach ($this->getAll() as $action) { - $action = $this->load($action['action_name'], $action['project_id']); + $action = $this->load($action['action_name'], $action['project_id'], $action['event_name']); $params += $action->getActionRequiredParameters(); } @@ -202,7 +223,7 @@ class Action extends Base { foreach ($this->getAll() as $action) { - $listener = $this->load($action['action_name'], $action['project_id']); + $listener = $this->load($action['action_name'], $action['project_id'], $action['event_name']); foreach ($action['params'] as $param) { $listener->setParam($param['name'], $param['value']); @@ -216,21 +237,15 @@ class Action extends Base * Load an action * * @access public - * @param string $name Action class name - * @param integer $project_id Project id - * @throws \LogicException - * @return \Core\Listener Action Instance + * @param string $name Action class name + * @param integer $project_id Project id + * @param string $event Event name + * @return \Core\Listener Action instance */ - public function load($name, $project_id) + public function load($name, $project_id, $event) { $className = '\Action\\'.$name; - - if ($name === 'TaskAssignCurrentUser') { - return new $className($project_id, new Task($this->registry), new Acl($this->registry)); - } - else { - return new $className($project_id, new Task($this->registry)); - } + return new $className($this->registry, $project_id, $event); } /** |