diff options
Diffstat (limited to 'app/Action')
-rw-r--r-- | app/Action/Base.php | 142 | ||||
-rw-r--r-- | app/Action/TaskAssignColorCategory.php | 85 | ||||
-rw-r--r-- | app/Action/TaskAssignColorUser.php | 85 | ||||
-rw-r--r-- | app/Action/TaskAssignCurrentUser.php | 95 | ||||
-rw-r--r-- | app/Action/TaskAssignSpecificUser.php | 85 | ||||
-rw-r--r-- | app/Action/TaskClose.php | 79 | ||||
-rw-r--r-- | app/Action/TaskDuplicateAnotherProject.php | 83 |
7 files changed, 654 insertions, 0 deletions
diff --git a/app/Action/Base.php b/app/Action/Base.php new file mode 100644 index 00000000..14b0a3c0 --- /dev/null +++ b/app/Action/Base.php @@ -0,0 +1,142 @@ +<?php + +namespace Action; + +use Core\Listener; + +/** + * Base class for automatic actions + * + * @package action + * @author Frederic Guillot + */ +abstract class Base implements Listener +{ + /** + * Project id + * + * @access private + * @var integer + */ + private $project_id = 0; + + /** + * User parameters + * + * @access private + * @var array + */ + private $params = array(); + + /** + * Execute the action + * + * @abstract + * @access public + * @param array $data Event data dictionary + * @return bool True if the action was executed or false when not executed + */ + abstract public function doAction(array $data); + + /** + * Get the required parameter for the action (defined by the user) + * + * @abstract + * @access public + * @return array + */ + abstract public function getActionRequiredParameters(); + + /** + * Get the required parameter for the event (check if for the event data) + * + * @abstract + * @access public + * @return array + */ + abstract public function getEventRequiredParameters(); + + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + */ + public function __construct($project_id) + { + $this->project_id = $project_id; + } + + /** + * Set an user defined parameter + * + * @access public + * @param string $name Parameter name + * @param mixed $value Value + */ + public function setParam($name, $value) + { + $this->params[$name] = $value; + } + + /** + * Get an user defined parameter + * + * @access public + * @param string $name Parameter name + * @param mixed $default_value Default value + * @return mixed + */ + public function getParam($name, $default_value = null) + { + return isset($this->params[$name]) ? $this->params[$name] : $default_value; + } + + /** + * Check if an action is executable (right project and required parameters) + * + * @access public + * @param array $data Event data dictionary + * @return bool True if the action is executable + */ + public function isExecutable(array $data) + { + if (isset($data['project_id']) && $data['project_id'] == $this->project_id && $this->hasRequiredParameters($data)) { + return true; + } + + return false; + } + + /** + * Check if the event data has required parameters to execute the action + * + * @access public + * @param array $data Event data dictionary + * @return bool True if all keys are there + */ + public function hasRequiredParameters(array $data) + { + foreach ($this->getEventRequiredParameters() as $parameter) { + if (! isset($data[$parameter])) return false; + } + + return true; + } + + /** + * Execute the action + * + * @access public + * @param array $data Event data dictionary + * @return bool True if the action was executed or false when not executed + */ + public function execute(array $data) + { + if ($this->isExecutable($data)) { + return $this->doAction($data); + } + + return false; + } +} diff --git a/app/Action/TaskAssignColorCategory.php b/app/Action/TaskAssignColorCategory.php new file mode 100644 index 00000000..4304d084 --- /dev/null +++ b/app/Action/TaskAssignColorCategory.php @@ -0,0 +1,85 @@ +<?php + +namespace Action; + +use Model\Task; + +/** + * Assign a color to a specific category + * + * @package action + * @author Frederic Guillot + */ +class TaskAssignColorCategory extends Base +{ + /** + * Task model + * + * @accesss private + * @var \Model\Task + */ + private $task; + + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + * @param \Model\Task $task Task model instance + */ + public function __construct($project_id, Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'color_id' => t('Color'), + 'category_id' => t('Category'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'category_id', + ); + } + + /** + * Execute the action + * + * @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) + { + if ($data['category_id'] == $this->getParam('category_id')) { + + $this->task->update(array( + 'id' => $data['task_id'], + 'color_id' => $this->getParam('color_id'), + )); + + return true; + } + + return false; + } +} diff --git a/app/Action/TaskAssignColorUser.php b/app/Action/TaskAssignColorUser.php new file mode 100644 index 00000000..9ff140b3 --- /dev/null +++ b/app/Action/TaskAssignColorUser.php @@ -0,0 +1,85 @@ +<?php + +namespace Action; + +use Model\Task; + +/** + * Assign a color to a specific user + * + * @package action + * @author Frederic Guillot + */ +class TaskAssignColorUser extends Base +{ + /** + * Task model + * + * @accesss private + * @var \Model\Task + */ + private $task; + + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + * @param \Model\Task $task Task model instance + */ + public function __construct($project_id, Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'color_id' => t('Color'), + 'user_id' => t('Assignee'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'owner_id', + ); + } + + /** + * Execute the action + * + * @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) + { + if ($data['owner_id'] == $this->getParam('user_id')) { + + $this->task->update(array( + 'id' => $data['task_id'], + 'color_id' => $this->getParam('color_id'), + )); + + return true; + } + + return false; + } +} diff --git a/app/Action/TaskAssignCurrentUser.php b/app/Action/TaskAssignCurrentUser.php new file mode 100644 index 00000000..1c038966 --- /dev/null +++ b/app/Action/TaskAssignCurrentUser.php @@ -0,0 +1,95 @@ +<?php + +namespace Action; + +use Model\Task; +use Model\Acl; + +/** + * Assign a task to the logged user + * + * @package action + * @author Frederic Guillot + */ +class TaskAssignCurrentUser extends Base +{ + /** + * Task model + * + * @accesss private + * @var \Model\Task + */ + private $task; + + /** + * Acl model + * + * @accesss private + * @var \Model\Acl + */ + private $acl; + + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + * @param \Model\Task $task Task model instance + * @param \Model\Acl $acl Acl model instance + */ + public function __construct($project_id, Task $task, Acl $acl) + { + parent::__construct($project_id); + $this->task = $task; + $this->acl = $acl; + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + ); + } + + /** + * Execute the action + * + * @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) + { + if ($data['column_id'] == $this->getParam('column_id')) { + + $this->task->update(array( + 'id' => $data['task_id'], + 'owner_id' => $this->acl->getUserId(), + )); + + return true; + } + + return false; + } +} diff --git a/app/Action/TaskAssignSpecificUser.php b/app/Action/TaskAssignSpecificUser.php new file mode 100644 index 00000000..8c379bcc --- /dev/null +++ b/app/Action/TaskAssignSpecificUser.php @@ -0,0 +1,85 @@ +<?php + +namespace Action; + +use Model\Task; + +/** + * Assign a task to a specific user + * + * @package action + * @author Frederic Guillot + */ +class TaskAssignSpecificUser extends Base +{ + /** + * Task model + * + * @accesss private + * @var \Model\Task + */ + private $task; + + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + * @param \Model\Task $task Task model instance + */ + public function __construct($project_id, Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + 'user_id' => t('Assignee'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + ); + } + + /** + * Execute the action + * + * @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) + { + if ($data['column_id'] == $this->getParam('column_id')) { + + $this->task->update(array( + 'id' => $data['task_id'], + 'owner_id' => $this->getParam('user_id'), + )); + + return true; + } + + return false; + } +} diff --git a/app/Action/TaskClose.php b/app/Action/TaskClose.php new file mode 100644 index 00000000..32887d3c --- /dev/null +++ b/app/Action/TaskClose.php @@ -0,0 +1,79 @@ +<?php + +namespace Action; + +use Model\Task; + +/** + * Close automatically a task + * + * @package action + * @author Frederic Guillot + */ +class TaskClose extends Base +{ + /** + * Task model + * + * @accesss private + * @var \Model\Task + */ + private $task; + + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + * @param \Model\Task $task Task model instance + */ + public function __construct($project_id, Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + ); + } + + /** + * Execute the action + * + * @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) + { + if ($data['column_id'] == $this->getParam('column_id')) { + $this->task->close($data['task_id']); + return true; + } + + return false; + } +} diff --git a/app/Action/TaskDuplicateAnotherProject.php b/app/Action/TaskDuplicateAnotherProject.php new file mode 100644 index 00000000..7ef0f6ab --- /dev/null +++ b/app/Action/TaskDuplicateAnotherProject.php @@ -0,0 +1,83 @@ +<?php + +namespace Action; + +use Model\Task; + +/** + * Duplicate a task to another project + * + * @package action + * @author Frederic Guillot + */ +class TaskDuplicateAnotherProject extends Base +{ + /** + * Task model + * + * @accesss private + * @var \Model\Task + */ + private $task; + + /** + * Constructor + * + * @access public + * @param integer $project_id Project id + * @param \Model\Task $task Task model instance + */ + public function __construct($project_id, Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + 'project_id' => t('Project'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + 'project_id', + ); + } + + /** + * Execute the action + * + * @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) + { + if ($data['column_id'] == $this->getParam('column_id') && $data['project_id'] != $this->getParam('project_id')) { + + $this->task->duplicateToAnotherProject($data['task_id'], $this->getParam('project_id')); + + return true; + } + + return false; + } +} |