diff options
Diffstat (limited to 'actions')
-rw-r--r-- | actions/.htaccess | 1 | ||||
-rw-r--r-- | actions/Base.php | 55 | ||||
-rw-r--r-- | actions/task_assign_current_user.php | 45 | ||||
-rw-r--r-- | actions/task_assign_specific_user.php | 45 | ||||
-rw-r--r-- | actions/task_close.php | 39 | ||||
-rw-r--r-- | actions/task_duplicate_another_project.php | 43 |
6 files changed, 228 insertions, 0 deletions
diff --git a/actions/.htaccess b/actions/.htaccess new file mode 100644 index 00000000..14249c50 --- /dev/null +++ b/actions/.htaccess @@ -0,0 +1 @@ +Deny from all
\ No newline at end of file diff --git a/actions/Base.php b/actions/Base.php new file mode 100644 index 00000000..bb9b8bc1 --- /dev/null +++ b/actions/Base.php @@ -0,0 +1,55 @@ +<?php + +namespace Action; + +abstract class Base implements \Core\Listener +{ + private $project_id = 0; + private $params = array(); + + abstract public function doAction(array $data); + abstract public function getActionRequiredParameters(); + abstract public function getEventRequiredParameters(); + + public function __construct($project_id) + { + $this->project_id = $project_id; + } + + public function setParam($name, $value) + { + $this->params[$name] = $value; + } + + public function getParam($name, $default_value = null) + { + return isset($this->params[$name]) ? $this->params[$name] : $default_value; + } + + public function isExecutable(array $data) + { + if (isset($data['project_id']) && $data['project_id'] == $this->project_id && $this->hasRequiredParameters($data)) { + return true; + } + + return false; + } + + public function hasRequiredParameters(array $data) + { + foreach ($this->getEventRequiredParameters() as $parameter) { + if (! isset($data[$parameter])) return false; + } + + return true; + } + + public function execute(array $data) + { + if ($this->isExecutable($data)) { + return $this->doAction($data); + } + + return false; + } +} diff --git a/actions/task_assign_current_user.php b/actions/task_assign_current_user.php new file mode 100644 index 00000000..5a8edd01 --- /dev/null +++ b/actions/task_assign_current_user.php @@ -0,0 +1,45 @@ +<?php + +namespace Action; + +require_once __DIR__.'/base.php'; + +class TaskAssignCurrentUser extends Base +{ + public function __construct($project_id, \Model\Task $task, \Model\Acl $acl) + { + parent::__construct($project_id); + $this->task = $task; + $this->acl = $acl; + } + + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + ); + } + + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + ); + } + + 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/actions/task_assign_specific_user.php b/actions/task_assign_specific_user.php new file mode 100644 index 00000000..8cafde6d --- /dev/null +++ b/actions/task_assign_specific_user.php @@ -0,0 +1,45 @@ +<?php + +namespace Action; + +require_once __DIR__.'/base.php'; + +class TaskAssignSpecificUser extends Base +{ + public function __construct($project_id, \Model\Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + 'user_id' => t('Assignee'), + ); + } + + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + ); + } + + 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/actions/task_close.php b/actions/task_close.php new file mode 100644 index 00000000..4ac579c4 --- /dev/null +++ b/actions/task_close.php @@ -0,0 +1,39 @@ +<?php + +namespace Action; + +require_once __DIR__.'/base.php'; + +class TaskClose extends Base +{ + public function __construct($project_id, \Model\Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + ); + } + + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + ); + } + + 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/actions/task_duplicate_another_project.php b/actions/task_duplicate_another_project.php new file mode 100644 index 00000000..31089c67 --- /dev/null +++ b/actions/task_duplicate_another_project.php @@ -0,0 +1,43 @@ +<?php + +namespace Action; + +require_once __DIR__.'/base.php'; + +class TaskDuplicateAnotherProject extends Base +{ + public function __construct($project_id, \Model\Task $task) + { + parent::__construct($project_id); + $this->task = $task; + } + + public function getActionRequiredParameters() + { + return array( + 'column_id' => t('Column'), + 'project_id' => t('Project'), + ); + } + + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'column_id', + 'project_id', + ); + } + + 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; + } +} |