Advertisement
Guest User

Untitled

a guest
Jan 26th, 2024
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.69 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Kanboard\Plugin\RTAutomaticsActions\Action;
  4.  
  5. use Kanboard\Model\TaskModel;
  6. use Kanboard\Action\Base;
  7. use Kanboard\Model\TagModel;
  8. use Kanboard\Model\TaskTagModel;
  9.  
  10.  
  11. /**
  12.  * Rename Task Title
  13.  *
  14.  * @package action
  15.  * @author  
  16.  */
  17. class TaskAssignTagColor extends Base
  18. {
  19.     /**
  20.      * Get automatic action description
  21.      *
  22.      * @access public
  23.      * @return string
  24.      */
  25.     public function getDescription()
  26.     {
  27.         return t('Automatically assign tag and color when task created in specific column');
  28.     }
  29.  
  30.     /**
  31.      * Get the list of compatible events
  32.      *
  33.      * @access public
  34.      * @return array
  35.      */
  36.     public function getCompatibleEvents()
  37.     {
  38.         return array(
  39.             TaskModel::EVENT_MOVE_COLUMN,
  40.             TaskModel::EVENT_CREATE_UPDATE,
  41.         );
  42.     }
  43.  
  44.     /**
  45.      * Get the required parameter for the action (defined by the user)
  46.      *
  47.      * @access public
  48.      * @return array
  49.      */
  50.     public function getActionRequiredParameters()
  51.     {
  52.         return array(
  53.             'column_id' => t('Column'),
  54.             'color_id' => t('Color'),
  55.         );
  56.     }
  57.  
  58.     /**
  59.      * Get the required parameter for the event
  60.      *
  61.      * @access public
  62.      * @return string[]
  63.      */
  64.     public function getEventRequiredParameters()
  65.     {
  66.         return array(
  67.             'task_id',
  68.             'task' => array(
  69.                 'column_id',
  70.                 'project_id',
  71.             ),
  72.         );
  73.     }
  74.  
  75.     /**
  76.      * Execute the action
  77.      *
  78.      * @access public
  79.      * @param  array   $data   Event data dictionary
  80.      * @return bool            True if the action was executed or false when not executed
  81.      */
  82.     public function doAction(array $data)
  83.     {
  84.         $values = array(
  85.             'id' => $data['task_id'],
  86.             'color_id' => $this->getParam('color_id'),
  87.         );
  88.  
  89.         $project_id = '0'; // because global tags are in project_id = 0
  90.         $tag = 'column_id'; // ?! the string value of column_id defined by user
  91.         findOrCreateTag($project_id, $tag); // Return tag id and create a new tag if necessary, in TagModel.php
  92.  
  93.         // then, we have tag_id created and task_id, so lets assign the tag to the task
  94.         associateTag($task_id, $tag_id); // in TaskTagModel.php
  95.  
  96.         return $this->taskModificationModel->update($values, false);
  97.     }
  98.  
  99.  
  100.     /**
  101.      * Check if the event data meet the action condition
  102.      *
  103.      * @access public
  104.      * @param  array   $data   Event data dictionary
  105.      * @return bool
  106.      */
  107.     public function hasRequiredCondition(array $data)
  108.     {
  109.         return $data['task']['column_id'] == $this->getParam('column_id');
  110.     }
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement