summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--app/Action/TaskAssignColorLink.php84
-rw-r--r--app/Controller/Action.php2
-rw-r--r--app/Event/TaskLinkEvent.php7
-rw-r--r--app/Locale/cs_CZ/translations.php3
-rw-r--r--app/Locale/da_DK/translations.php3
-rw-r--r--app/Locale/de_DE/translations.php3
-rw-r--r--app/Locale/es_ES/translations.php3
-rw-r--r--app/Locale/fi_FI/translations.php3
-rw-r--r--app/Locale/fr_FR/translations.php3
-rw-r--r--app/Locale/hu_HU/translations.php3
-rw-r--r--app/Locale/it_IT/translations.php3
-rw-r--r--app/Locale/ja_JP/translations.php3
-rw-r--r--app/Locale/nb_NO/translations.php3
-rw-r--r--app/Locale/nl_NL/translations.php3
-rw-r--r--app/Locale/pl_PL/translations.php3
-rw-r--r--app/Locale/pt_BR/translations.php3
-rw-r--r--app/Locale/pt_PT/translations.php3
-rw-r--r--app/Locale/ru_RU/translations.php3
-rw-r--r--app/Locale/sr_Latn_RS/translations.php3
-rw-r--r--app/Locale/sv_SE/translations.php3
-rw-r--r--app/Locale/th_TH/translations.php3
-rw-r--r--app/Locale/tr_TR/translations.php3
-rw-r--r--app/Locale/zh_CN/translations.php3
-rw-r--r--app/Model/Action.php2
-rw-r--r--app/Model/TaskLink.php62
-rw-r--r--app/Template/action/index.php2
-rw-r--r--app/Template/action/params.php3
-rw-r--r--docs/automatic-actions.markdown2
-rw-r--r--tests/units/ActionTaskAssignColorLinkTest.php47
30 files changed, 262 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index a7c75870..b1978d84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@ New features:
* Add config parameter to define session duration
* Add config parameter to disable/enable RememberMe authentication
* Add start/end date for projects
+* Add new automated action to change task color based on the task link
* Add Portuguese (European) translation
* Add Norwegian translation
diff --git a/app/Action/TaskAssignColorLink.php b/app/Action/TaskAssignColorLink.php
new file mode 100644
index 00000000..d055f225
--- /dev/null
+++ b/app/Action/TaskAssignColorLink.php
@@ -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');
+ }
+}
diff --git a/app/Controller/Action.php b/app/Controller/Action.php
index 140c47d3..d92385c7 100644
--- a/app/Controller/Action.php
+++ b/app/Controller/Action.php
@@ -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')
)));
diff --git a/app/Event/TaskLinkEvent.php b/app/Event/TaskLinkEvent.php
new file mode 100644
index 00000000..9499eef9
--- /dev/null
+++ b/app/Event/TaskLinkEvent.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace Event;
+
+class TaskLinkEvent extends GenericEvent
+{
+}
diff --git a/app/Locale/cs_CZ/translations.php b/app/Locale/cs_CZ/translations.php
index ed20a607..f6f51e3f 100644
--- a/app/Locale/cs_CZ/translations.php
+++ b/app/Locale/cs_CZ/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php
index 15ac90e8..c157d227 100644
--- a/app/Locale/da_DK/translations.php
+++ b/app/Locale/da_DK/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php
index 245d974d..c7986d95 100644
--- a/app/Locale/de_DE/translations.php
+++ b/app/Locale/de_DE/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php
index eaef0bce..7e8a16f4 100644
--- a/app/Locale/es_ES/translations.php
+++ b/app/Locale/es_ES/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php
index ecc70961..cf913461 100644
--- a/app/Locale/fi_FI/translations.php
+++ b/app/Locale/fi_FI/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php
index f1594004..a7c724f7 100644
--- a/app/Locale/fr_FR/translations.php
+++ b/app/Locale/fr_FR/translations.php
@@ -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',
);
diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php
index 65ff8a18..a6e2994d 100644
--- a/app/Locale/hu_HU/translations.php
+++ b/app/Locale/hu_HU/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php
index f63dfbec..64f79d0d 100644
--- a/app/Locale/it_IT/translations.php
+++ b/app/Locale/it_IT/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php
index 5984bc11..6b3ed32c 100644
--- a/app/Locale/ja_JP/translations.php
+++ b/app/Locale/ja_JP/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/nb_NO/translations.php b/app/Locale/nb_NO/translations.php
index 523d6101..3d849c97 100644
--- a/app/Locale/nb_NO/translations.php
+++ b/app/Locale/nb_NO/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php
index b4e67e6b..f32d713f 100644
--- a/app/Locale/nl_NL/translations.php
+++ b/app/Locale/nl_NL/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php
index ecf00553..e711f03e 100644
--- a/app/Locale/pl_PL/translations.php
+++ b/app/Locale/pl_PL/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php
index 348886b3..a64a9374 100644
--- a/app/Locale/pt_BR/translations.php
+++ b/app/Locale/pt_BR/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/pt_PT/translations.php b/app/Locale/pt_PT/translations.php
index 79c09f74..e88ab3ec 100644
--- a/app/Locale/pt_PT/translations.php
+++ b/app/Locale/pt_PT/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php
index 6f891d1c..339bbd4d 100644
--- a/app/Locale/ru_RU/translations.php
+++ b/app/Locale/ru_RU/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php
index ca1f786b..e8a3caff 100644
--- a/app/Locale/sr_Latn_RS/translations.php
+++ b/app/Locale/sr_Latn_RS/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php
index 0f3b18fe..28928081 100644
--- a/app/Locale/sv_SE/translations.php
+++ b/app/Locale/sv_SE/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php
index 0d68fd4c..f5cae497 100644
--- a/app/Locale/th_TH/translations.php
+++ b/app/Locale/th_TH/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php
index 4b91c822..3d3cd902 100644
--- a/app/Locale/tr_TR/translations.php
+++ b/app/Locale/tr_TR/translations.php
@@ -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' => '',
);
diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php
index 12978c9c..ac3eecae 100644
--- a/app/Locale/zh_CN/translations.php
+++ b/app/Locale/zh_CN/translations.php
@@ -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' => '',
);
diff --git a/app/Model/Action.php b/app/Model/Action.php
index 3759653d..87058cce 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -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'),
diff --git a/app/Model/TaskLink.php b/app/Model/TaskLink.php
index 3fdbd04b..466e44df 100644
--- a/app/Model/TaskLink.php
+++ b/app/Model/TaskLink.php
@@ -4,6 +4,7 @@ namespace Model;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
+use Event\TaskLinkEvent;
/**
* TaskLink model
@@ -22,6 +23,13 @@ class TaskLink extends Base
const TABLE = 'task_has_links';
/**
+ * Events
+ *
+ * @var string
+ */
+ const EVENT_CREATE_UPDATE = 'tasklink.create_update';
+
+ /**
* Get a task link
*
* @access public
@@ -114,6 +122,20 @@ class TaskLink extends Base
}
/**
+ * 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
*
* @access public
@@ -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;
}
/**
diff --git a/app/Template/action/index.php b/app/Template/action/index.php
index 6898fc26..bf2f7475 100644
--- a/app/Template/action/index.php
+++ b/app/Template/action/index.php
@@ -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 ?>
diff --git a/app/Template/action/params.php b/app/Template/action/params.php
index 759c5968..dcfaa9cc 100644
--- a/app/Template/action/params.php
+++ b/app/Template/action/params.php
@@ -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) ?>
diff --git a/docs/automatic-actions.markdown b/docs/automatic-actions.markdown
index 6fb0005d..c4e2bc4c 100644
--- a/docs/automatic-actions.markdown
+++ b/docs/automatic-actions.markdown
@@ -37,6 +37,7 @@ List of available events
- Closing a task
- Task creation or modification
- Task assignee change
+- Task link created or updated
- Github commit received
- Github issue opened
- Github issue closed
@@ -77,6 +78,7 @@ List of available actions
- Automatically update the start date
- Move the task to another column when the category is changed
- Send a task by email to someone
+- Change task color when using a specific task link
Examples
--------
diff --git a/tests/units/ActionTaskAssignColorLinkTest.php b/tests/units/ActionTaskAssignColorLinkTest.php
new file mode 100644
index 00000000..b0cd269e
--- /dev/null
+++ b/tests/units/ActionTaskAssignColorLinkTest.php
@@ -0,0 +1,47 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Event\TaskLinkEvent;
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\TaskLink;
+use Model\Project;
+
+class ActionTaskAssignColorLinkTest extends Base
+{
+ public function testExecute()
+ {
+ $action = new Action\TaskAssignColorLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
+ $action->setParam('link_id', 2);
+ $action->setParam('color_id', 'green');
+
+ // We create a task in the first column
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ // The color should be yellow
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ $event = array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'link_id' => 2,
+ );
+
+ // Our event should be executed
+ $this->assertTrue($action->execute(new TaskLinkEvent($event)));
+
+ // The color should be green
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('green', $task['color_id']);
+ }
+}