summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-05-27 11:40:07 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-05-27 11:40:07 -0400
commitc482e704697301a982e3c989ac795e0f4c2e899a (patch)
treeaaeba920ba4218792afac198e6b43ea619ff5a53 /app
parent73944ae3687525eb7fafa0a0de2b919b51974542 (diff)
Add a new automatic action: assign a category based on a defined color
Diffstat (limited to 'app')
-rw-r--r--app/Action/TaskAssignCategoryColor.php85
-rw-r--r--app/Locales/de_DE/translations.php3
-rw-r--r--app/Locales/es_ES/translations.php3
-rw-r--r--app/Locales/fr_FR/translations.php3
-rw-r--r--app/Locales/pl_PL/translations.php3
-rw-r--r--app/Locales/pt_BR/translations.php3
-rw-r--r--app/Model/Action.php6
7 files changed, 100 insertions, 6 deletions
diff --git a/app/Action/TaskAssignCategoryColor.php b/app/Action/TaskAssignCategoryColor.php
new file mode 100644
index 00000000..19d7fa9c
--- /dev/null
+++ b/app/Action/TaskAssignCategoryColor.php
@@ -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;
+ }
+}
diff --git a/app/Locales/de_DE/translations.php b/app/Locales/de_DE/translations.php
index 3816a251..24122b00 100644
--- a/app/Locales/de_DE/translations.php
+++ b/app/Locales/de_DE/translations.php
@@ -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:' => '',
diff --git a/app/Locales/es_ES/translations.php b/app/Locales/es_ES/translations.php
index 35ce6c05..d5a8a104 100644
--- a/app/Locales/es_ES/translations.php
+++ b/app/Locales/es_ES/translations.php
@@ -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:' => '',
diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php
index bc9b555f..53ded262 100644
--- a/app/Locales/fr_FR/translations.php
+++ b/app/Locales/fr_FR/translations.php
@@ -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 :',
diff --git a/app/Locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php
index 21b3e5a5..456a7253 100644
--- a/app/Locales/pl_PL/translations.php
+++ b/app/Locales/pl_PL/translations.php
@@ -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:' => '',
diff --git a/app/Locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php
index 9939a0c3..19e3799d 100644
--- a/app/Locales/pt_BR/translations.php
+++ b/app/Locales/pt_BR/translations.php
@@ -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:' => '',
diff --git a/app/Model/Action.php b/app/Model/Action.php
index 7cd917e9..0e3aee71 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -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);
}