Advertisement
Guest User

Untitled

a guest
Jan 27th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Kanboard\Plugin\RTAutomaticsActions\Action;
  4.  
  5. use Kanboard\Action\Base;
  6. use Kanboard\Model\TaskModel;
  7. use Kanboard\Model\TagModel;
  8. use Kanboard\Model\TaskTagModel;
  9.  
  10.  
  11. class TaskAssignTagColor extends Base
  12. {
  13. /**
  14. * Get automatic action description
  15. *
  16. * @access public
  17. * @return string
  18. */
  19. public function getDescription()
  20. {
  21. return t('RT - Assigner automatiquement un tag et une couleur lorsque une tâche est créée dans une colonne');
  22. }
  23.  
  24. /**
  25. * Get the list of compatible events
  26. *
  27. * @access public
  28. * @return array
  29. */
  30. public function getCompatibleEvents()
  31. {
  32. return array(
  33. TaskModel::EVENT_MOVE_COLUMN,
  34. TaskModel::EVENT_CREATE_UPDATE,
  35. );
  36. }
  37.  
  38. /**
  39. * Get the required parameter for the action (defined by the user)
  40. *
  41. * @access public
  42. * @return array
  43. */
  44. public function getActionRequiredParameters()
  45. {
  46. return array(
  47. 'column_id' => t('Column'),
  48. 'color_id' => t('Color'),
  49. );
  50. }
  51.  
  52. /**
  53. * Get the required parameter for the event
  54. *
  55. * @access public
  56. * @return string[]
  57. */
  58. public function getEventRequiredParameters()
  59. {
  60. return array(
  61. 'task_id',
  62. 'task' => array(
  63. 'column_id',
  64. 'project_id',
  65. ),
  66. );
  67. }
  68.  
  69. /**
  70. * Execute the action
  71. *
  72. * @access public
  73. * @param array $data Event data dictionary
  74. * @return bool True if the action was executed or false when not executed
  75. */
  76. public function doAction(array $data)
  77. {
  78. $values = array(
  79. 'id' => $data['task_id'],
  80. 'color_id' => $this->getParam('color_id'),
  81. );
  82. // récupère le task_id
  83. $task_id=$data['task_id'];
  84.  
  85. // récupère le titre de la colonne dans laquelle se trouve la tâche
  86. $column_title = $this->columnModel->getColumnTitleById($data['column_id']);
  87.  
  88. // 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)
  89. $column_tag_id=$this->tagModel->findOrCreateTag(0, $column_title);
  90. // associe le tag correspondant à la colonne puis le tag correspondant au projet
  91. $this->taskTagModel->associateTag($task_id, $column_tag_id); // in TaskTagModel.php
  92.  
  93. return $this->taskModificationModel->update($values, false);
  94. }
  95.  
  96. /**
  97. * Check if the event data meet the action condition
  98. *
  99. * @access public
  100. * @param array $data Event data dictionary
  101. * @return bool
  102. */
  103. public function hasRequiredCondition(array $data)
  104. {
  105. return $data['task']['column_id'] == $this->getParam('column_id');
  106. }
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement