Automatic actions
This commit is contained in:
1
actions/.htaccess
Normal file
1
actions/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
Deny from all
|
||||
55
actions/Base.php
Normal file
55
actions/Base.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
45
actions/task_assign_current_user.php
Normal file
45
actions/task_assign_current_user.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
45
actions/task_assign_specific_user.php
Normal file
45
actions/task_assign_specific_user.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
39
actions/task_close.php
Normal file
39
actions/task_close.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
43
actions/task_duplicate_another_project.php
Normal file
43
actions/task_duplicate_another_project.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user