Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Kanboard\Plugin\RTAutomaticsActions\Action;
- use Kanboard\Model\TaskModel;
- use Kanboard\Action\Base;
- use Kanboard\Model\TagModel;
- use Kanboard\Model\TaskTagModel;
- /**
- * Rename Task Title
- *
- * @package action
- * @author
- */
- class TaskAssignTagColor extends Base
- {
- /**
- * Get automatic action description
- *
- * @access public
- * @return string
- */
- public function getDescription()
- {
- return t('Automatically assign tag and color when task created in specific column');
- }
- /**
- * 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'),
- );
- $project_id = '0'; // because global tags are in project_id = 0
- $tag = 'column_id'; // ?! the string value of column_id defined by user
- findOrCreateTag($project_id, $tag); // Return tag id and create a new tag if necessary, in TagModel.php
- // then, we have tag_id created and task_id, so lets assign the tag to the task
- associateTag($task_id, $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