NotificationModel refactoring
This commit is contained in:
@@ -19,5 +19,26 @@ abstract class BaseEventBuilder extends Base
|
||||
* @access public
|
||||
* @return GenericEvent|null
|
||||
*/
|
||||
abstract public function build();
|
||||
abstract public function buildEvent();
|
||||
|
||||
/**
|
||||
* Get event title with author
|
||||
*
|
||||
* @access public
|
||||
* @param string $author
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
abstract public function buildTitleWithAuthor($author, $eventName, array $eventData);
|
||||
|
||||
/**
|
||||
* Get event title without author
|
||||
*
|
||||
* @access public
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
abstract public function buildTitleWithoutAuthor($eventName, array $eventData);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Kanboard\EventBuilder;
|
||||
|
||||
use Kanboard\Event\CommentEvent;
|
||||
use Kanboard\Model\CommentModel;
|
||||
|
||||
/**
|
||||
* Class CommentEventBuilder
|
||||
@@ -32,7 +33,7 @@ class CommentEventBuilder extends BaseEventBuilder
|
||||
* @access public
|
||||
* @return CommentEvent|null
|
||||
*/
|
||||
public function build()
|
||||
public function buildEvent()
|
||||
{
|
||||
$comment = $this->commentModel->getById($this->commentId);
|
||||
|
||||
@@ -45,4 +46,53 @@ class CommentEventBuilder extends BaseEventBuilder
|
||||
'task' => $this->taskFinderModel->getDetails($comment['task_id']),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title with author
|
||||
*
|
||||
* @access public
|
||||
* @param string $author
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithAuthor($author, $eventName, array $eventData)
|
||||
{
|
||||
switch ($eventName) {
|
||||
case CommentModel::EVENT_UPDATE:
|
||||
return e('%s updated a comment on the task #%d', $author, $eventData['task']['id']);
|
||||
case CommentModel::EVENT_CREATE:
|
||||
return e('%s commented on the task #%d', $author, $eventData['task']['id']);
|
||||
case CommentModel::EVENT_DELETE:
|
||||
return e('%s removed a comment on the task #%d', $author, $eventData['task']['id']);
|
||||
case CommentModel::EVENT_USER_MENTION:
|
||||
return e('%s mentioned you in a comment on the task #%d', $author, $eventData['task']['id']);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title without author
|
||||
*
|
||||
* @access public
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithoutAuthor($eventName, array $eventData)
|
||||
{
|
||||
switch ($eventName) {
|
||||
case CommentModel::EVENT_CREATE:
|
||||
return e('New comment on task #%d', $eventData['comment']['task_id']);
|
||||
case CommentModel::EVENT_UPDATE:
|
||||
return e('Comment updated on task #%d', $eventData['comment']['task_id']);
|
||||
case CommentModel::EVENT_DELETE:
|
||||
return e('Comment removed on task #%d', $eventData['comment']['task_id']);
|
||||
case CommentModel::EVENT_USER_MENTION:
|
||||
return e('You were mentioned in a comment on the task #%d', $eventData['task']['id']);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
app/EventBuilder/EventIteratorBuilder.php
Normal file
48
app/EventBuilder/EventIteratorBuilder.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\EventBuilder;
|
||||
|
||||
use Iterator;
|
||||
|
||||
/**
|
||||
* Class EventIteratorBuilder
|
||||
*
|
||||
* @package Kanboard\EventBuilder
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class EventIteratorBuilder implements Iterator {
|
||||
private $position = 0;
|
||||
private $builders = array();
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function withBuilder(BaseEventBuilder $builder)
|
||||
{
|
||||
$this->builders[] = $builder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function rewind() {
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BaseEventBuilder
|
||||
*/
|
||||
public function current() {
|
||||
return $this->builders[$this->position];
|
||||
}
|
||||
|
||||
public function key() {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function next() {
|
||||
++$this->position;
|
||||
}
|
||||
|
||||
public function valid() {
|
||||
return isset($this->builders[$this->position]);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class ProjectFileEventBuilder extends BaseEventBuilder
|
||||
* @access public
|
||||
* @return GenericEvent|null
|
||||
*/
|
||||
public function build()
|
||||
public function buildEvent()
|
||||
{
|
||||
$file = $this->projectFileModel->getById($this->fileId);
|
||||
|
||||
@@ -47,4 +47,31 @@ class ProjectFileEventBuilder extends BaseEventBuilder
|
||||
'project' => $this->projectModel->getById($file['project_id']),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title with author
|
||||
*
|
||||
* @access public
|
||||
* @param string $author
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithAuthor($author, $eventName, array $eventData)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title without author
|
||||
*
|
||||
* @access public
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithoutAuthor($eventName, array $eventData)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Kanboard\EventBuilder;
|
||||
|
||||
use Kanboard\Event\SubtaskEvent;
|
||||
use Kanboard\Event\GenericEvent;
|
||||
use Kanboard\Model\SubtaskModel;
|
||||
|
||||
/**
|
||||
* Class SubtaskEventBuilder
|
||||
@@ -59,7 +60,7 @@ class SubtaskEventBuilder extends BaseEventBuilder
|
||||
* @access public
|
||||
* @return GenericEvent|null
|
||||
*/
|
||||
public function build()
|
||||
public function buildEvent()
|
||||
{
|
||||
$eventData = array();
|
||||
$eventData['subtask'] = $this->subtaskModel->getById($this->subtaskId, true);
|
||||
@@ -76,4 +77,49 @@ class SubtaskEventBuilder extends BaseEventBuilder
|
||||
$eventData['task'] = $this->taskFinderModel->getDetails($eventData['subtask']['task_id']);
|
||||
return new SubtaskEvent($eventData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title with author
|
||||
*
|
||||
* @access public
|
||||
* @param string $author
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithAuthor($author, $eventName, array $eventData)
|
||||
{
|
||||
switch ($eventName) {
|
||||
case SubtaskModel::EVENT_UPDATE:
|
||||
return e('%s updated a subtask for the task #%d', $author, $eventData['task']['id']);
|
||||
case SubtaskModel::EVENT_CREATE:
|
||||
return e('%s created a subtask for the task #%d', $author, $eventData['task']['id']);
|
||||
case SubtaskModel::EVENT_DELETE:
|
||||
return e('%s removed a subtask for the task #%d', $author, $eventData['task']['id']);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title without author
|
||||
*
|
||||
* @access public
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithoutAuthor($eventName, array $eventData)
|
||||
{
|
||||
switch ($eventName) {
|
||||
case SubtaskModel::EVENT_CREATE:
|
||||
return e('New subtask on task #%d', $eventData['subtask']['task_id']);
|
||||
case SubtaskModel::EVENT_UPDATE:
|
||||
return e('Subtask updated on task #%d', $eventData['subtask']['task_id']);
|
||||
case SubtaskModel::EVENT_DELETE:
|
||||
return e('Subtask removed on task #%d', $eventData['subtask']['task_id']);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Kanboard\EventBuilder;
|
||||
|
||||
use Kanboard\Event\TaskEvent;
|
||||
use Kanboard\Model\TaskModel;
|
||||
|
||||
/**
|
||||
* Class TaskEventBuilder
|
||||
@@ -98,7 +99,7 @@ class TaskEventBuilder extends BaseEventBuilder
|
||||
* @access public
|
||||
* @return TaskEvent|null
|
||||
*/
|
||||
public function build()
|
||||
public function buildEvent()
|
||||
{
|
||||
$eventData = array();
|
||||
$eventData['task_id'] = $this->taskId;
|
||||
@@ -120,4 +121,103 @@ class TaskEventBuilder extends BaseEventBuilder
|
||||
|
||||
return new TaskEvent(array_merge($eventData, $this->values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title with author
|
||||
*
|
||||
* @access public
|
||||
* @param string $author
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithAuthor($author, $eventName, array $eventData)
|
||||
{
|
||||
switch ($eventName) {
|
||||
case TaskModel::EVENT_ASSIGNEE_CHANGE:
|
||||
$assignee = $eventData['task']['assignee_name'] ?: $eventData['task']['assignee_username'];
|
||||
|
||||
if (! empty($assignee)) {
|
||||
return e('%s changed the assignee of the task #%d to %s', $author, $eventData['task']['id'], $assignee);
|
||||
}
|
||||
|
||||
return e('%s removed the assignee of the task %s', $author, e('#%d', $eventData['task']['id']));
|
||||
case TaskModel::EVENT_UPDATE:
|
||||
return e('%s updated the task #%d', $author, $eventData['task']['id']);
|
||||
case TaskModel::EVENT_CREATE:
|
||||
return e('%s created the task #%d', $author, $eventData['task']['id']);
|
||||
case TaskModel::EVENT_CLOSE:
|
||||
return e('%s closed the task #%d', $author, $eventData['task']['id']);
|
||||
case TaskModel::EVENT_OPEN:
|
||||
return e('%s opened the task #%d', $author, $eventData['task']['id']);
|
||||
case TaskModel::EVENT_MOVE_COLUMN:
|
||||
return e(
|
||||
'%s moved the task #%d to the column "%s"',
|
||||
$author,
|
||||
$eventData['task']['id'],
|
||||
$eventData['task']['column_title']
|
||||
);
|
||||
case TaskModel::EVENT_MOVE_POSITION:
|
||||
return e(
|
||||
'%s moved the task #%d to the position %d in the column "%s"',
|
||||
$author,
|
||||
$eventData['task']['id'],
|
||||
$eventData['task']['position'],
|
||||
$eventData['task']['column_title']
|
||||
);
|
||||
case TaskModel::EVENT_MOVE_SWIMLANE:
|
||||
if ($eventData['task']['swimlane_id'] == 0) {
|
||||
return e('%s moved the task #%d to the first swimlane', $author, $eventData['task']['id']);
|
||||
}
|
||||
|
||||
return e(
|
||||
'%s moved the task #%d to the swimlane "%s"',
|
||||
$author,
|
||||
$eventData['task']['id'],
|
||||
$eventData['task']['swimlane_name']
|
||||
);
|
||||
|
||||
case TaskModel::EVENT_USER_MENTION:
|
||||
return e('%s mentioned you in the task #%d', $author, $eventData['task']['id']);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title without author
|
||||
*
|
||||
* @access public
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithoutAuthor($eventName, array $eventData)
|
||||
{
|
||||
switch ($eventName) {
|
||||
case TaskModel::EVENT_CREATE:
|
||||
return e('New task #%d: %s', $eventData['task']['id'], $eventData['task']['title']);
|
||||
case TaskModel::EVENT_UPDATE:
|
||||
return e('Task updated #%d', $eventData['task']['id']);
|
||||
case TaskModel::EVENT_CLOSE:
|
||||
return e('Task #%d closed', $eventData['task']['id']);
|
||||
case TaskModel::EVENT_OPEN:
|
||||
return e('Task #%d opened', $eventData['task']['id']);
|
||||
case TaskModel::EVENT_MOVE_COLUMN:
|
||||
return e('Column changed for task #%d', $eventData['task']['id']);
|
||||
case TaskModel::EVENT_MOVE_POSITION:
|
||||
return e('New position for task #%d', $eventData['task']['id']);
|
||||
case TaskModel::EVENT_MOVE_SWIMLANE:
|
||||
return e('Swimlane changed for task #%d', $eventData['task']['id']);
|
||||
case TaskModel::EVENT_ASSIGNEE_CHANGE:
|
||||
return e('Assignee changed on task #%d', $eventData['task']['id']);
|
||||
case TaskModel::EVENT_OVERDUE:
|
||||
$nb = count($eventData['tasks']);
|
||||
return $nb > 1 ? e('%d overdue tasks', $nb) : e('Task #%d is overdue', $eventData['tasks'][0]['id']);
|
||||
case TaskModel::EVENT_USER_MENTION:
|
||||
return e('You were mentioned in the task #%d', $eventData['task']['id']);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Kanboard\EventBuilder;
|
||||
|
||||
use Kanboard\Event\TaskFileEvent;
|
||||
use Kanboard\Event\GenericEvent;
|
||||
use Kanboard\Model\TaskFileModel;
|
||||
|
||||
/**
|
||||
* Class TaskFileEventBuilder
|
||||
@@ -33,7 +34,7 @@ class TaskFileEventBuilder extends BaseEventBuilder
|
||||
* @access public
|
||||
* @return GenericEvent|null
|
||||
*/
|
||||
public function build()
|
||||
public function buildEvent()
|
||||
{
|
||||
$file = $this->taskFileModel->getById($this->fileId);
|
||||
|
||||
@@ -47,4 +48,39 @@ class TaskFileEventBuilder extends BaseEventBuilder
|
||||
'task' => $this->taskFinderModel->getDetails($file['task_id']),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title with author
|
||||
*
|
||||
* @access public
|
||||
* @param string $author
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithAuthor($author, $eventName, array $eventData)
|
||||
{
|
||||
if ($eventName === TaskFileModel::EVENT_CREATE) {
|
||||
return e('%s attached a file to the task #%d', $author, $eventData['task']['id']);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event title without author
|
||||
*
|
||||
* @access public
|
||||
* @param string $eventName
|
||||
* @param array $eventData
|
||||
* @return string
|
||||
*/
|
||||
public function buildTitleWithoutAuthor($eventName, array $eventData)
|
||||
{
|
||||
if ($eventName === TaskFileModel::EVENT_CREATE) {
|
||||
return e('New attachment on task #%d: %s', $eventData['file']['task_id'], $eventData['file']['name']);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class TaskLinkEventBuilder extends BaseEventBuilder
|
||||
* @access public
|
||||
* @return TaskLinkEvent|null
|
||||
*/
|
||||
public function build()
|
||||
public function buildEvent()
|
||||
{
|
||||
$taskLink = $this->taskLinkModel->getById($this->taskLinkId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user