Add a new automatic action: assign a category based on a defined color
This commit is contained in:
parent
73944ae368
commit
c482e70469
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace Action;
|
||||
|
||||
use Model\Task;
|
||||
|
||||
/**
|
||||
* Set a category automatically according to the color
|
||||
*
|
||||
* @package action
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskAssignCategoryColor 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',
|
||||
'color_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['color_id'] == $this->getParam('color_id')) {
|
||||
|
||||
$this->task->update(array(
|
||||
'id' => $data['task_id'],
|
||||
'category_id' => $this->getParam('category_id'),
|
||||
));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -312,7 +312,8 @@ return array(
|
|||
// 'Unable to remove this task.' => '',
|
||||
// 'Remove a task' => '',
|
||||
// 'Do you really want to remove this task: "%s"?' => '',
|
||||
// 'Assign a color to a specific category' => '',
|
||||
// 'Assign automatically a color based on a category' => '',
|
||||
// 'Assign automatically a category based on a color' => '',
|
||||
// 'Task creation or modification' => '',
|
||||
// 'Category' => '',
|
||||
// 'Category:' => '',
|
||||
|
|
|
|||
|
|
@ -310,7 +310,8 @@ return array(
|
|||
// 'Unable to remove this task.' => '',
|
||||
// 'Remove a task' => '',
|
||||
// 'Do you really want to remove this task: "%s"?' => '',
|
||||
// 'Assign a color to a specific category' => '',
|
||||
// 'Assign automatically a color based on a category' => '',
|
||||
// 'Assign automatically a category based on a color' => '',
|
||||
// 'Task creation or modification' => '',
|
||||
// 'Category' => '',
|
||||
// 'Category:' => '',
|
||||
|
|
|
|||
|
|
@ -310,7 +310,8 @@ return array(
|
|||
'Unable to remove this task.' => 'Impossible de supprimer cette tâche.',
|
||||
'Remove a task' => 'Supprimer une tâche',
|
||||
'Do you really want to remove this task: "%s"?' => 'Voulez-vous vraiment supprimer cette tâche « %s » ?',
|
||||
'Assign a color to a specific category' => 'Assigner une couleur à une catégorie spécifique',
|
||||
'Assign automatically a color based on a category' => 'Assigner automatiquement une couleur par rapport à une catégorie définie',
|
||||
'Assign automatically a category based on a color' => 'Assigner automatiquement une catégorie par rapport à une couleur définie',
|
||||
'Task creation or modification' => 'Création ou modification d\'une tâche',
|
||||
'Category' => 'Catégorie',
|
||||
'Category:' => 'Catégorie :',
|
||||
|
|
|
|||
|
|
@ -315,7 +315,8 @@ return array(
|
|||
// 'Unable to remove this task.' => '',
|
||||
// 'Remove a task' => '',
|
||||
// 'Do you really want to remove this task: "%s"?' => '',
|
||||
// 'Assign a color to a specific category' => '',
|
||||
// 'Assign automatically a color based on a category' => '',
|
||||
// 'Assign automatically a category based on a color' => '',
|
||||
// 'Task creation or modification' => '',
|
||||
// 'Category' => '',
|
||||
// 'Category:' => '',
|
||||
|
|
|
|||
|
|
@ -311,7 +311,8 @@ return array(
|
|||
// 'Unable to remove this task.' => '',
|
||||
// 'Remove a task' => '',
|
||||
// 'Do you really want to remove this task: "%s"?' => '',
|
||||
// 'Assign a color to a specific category' => '',
|
||||
// 'Assign automatically a color based on a category' => '',
|
||||
// 'Assign automatically a category based on a color' => '',
|
||||
// 'Task creation or modification' => '',
|
||||
// 'Category' => '',
|
||||
// 'Category:' => '',
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ class Action extends Base
|
|||
'TaskAssignCurrentUser' => t('Assign the task to the person who does the action'),
|
||||
'TaskDuplicateAnotherProject' => t('Duplicate the task to another project'),
|
||||
'TaskAssignColorUser' => t('Assign a color to a specific user'),
|
||||
'TaskAssignColorCategory' => t('Assign a color to a specific category'),
|
||||
'TaskAssignColorCategory' => t('Assign automatically a color based on a category'),
|
||||
'TaskAssignCategoryColor' => t('Assign automatically a category based on a color'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -237,6 +238,9 @@ class Action extends Base
|
|||
case 'TaskAssignColorCategory':
|
||||
$className = '\Action\TaskAssignColorCategory';
|
||||
return new $className($project_id, new Task($this->db, $this->event));
|
||||
case 'TaskAssignCategoryColor':
|
||||
$className = '\Action\TaskAssignCategoryColor';
|
||||
return new $className($project_id, new Task($this->db, $this->event));
|
||||
default:
|
||||
throw new LogicException('Action not found: '.$name);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue