You don’t need a new event, since there is already TaskModel::EVENT_CREATE_UPDATE
but you would need a new action, one where the hasRequiredCondition is looking for the catergory
public function hasRequiredCondition(array $data)
{
return $data['task']['category_id'] == $this->getParam('category_id');
}
and then the doAction sets the new assignee.
edit:
This is the cloest action available, if the task category changes, then color changes
this would be very simple to convert into an action that does exactly what you want, in fact, here I’ll do it for you.
<?php
namespace Kanboard\Action;
use Kanboard\Model\TaskModel;
/**
* Assign a user to a specific category
*
* @package Kanboard\Action
* @author Craig Crosby
*/
class TaskAssigneeByCategory extends Base
{
/**
* Get automatic action description
*
* @access public
* @return string
*/
public function getDescription()
{
return t('Assign automatically a tasks assignee based on a category');
}
/**
* Get the list of compatible events
*
* @access public
* @return array
*/
public function getCompatibleEvents()
{
return array(
TaskModel::EVENT_CREATE_UPDATE,
);
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
return array(
'user_id' => t('Assignee'),
'category_id' => t('Category'),
);
}
/**
* Get the required parameter for the event
*
* @access public
* @return string[]
*/
public function getEventRequiredParameters()
{
return array(
'task_id',
'task' => array(
'project_id',
'category_id',
),
);
}
/**
* Execute the action (change the task color)
*
* @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'],
'owner_id' => $this->getParam('user_id'),
);
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']['category_id'] == $this->getParam('category_id');
}
}
now, how you add this action is up to you, if via plugin, you will need to change the namespace.