Add more events and notifications for tasks
This commit is contained in:
@@ -139,4 +139,15 @@ abstract class Base implements Listener
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return class information
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return get_called_class();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TaskAssignCategoryColor extends Base
|
|||||||
$this->task->update(array(
|
$this->task->update(array(
|
||||||
'id' => $data['task_id'],
|
'id' => $data['task_id'],
|
||||||
'category_id' => $this->getParam('category_id'),
|
'category_id' => $this->getParam('category_id'),
|
||||||
));
|
), false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TaskAssignColorCategory extends Base
|
|||||||
$this->task->update(array(
|
$this->task->update(array(
|
||||||
'id' => $data['task_id'],
|
'id' => $data['task_id'],
|
||||||
'color_id' => $this->getParam('color_id'),
|
'color_id' => $this->getParam('color_id'),
|
||||||
));
|
), false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TaskAssignColorUser extends Base
|
|||||||
$this->task->update(array(
|
$this->task->update(array(
|
||||||
'id' => $data['task_id'],
|
'id' => $data['task_id'],
|
||||||
'color_id' => $this->getParam('color_id'),
|
'color_id' => $this->getParam('color_id'),
|
||||||
));
|
), false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class TaskAssignCurrentUser extends Base
|
|||||||
$this->task->update(array(
|
$this->task->update(array(
|
||||||
'id' => $data['task_id'],
|
'id' => $data['task_id'],
|
||||||
'owner_id' => $this->acl->getUserId(),
|
'owner_id' => $this->acl->getUserId(),
|
||||||
));
|
), false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TaskAssignSpecificUser extends Base
|
|||||||
$this->task->update(array(
|
$this->task->update(array(
|
||||||
'id' => $data['task_id'],
|
'id' => $data['task_id'],
|
||||||
'owner_id' => $this->getParam('user_id'),
|
'owner_id' => $this->getParam('user_id'),
|
||||||
));
|
), false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,17 @@ abstract class BaseNotificationListener implements Listener
|
|||||||
$this->notification = $notification;
|
$this->notification = $notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return class information
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return get_called_class();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the action
|
* Execute the action
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -32,6 +32,17 @@ class CommentHistoryListener implements Listener
|
|||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return class information
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return get_called_class();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the action
|
* Execute the action
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,6 +34,17 @@ class ProjectModificationDate implements Listener
|
|||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return class information
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return get_called_class();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the action
|
* Execute the action
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -32,6 +32,17 @@ class SubtaskHistoryListener implements Listener
|
|||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return class information
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return get_called_class();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the action
|
* Execute the action
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -32,6 +32,17 @@ class TaskHistoryListener implements Listener
|
|||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return class information
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return get_called_class();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the action
|
* Execute the action
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -42,6 +42,17 @@ class WebhookListener implements Listener
|
|||||||
$this->webhook = $webhook;
|
$this->webhook = $webhook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return class information
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return get_called_class();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the action
|
* Execute the action
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -496,4 +496,10 @@ return array(
|
|||||||
'Activity' => 'Activité',
|
'Activity' => 'Activité',
|
||||||
'Default values are "%s"' => 'Les valeurs par défaut sont « %s »',
|
'Default values are "%s"' => 'Les valeurs par défaut sont « %s »',
|
||||||
'Default columns for new projects (Comma-separated)' => 'Colonnes par défaut pour les nouveaux projets (séparé par des virgules)',
|
'Default columns for new projects (Comma-separated)' => 'Colonnes par défaut pour les nouveaux projets (séparé par des virgules)',
|
||||||
|
'Task assignee change' => 'Modification de la personne assignée sur une tâche',
|
||||||
|
'%s change the assignee of the task #%d' => '%s a changé la personne assignée sur la tâche #%d',
|
||||||
|
'%s change the assignee of the task <a href="?controller=task&action=show&task_id=%d">#%d</a>' => '%s a changé la personne assignée sur la tâche <a href="?controller=task&action=show&task_id=%d">n°%d</a>',
|
||||||
|
'[%s][Column Change] %s (#%d)' => '[%s][Changement de colonne] %s (#%d)',
|
||||||
|
'[%s][Position Change] %s (#%d)' => '[%s][Changement de position] %s (#%d)',
|
||||||
|
'[%s][Assignee Change] %s (#%d)' => '[%s][Changement d\'assigné] %s (#%d)',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ class Action extends Base
|
|||||||
Task::EVENT_OPEN => t('Open a closed task'),
|
Task::EVENT_OPEN => t('Open a closed task'),
|
||||||
Task::EVENT_CLOSE => t('Closing a task'),
|
Task::EVENT_CLOSE => t('Closing a task'),
|
||||||
Task::EVENT_CREATE_UPDATE => t('Task creation or modification'),
|
Task::EVENT_CREATE_UPDATE => t('Task creation or modification'),
|
||||||
|
Task::EVENT_ASSIGNEE_CHANGE => t('Task assignee change'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ class Notification extends Base
|
|||||||
$this->event->attach(Task::EVENT_UPDATE, new TaskNotificationListener($this, 'notification_task_update'));
|
$this->event->attach(Task::EVENT_UPDATE, new TaskNotificationListener($this, 'notification_task_update'));
|
||||||
$this->event->attach(Task::EVENT_CLOSE, new TaskNotificationListener($this, 'notification_task_close'));
|
$this->event->attach(Task::EVENT_CLOSE, new TaskNotificationListener($this, 'notification_task_close'));
|
||||||
$this->event->attach(Task::EVENT_OPEN, new TaskNotificationListener($this, 'notification_task_open'));
|
$this->event->attach(Task::EVENT_OPEN, new TaskNotificationListener($this, 'notification_task_open'));
|
||||||
|
$this->event->attach(Task::EVENT_MOVE_COLUMN, new TaskNotificationListener($this, 'notification_task_move_column'));
|
||||||
|
$this->event->attach(Task::EVENT_MOVE_POSITION, new TaskNotificationListener($this, 'notification_task_move_position'));
|
||||||
|
$this->event->attach(Task::EVENT_ASSIGNEE_CHANGE, new TaskNotificationListener($this, 'notification_task_assignee_change'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +100,6 @@ class Notification extends Base
|
|||||||
$message = Swift_Message::newInstance()
|
$message = Swift_Message::newInstance()
|
||||||
->setSubject($this->getMailSubject($template, $data))
|
->setSubject($this->getMailSubject($template, $data))
|
||||||
->setFrom(array(MAIL_FROM => 'Kanboard'))
|
->setFrom(array(MAIL_FROM => 'Kanboard'))
|
||||||
//->setTo(array($user['email'] => $user['name']))
|
|
||||||
->setBody($this->getMailContent($template, $data), 'text/html');
|
->setBody($this->getMailContent($template, $data), 'text/html');
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
@@ -143,6 +145,15 @@ class Notification extends Base
|
|||||||
case 'notification_task_open':
|
case 'notification_task_open':
|
||||||
$subject = e('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
|
$subject = e('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
|
||||||
break;
|
break;
|
||||||
|
case 'notification_task_move_column':
|
||||||
|
$subject = e('[%s][Column Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
|
||||||
|
break;
|
||||||
|
case 'notification_task_move_position':
|
||||||
|
$subject = e('[%s][Position Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
|
||||||
|
break;
|
||||||
|
case 'notification_task_assignee_change':
|
||||||
|
$subject = e('[%s][Assignee Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']);
|
||||||
|
break;
|
||||||
case 'notification_task_due':
|
case 'notification_task_due':
|
||||||
$subject = e('[%s][Due tasks]', $data['project']);
|
$subject = e('[%s][Due tasks]', $data['project']);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -35,13 +35,14 @@ class Task extends Base
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const EVENT_MOVE_COLUMN = 'task.move.column';
|
const EVENT_MOVE_COLUMN = 'task.move.column';
|
||||||
const EVENT_MOVE_POSITION = 'task.move.position';
|
const EVENT_MOVE_POSITION = 'task.move.position';
|
||||||
const EVENT_UPDATE = 'task.update';
|
const EVENT_UPDATE = 'task.update';
|
||||||
const EVENT_CREATE = 'task.create';
|
const EVENT_CREATE = 'task.create';
|
||||||
const EVENT_CLOSE = 'task.close';
|
const EVENT_CLOSE = 'task.close';
|
||||||
const EVENT_OPEN = 'task.open';
|
const EVENT_OPEN = 'task.open';
|
||||||
const EVENT_CREATE_UPDATE = 'task.create_update';
|
const EVENT_CREATE_UPDATE = 'task.create_update';
|
||||||
|
const EVENT_ASSIGNEE_CHANGE = 'task.assignee_change';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get available colors
|
* Get available colors
|
||||||
@@ -437,9 +438,10 @@ class Task extends Base
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param array $values Form values
|
* @param array $values Form values
|
||||||
|
* @param boolean $trigger_Events Trigger events
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function update(array $values)
|
public function update(array $values, $trigger_events = true)
|
||||||
{
|
{
|
||||||
// Fetch original task
|
// Fetch original task
|
||||||
$original_task = $this->getById($values['id']);
|
$original_task = $this->getById($values['id']);
|
||||||
@@ -454,7 +456,9 @@ class Task extends Base
|
|||||||
$updated_task['date_modification'] = time();
|
$updated_task['date_modification'] = time();
|
||||||
unset($updated_task['id']);
|
unset($updated_task['id']);
|
||||||
|
|
||||||
if ($this->db->table(self::TABLE)->eq('id', $values['id'])->update($updated_task)) {
|
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($updated_task);
|
||||||
|
|
||||||
|
if ($result && $trigger_events) {
|
||||||
$this->triggerUpdateEvents($original_task, $updated_task);
|
$this->triggerUpdateEvents($original_task, $updated_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +476,10 @@ class Task extends Base
|
|||||||
{
|
{
|
||||||
$events = array();
|
$events = array();
|
||||||
|
|
||||||
if (isset($updated_task['column_id']) && $original_task['column_id'] != $updated_task['column_id']) {
|
if (isset($updated_task['owner_id']) && $original_task['owner_id'] != $updated_task['owner_id']) {
|
||||||
|
$events[] = self::EVENT_ASSIGNEE_CHANGE;
|
||||||
|
}
|
||||||
|
else if (isset($updated_task['column_id']) && $original_task['column_id'] != $updated_task['column_id']) {
|
||||||
$events[] = self::EVENT_MOVE_COLUMN;
|
$events[] = self::EVENT_MOVE_COLUMN;
|
||||||
}
|
}
|
||||||
else if (isset($updated_task['position']) && $original_task['position'] != $updated_task['position']) {
|
else if (isset($updated_task['position']) && $original_task['position'] != $updated_task['position']) {
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ class TaskHistory extends BaseHistory
|
|||||||
public function getTitle(array $event)
|
public function getTitle(array $event)
|
||||||
{
|
{
|
||||||
$titles = array(
|
$titles = array(
|
||||||
|
Task::EVENT_ASSIGNEE_CHANGE => t('%s change the assignee of the task #%d', $event['author'], $event['task_id']),
|
||||||
Task::EVENT_UPDATE => t('%s updated the task #%d', $event['author'], $event['task_id']),
|
Task::EVENT_UPDATE => t('%s updated the task #%d', $event['author'], $event['task_id']),
|
||||||
Task::EVENT_CREATE => t('%s created the task #%d', $event['author'], $event['task_id']),
|
Task::EVENT_CREATE => t('%s created the task #%d', $event['author'], $event['task_id']),
|
||||||
Task::EVENT_CLOSE => t('%s closed the task #%d', $event['author'], $event['task_id']),
|
Task::EVENT_CLOSE => t('%s closed the task #%d', $event['author'], $event['task_id']),
|
||||||
@@ -141,6 +142,7 @@ class TaskHistory extends BaseHistory
|
|||||||
public function attachEvents()
|
public function attachEvents()
|
||||||
{
|
{
|
||||||
$events = array(
|
$events = array(
|
||||||
|
Task::EVENT_ASSIGNEE_CHANGE,
|
||||||
Task::EVENT_UPDATE,
|
Task::EVENT_UPDATE,
|
||||||
Task::EVENT_CREATE,
|
Task::EVENT_CREATE,
|
||||||
Task::EVENT_CLOSE,
|
Task::EVENT_CLOSE,
|
||||||
|
|||||||
6
app/Templates/event_task_assignee_change.php
Normal file
6
app/Templates/event_task_assignee_change.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<p class="activity-title">
|
||||||
|
<?= e('%s change the assignee of the task <a href="?controller=task&action=show&task_id=%d">#%d</a>', Helper\escape($author), $task_id, $task_id) ?>
|
||||||
|
</p>
|
||||||
|
<p class="activity-description">
|
||||||
|
<em><?= Helper\escape($task_title) ?></em>
|
||||||
|
</p>
|
||||||
20
app/Templates/notification_task_assignee_change.php
Normal file
20
app/Templates/notification_task_assignee_change.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<h2><?= Helper\escape($task['title']) ?> (#<?= $task['id'] ?>)</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<strong>
|
||||||
|
<?php if ($task['assignee_username']): ?>
|
||||||
|
<?= t('Assigned to %s', $task['assignee_name'] ?: $task['assignee_username']) ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<?= t('There is nobody assigned') ?>
|
||||||
|
<?php endif ?>
|
||||||
|
</strong>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<?php if (! empty($task['description'])): ?>
|
||||||
|
<h2><?= t('Description') ?></h2>
|
||||||
|
<?= Helper\parse($task['description']) ?: t('There is no description.') ?>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
|
<?= Helper\template('notification_footer', array('task' => $task)) ?>
|
||||||
11
app/Templates/notification_task_move_column.php
Normal file
11
app/Templates/notification_task_move_column.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<h2><?= Helper\escape($task['title']) ?> (#<?= $task['id'] ?>)</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<?= t('Column on the board:') ?>
|
||||||
|
<strong><?= Helper\escape($task['column_title']) ?></strong>
|
||||||
|
</li>
|
||||||
|
<li><?= t('Task position:').' '.Helper\escape($task['position']) ?></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<?= Helper\template('notification_footer', array('task' => $task)) ?>
|
||||||
11
app/Templates/notification_task_move_position.php
Normal file
11
app/Templates/notification_task_move_position.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<h2><?= Helper\escape($task['title']) ?> (#<?= $task['id'] ?>)</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<?= t('Column on the board:') ?>
|
||||||
|
<strong><?= Helper\escape($task['column_title']) ?></strong>
|
||||||
|
</li>
|
||||||
|
<li><?= t('Task position:').' '.Helper\escape($task['position']) ?></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<?= Helper\template('notification_footer', array('task' => $task)) ?>
|
||||||
@@ -25,6 +25,7 @@ List of available events
|
|||||||
- Open a closed task
|
- Open a closed task
|
||||||
- Closing a task
|
- Closing a task
|
||||||
- Task creation or modification
|
- Task creation or modification
|
||||||
|
- Task assignee change
|
||||||
|
|
||||||
List of available actions
|
List of available actions
|
||||||
-------------------------
|
-------------------------
|
||||||
@@ -79,7 +80,7 @@ Let's say we have two projects "Ideas" and "Development", once the idea is valid
|
|||||||
|
|
||||||
### I want to assign automatically a color to the user Bob
|
### I want to assign automatically a color to the user Bob
|
||||||
|
|
||||||
- Choose the event: **Task creation**
|
- Choose the event: **Task assignee change**
|
||||||
- Choose the action: **Assign a color to a specific user**
|
- Choose the action: **Assign a color to a specific user**
|
||||||
- Define the action parameters: **Color = Green** and **Assignee = Bob**
|
- Define the action parameters: **Color = Green** and **Assignee = Bob**
|
||||||
|
|
||||||
|
|||||||
@@ -648,5 +648,9 @@ class TaskTest extends Base
|
|||||||
// We change the column and the position of our task
|
// We change the column and the position of our task
|
||||||
$this->assertTrue($t->movePosition(1, 1, 1, 1));
|
$this->assertTrue($t->movePosition(1, 1, 1, 1));
|
||||||
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
|
||||||
|
|
||||||
|
// We change the assignee
|
||||||
|
$this->assertTrue($t->update(array('owner_id' => 1, 'id' => 1)));
|
||||||
|
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user