From c482e704697301a982e3c989ac795e0f4c2e899a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Tue, 27 May 2014 11:40:07 -0400 Subject: [PATCH] Add a new automatic action: assign a category based on a defined color --- app/Action/TaskAssignCategoryColor.php | 85 ++++++++++++++++++++++++++ app/Locales/de_DE/translations.php | 3 +- app/Locales/es_ES/translations.php | 3 +- app/Locales/fr_FR/translations.php | 3 +- app/Locales/pl_PL/translations.php | 3 +- app/Locales/pt_BR/translations.php | 3 +- app/Model/Action.php | 6 +- 7 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 app/Action/TaskAssignCategoryColor.php diff --git a/app/Action/TaskAssignCategoryColor.php b/app/Action/TaskAssignCategoryColor.php new file mode 100644 index 000000000..19d7fa9c5 --- /dev/null +++ b/app/Action/TaskAssignCategoryColor.php @@ -0,0 +1,85 @@ +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 3816a2517..24122b003 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 35ce6c054..d5a8a1044 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 bc9b555f7..53ded2620 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 21b3e5a5a..456a72532 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 9939a0c34..19e3799d9 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 7cd917e9b..0e3aee71f 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); }