Add new automated action to change task color based on the task link
This commit is contained in:
84
app/Action/TaskAssignColorLink.php
Normal file
84
app/Action/TaskAssignColorLink.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Action;
|
||||
|
||||
use Model\TaskLink;
|
||||
|
||||
/**
|
||||
* Assign a color to a specific task link
|
||||
*
|
||||
* @package action
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskAssignColorLink extends Base
|
||||
{
|
||||
/**
|
||||
* Get the list of compatible events
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getCompatibleEvents()
|
||||
{
|
||||
return array(
|
||||
TaskLink::EVENT_CREATE_UPDATE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required parameter for the action (defined by the user)
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getActionRequiredParameters()
|
||||
{
|
||||
return array(
|
||||
'color_id' => t('Color'),
|
||||
'link_id' => t('Link type'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required parameter for the event
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getEventRequiredParameters()
|
||||
{
|
||||
return array(
|
||||
'task_id',
|
||||
'link_id',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the action (change the task color)
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$values = array(
|
||||
'id' => $data['task_id'],
|
||||
'color_id' => $this->getParam('color_id'),
|
||||
);
|
||||
|
||||
return $this->taskModification->update($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the event data meet the action condition
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Event data dictionary
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRequiredCondition(array $data)
|
||||
{
|
||||
return $data['link_id'] == $this->getParam('link_id');
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ class Action extends Base
|
||||
'projects_list' => $this->project->getList(false),
|
||||
'colors_list' => $this->color->getList(),
|
||||
'categories_list' => $this->category->getList($project['id']),
|
||||
'links_list' => $this->link->getList(0, false),
|
||||
'title' => t('Automatic actions')
|
||||
)));
|
||||
}
|
||||
@@ -89,6 +90,7 @@ class Action extends Base
|
||||
'projects_list' => $projects_list,
|
||||
'colors_list' => $this->color->getList(),
|
||||
'categories_list' => $this->category->getList($project['id']),
|
||||
'links_list' => $this->link->getList(0, false),
|
||||
'project' => $project,
|
||||
'title' => t('Automatic actions')
|
||||
)));
|
||||
|
||||
7
app/Event/TaskLinkEvent.php
Normal file
7
app/Event/TaskLinkEvent.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Event;
|
||||
|
||||
class TaskLinkEvent extends GenericEvent
|
||||
{
|
||||
}
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1051,4 +1051,7 @@ return array(
|
||||
'Projects Gantt chart' => 'Diagramme de Gantt des projets',
|
||||
'Start date: %s' => 'Date de début : %s',
|
||||
'End date: %s' => 'Date de fin : %s',
|
||||
'Link type' => 'Type de lien',
|
||||
'Change task color when using a specific task link' => 'Changer la couleur de la tâche lorsqu\'un lien spécifique est utilisé',
|
||||
'Task link creation or modification' => 'Création ou modification d\'un lien sur une tâche',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -1049,4 +1049,7 @@ return array(
|
||||
// 'Projects Gantt chart' => '',
|
||||
// 'Start date: %s' => '',
|
||||
// 'End date: %s' => '',
|
||||
// 'Link type' => '',
|
||||
// 'Change task color when using a specific task link' => '',
|
||||
// 'Task link creation or modification' => '',
|
||||
);
|
||||
|
||||
@@ -59,6 +59,7 @@ class Action extends Base
|
||||
'TaskUpdateStartDate' => t('Automatically update the start date'),
|
||||
'TaskMoveColumnCategoryChange' => t('Move the task to another column when the category is changed'),
|
||||
'TaskEmail' => t('Send a task by email to someone'),
|
||||
'TaskAssignColorLink' => t('Change task color when using a specific task link'),
|
||||
);
|
||||
|
||||
asort($values);
|
||||
@@ -75,6 +76,7 @@ class Action extends Base
|
||||
public function getAvailableEvents()
|
||||
{
|
||||
$values = array(
|
||||
TaskLink::EVENT_CREATE_UPDATE => t('Task link creation or modification'),
|
||||
Task::EVENT_MOVE_COLUMN => t('Move a task to another column'),
|
||||
Task::EVENT_UPDATE => t('Task modification'),
|
||||
Task::EVENT_CREATE => t('Task creation'),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Model;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Event\TaskLinkEvent;
|
||||
|
||||
/**
|
||||
* TaskLink model
|
||||
@@ -21,6 +22,13 @@ class TaskLink extends Base
|
||||
*/
|
||||
const TABLE = 'task_has_links';
|
||||
|
||||
/**
|
||||
* Events
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const EVENT_CREATE_UPDATE = 'tasklink.create_update';
|
||||
|
||||
/**
|
||||
* Get a task link
|
||||
*
|
||||
@@ -113,6 +121,20 @@ class TaskLink extends Base
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish events
|
||||
*
|
||||
* @access private
|
||||
* @param array $events
|
||||
*/
|
||||
private function fireEvents(array $events)
|
||||
{
|
||||
foreach ($events as $event) {
|
||||
$event['project_id'] = $this->taskFinder->getProjectId($event['task_id']);
|
||||
$this->container['dispatcher']->dispatch(self::EVENT_CREATE_UPDATE, new TaskLinkEvent($event));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new link
|
||||
*
|
||||
@@ -124,29 +146,37 @@ class TaskLink extends Base
|
||||
*/
|
||||
public function create($task_id, $opposite_task_id, $link_id)
|
||||
{
|
||||
$events = array();
|
||||
$this->db->startTransaction();
|
||||
|
||||
// Get opposite link
|
||||
$opposite_link_id = $this->link->getOppositeLinkId($link_id);
|
||||
|
||||
// Create the original task link
|
||||
$this->db->table(self::TABLE)->insert(array(
|
||||
$values = array(
|
||||
'task_id' => $task_id,
|
||||
'opposite_task_id' => $opposite_task_id,
|
||||
'link_id' => $link_id,
|
||||
));
|
||||
);
|
||||
|
||||
// Create the original task link
|
||||
$this->db->table(self::TABLE)->insert($values);
|
||||
$task_link_id = $this->db->getLastId();
|
||||
$events[] = $values;
|
||||
|
||||
// Create the opposite task link
|
||||
$this->db->table(self::TABLE)->insert(array(
|
||||
$values = array(
|
||||
'task_id' => $opposite_task_id,
|
||||
'opposite_task_id' => $task_id,
|
||||
'link_id' => $opposite_link_id,
|
||||
));
|
||||
);
|
||||
|
||||
$this->db->table(self::TABLE)->insert($values);
|
||||
$events[] = $values;
|
||||
|
||||
$this->db->closeTransaction();
|
||||
|
||||
$this->fireEvents($events);
|
||||
|
||||
return (int) $task_link_id;
|
||||
}
|
||||
|
||||
@@ -162,6 +192,7 @@ class TaskLink extends Base
|
||||
*/
|
||||
public function update($task_link_id, $task_id, $opposite_task_id, $link_id)
|
||||
{
|
||||
$events = array();
|
||||
$this->db->startTransaction();
|
||||
|
||||
// Get original task link
|
||||
@@ -174,22 +205,33 @@ class TaskLink extends Base
|
||||
$opposite_link_id = $this->link->getOppositeLinkId($link_id);
|
||||
|
||||
// Update the original task link
|
||||
$rs1 = $this->db->table(self::TABLE)->eq('id', $task_link_id)->update(array(
|
||||
$values = array(
|
||||
'task_id' => $task_id,
|
||||
'opposite_task_id' => $opposite_task_id,
|
||||
'link_id' => $link_id,
|
||||
));
|
||||
);
|
||||
|
||||
$rs1 = $this->db->table(self::TABLE)->eq('id', $task_link_id)->update($values);
|
||||
$events[] = $values;
|
||||
|
||||
// Update the opposite link
|
||||
$rs2 = $this->db->table(self::TABLE)->eq('id', $opposite_task_link['id'])->update(array(
|
||||
$values = array(
|
||||
'task_id' => $opposite_task_id,
|
||||
'opposite_task_id' => $task_id,
|
||||
'link_id' => $opposite_link_id,
|
||||
));
|
||||
);
|
||||
|
||||
$rs2 = $this->db->table(self::TABLE)->eq('id', $opposite_task_link['id'])->update($values);
|
||||
$events[] = $values;
|
||||
|
||||
$this->db->closeTransaction();
|
||||
|
||||
return $rs1 && $rs2;
|
||||
if ($rs1 && $rs2) {
|
||||
$this->fireEvents($events);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
<?= $this->text->in($param['value'], $colors_list) ?>
|
||||
<?php elseif ($this->text->contains($param['name'], 'category_id')): ?>
|
||||
<?= $this->text->in($param['value'], $categories_list) ?>
|
||||
<?php elseif ($this->text->contains($param['name'], 'link_id')): ?>
|
||||
<?= $this->text->in($param['value'], $links_list) ?>
|
||||
<?php else: ?>
|
||||
<?= $this->e($param['value']) ?>
|
||||
<?php endif ?>
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
<?php elseif ($this->text->contains($param_name, 'category_id')): ?>
|
||||
<?= $this->form->label($param_desc, $param_name) ?>
|
||||
<?= $this->form->select('params['.$param_name.']', $categories_list, $values) ?><br/>
|
||||
<?php elseif ($this->text->contains($param_name, 'link_id')): ?>
|
||||
<?= $this->form->label($param_desc, $param_name) ?>
|
||||
<?= $this->form->select('params['.$param_name.']', $links_list, $values) ?><br/>
|
||||
<?php else: ?>
|
||||
<?= $this->form->label($param_desc, $param_name) ?>
|
||||
<?= $this->form->text('params['.$param_name.']', $values) ?>
|
||||
|
||||
Reference in New Issue
Block a user