Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Kanboard\Plugin\RTAutomaticsActions\Action;
- use Kanboard\Action\Base;
- use Kanboard\Model\TaskModel;
- use Kanboard\Model\TagModel;
- use Kanboard\Model\TaskTagModel;
- class TaskAssignTagColor extends Base
- {
- /**
- * Get automatic action description
- *
- * @access public
- * @return string
- */
- public function getDescription()
- {
- return t('RT - Assigner automatiquement un tag et une couleur lorsque une tâche est créée dans une colonne');
- }
- /**
- * Get the list of compatible events
- *
- * @access public
- * @return array
- */
- public function getCompatibleEvents()
- {
- return array(
- TaskModel::EVENT_MOVE_COLUMN,
- TaskModel::EVENT_CREATE_UPDATE,
- );
- }
- /**
- * Get the required parameter for the action (defined by the user)
- *
- * @access public
- * @return array
- */
- public function getActionRequiredParameters()
- {
- return array(
- 'column_id' => t('Column'),
- 'color_id' => t('Color'),
- );
- }
- /**
- * Get the required parameter for the event
- *
- * @access public
- * @return string[]
- */
- public function getEventRequiredParameters()
- {
- return array(
- 'task_id',
- 'task' => array(
- 'column_id',
- 'project_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)
- {
- $values = array(
- 'id' => $data['task_id'],
- 'color_id' => $this->getParam('color_id'),
- );
- // récupère le task_id
- $task_id=$data['task_id'];
- // récupère le titre de la colonne dans laquelle se trouve la tâche
- $column_title = $this->columnModel->getColumnTitleById($data['column_id']);
- // renvoie le tag_id du tag portant le même nom que la colonne sinon en créer un nouveau global_tag si nexiste pas (TagModel.php) (0 pour global project)
- $column_tag_id=$this->tagModel->findOrCreateTag(0, $column_title);
- // associe le tag correspondant à la colonne puis le tag correspondant au projet
- $this->taskTagModel->associateTag($task_id, $column_tag_id); // in TaskTagModel.php
- return $this->taskModificationModel->update($values, false);
- }
- /**
- * 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['task']['column_id'] == $this->getParam('column_id');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement