From 2230dd4e6b148346c0ec596b9e3e12996a762ed8 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 22 May 2014 12:28:28 -0400 Subject: Code refactoring (add autoloader and change files organization) --- app/Action/Base.php | 142 +++++++++++++++++++++++++++++ app/Action/TaskAssignColorCategory.php | 85 +++++++++++++++++ app/Action/TaskAssignColorUser.php | 85 +++++++++++++++++ app/Action/TaskAssignCurrentUser.php | 95 +++++++++++++++++++ app/Action/TaskAssignSpecificUser.php | 85 +++++++++++++++++ app/Action/TaskClose.php | 79 ++++++++++++++++ app/Action/TaskDuplicateAnotherProject.php | 83 +++++++++++++++++ 7 files changed, 654 insertions(+) create mode 100644 app/Action/Base.php create mode 100644 app/Action/TaskAssignColorCategory.php create mode 100644 app/Action/TaskAssignColorUser.php create mode 100644 app/Action/TaskAssignCurrentUser.php create mode 100644 app/Action/TaskAssignSpecificUser.php create mode 100644 app/Action/TaskClose.php create mode 100644 app/Action/TaskDuplicateAnotherProject.php (limited to 'app/Action') 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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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; + } +} -- cgit v1.2.3