diff options
author | Christopher Geelen <christopher.geelen@vinotion.nl> | 2016-07-27 13:58:23 +0200 |
---|---|---|
committer | Christopher Geelen <christopher.geelen@vinotion.nl> | 2016-07-27 13:58:23 +0200 |
commit | 24745182724ca69092554eb5946e31584420f68a (patch) | |
tree | 386cdf7a8d7bf7ad2d80d938333bafbaf0fedcbc /app/EventBuilder | |
parent | 160c0b885eb4f1a1a1baa2b6b9fc6d99fdb80d0c (diff) | |
parent | 9649f7ba82ba7fe6a470abfe9f65e214cc68fa34 (diff) |
Merge remote-tracking branch 'upstream/master'
Conflicts:
app/Job/NotificationJob.php
Diffstat (limited to 'app/EventBuilder')
-rw-r--r-- | app/EventBuilder/BaseEventBuilder.php | 44 | ||||
-rw-r--r-- | app/EventBuilder/CommentEventBuilder.php | 98 | ||||
-rw-r--r-- | app/EventBuilder/EventIteratorBuilder.php | 52 | ||||
-rw-r--r-- | app/EventBuilder/ProjectFileEventBuilder.php | 77 | ||||
-rw-r--r-- | app/EventBuilder/SubtaskEventBuilder.php | 125 | ||||
-rw-r--r-- | app/EventBuilder/TaskEventBuilder.php | 223 | ||||
-rw-r--r-- | app/EventBuilder/TaskFileEventBuilder.php | 86 | ||||
-rw-r--r-- | app/EventBuilder/TaskLinkEventBuilder.php | 89 |
8 files changed, 794 insertions, 0 deletions
diff --git a/app/EventBuilder/BaseEventBuilder.php b/app/EventBuilder/BaseEventBuilder.php new file mode 100644 index 00000000..5aa777a0 --- /dev/null +++ b/app/EventBuilder/BaseEventBuilder.php @@ -0,0 +1,44 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Kanboard\Core\Base; +use Kanboard\Event\GenericEvent; + +/** + * Class BaseEventBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +abstract class BaseEventBuilder extends Base +{ + /** + * Build event data + * + * @access public + * @return GenericEvent|null + */ + 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); +} diff --git a/app/EventBuilder/CommentEventBuilder.php b/app/EventBuilder/CommentEventBuilder.php new file mode 100644 index 00000000..ba5842a4 --- /dev/null +++ b/app/EventBuilder/CommentEventBuilder.php @@ -0,0 +1,98 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Kanboard\Event\CommentEvent; +use Kanboard\Model\CommentModel; + +/** + * Class CommentEventBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +class CommentEventBuilder extends BaseEventBuilder +{ + protected $commentId = 0; + + /** + * Set commentId + * + * @param int $commentId + * @return $this + */ + public function withCommentId($commentId) + { + $this->commentId = $commentId; + return $this; + } + + /** + * Build event data + * + * @access public + * @return CommentEvent|null + */ + public function buildEvent() + { + $comment = $this->commentModel->getById($this->commentId); + + if (empty($comment)) { + return null; + } + + return new CommentEvent(array( + 'comment' => $comment, + '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 ''; + } + } +} diff --git a/app/EventBuilder/EventIteratorBuilder.php b/app/EventBuilder/EventIteratorBuilder.php new file mode 100644 index 00000000..ba821753 --- /dev/null +++ b/app/EventBuilder/EventIteratorBuilder.php @@ -0,0 +1,52 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Iterator; + +/** + * Class EventIteratorBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +class EventIteratorBuilder implements Iterator { + private $position = 0; + private $builders = array(); + + /** + * Set builder + * + * @access public + * @param BaseEventBuilder $builder + * @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]); + } +} diff --git a/app/EventBuilder/ProjectFileEventBuilder.php b/app/EventBuilder/ProjectFileEventBuilder.php new file mode 100644 index 00000000..6698f78a --- /dev/null +++ b/app/EventBuilder/ProjectFileEventBuilder.php @@ -0,0 +1,77 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Kanboard\Event\ProjectFileEvent; +use Kanboard\Event\GenericEvent; + +/** + * Class ProjectFileEventBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +class ProjectFileEventBuilder extends BaseEventBuilder +{ + protected $fileId = 0; + + /** + * Set fileId + * + * @param int $fileId + * @return $this + */ + public function withFileId($fileId) + { + $this->fileId = $fileId; + return $this; + } + + /** + * Build event data + * + * @access public + * @return GenericEvent|null + */ + public function buildEvent() + { + $file = $this->projectFileModel->getById($this->fileId); + + if (empty($file)) { + $this->logger->debug(__METHOD__.': File not found'); + return null; + } + + return new ProjectFileEvent(array( + 'file' => $file, + '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 ''; + } +} diff --git a/app/EventBuilder/SubtaskEventBuilder.php b/app/EventBuilder/SubtaskEventBuilder.php new file mode 100644 index 00000000..5f7e831d --- /dev/null +++ b/app/EventBuilder/SubtaskEventBuilder.php @@ -0,0 +1,125 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Kanboard\Event\SubtaskEvent; +use Kanboard\Event\GenericEvent; +use Kanboard\Model\SubtaskModel; + +/** + * Class SubtaskEventBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +class SubtaskEventBuilder extends BaseEventBuilder +{ + /** + * SubtaskId + * + * @access protected + * @var int + */ + protected $subtaskId = 0; + + /** + * Changed values + * + * @access protected + * @var array + */ + protected $values = array(); + + /** + * Set SubtaskId + * + * @param int $subtaskId + * @return $this + */ + public function withSubtaskId($subtaskId) + { + $this->subtaskId = $subtaskId; + return $this; + } + + /** + * Set values + * + * @param array $values + * @return $this + */ + public function withValues(array $values) + { + $this->values = $values; + return $this; + } + + /** + * Build event data + * + * @access public + * @return GenericEvent|null + */ + public function buildEvent() + { + $eventData = array(); + $eventData['subtask'] = $this->subtaskModel->getById($this->subtaskId, true); + + if (empty($eventData['subtask'])) { + $this->logger->debug(__METHOD__.': Subtask not found'); + return null; + } + + if (! empty($this->values)) { + $eventData['changes'] = array_diff_assoc($this->values, $eventData['subtask']); + } + + $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 ''; + } + } +} diff --git a/app/EventBuilder/TaskEventBuilder.php b/app/EventBuilder/TaskEventBuilder.php new file mode 100644 index 00000000..aa897632 --- /dev/null +++ b/app/EventBuilder/TaskEventBuilder.php @@ -0,0 +1,223 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Kanboard\Event\TaskEvent; +use Kanboard\Model\TaskModel; + +/** + * Class TaskEventBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +class TaskEventBuilder extends BaseEventBuilder +{ + /** + * TaskId + * + * @access protected + * @var int + */ + protected $taskId = 0; + + /** + * Task + * + * @access protected + * @var array + */ + protected $task = array(); + + /** + * Extra values + * + * @access protected + * @var array + */ + protected $values = array(); + + /** + * Changed values + * + * @access protected + * @var array + */ + protected $changes = array(); + + /** + * Set TaskId + * + * @param int $taskId + * @return $this + */ + public function withTaskId($taskId) + { + $this->taskId = $taskId; + return $this; + } + + /** + * Set task + * + * @param array $task + * @return $this + */ + public function withTask(array $task) + { + $this->task = $task; + return $this; + } + + /** + * Set values + * + * @param array $values + * @return $this + */ + public function withValues(array $values) + { + $this->values = $values; + return $this; + } + + /** + * Set changes + * + * @param array $changes + * @return $this + */ + public function withChanges(array $changes) + { + $this->changes = $changes; + return $this; + } + + /** + * Build event data + * + * @access public + * @return TaskEvent|null + */ + public function buildEvent() + { + $eventData = array(); + $eventData['task_id'] = $this->taskId; + $eventData['task'] = $this->taskFinderModel->getDetails($this->taskId); + + if (empty($eventData['task'])) { + $this->logger->debug(__METHOD__.': Task not found'); + return null; + } + + if (! empty($this->changes)) { + if (empty($this->task)) { + $this->task = $eventData['task']; + } + + $eventData['changes'] = array_diff_assoc($this->changes, $this->task); + unset($eventData['changes']['date_modification']); + } + + 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 ''; + } + } +} diff --git a/app/EventBuilder/TaskFileEventBuilder.php b/app/EventBuilder/TaskFileEventBuilder.php new file mode 100644 index 00000000..8c985cc0 --- /dev/null +++ b/app/EventBuilder/TaskFileEventBuilder.php @@ -0,0 +1,86 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Kanboard\Event\TaskFileEvent; +use Kanboard\Event\GenericEvent; +use Kanboard\Model\TaskFileModel; + +/** + * Class TaskFileEventBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +class TaskFileEventBuilder extends BaseEventBuilder +{ + protected $fileId = 0; + + /** + * Set fileId + * + * @param int $fileId + * @return $this + */ + public function withFileId($fileId) + { + $this->fileId = $fileId; + return $this; + } + + /** + * Build event data + * + * @access public + * @return GenericEvent|null + */ + public function buildEvent() + { + $file = $this->taskFileModel->getById($this->fileId); + + if (empty($file)) { + $this->logger->debug(__METHOD__.': File not found'); + return null; + } + + return new TaskFileEvent(array( + 'file' => $file, + '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 ''; + } +} diff --git a/app/EventBuilder/TaskLinkEventBuilder.php b/app/EventBuilder/TaskLinkEventBuilder.php new file mode 100644 index 00000000..f1a3fba2 --- /dev/null +++ b/app/EventBuilder/TaskLinkEventBuilder.php @@ -0,0 +1,89 @@ +<?php + +namespace Kanboard\EventBuilder; + +use Kanboard\Event\TaskLinkEvent; +use Kanboard\Model\TaskLinkModel; + +/** + * Class TaskLinkEventBuilder + * + * @package Kanboard\EventBuilder + * @author Frederic Guillot + */ +class TaskLinkEventBuilder extends BaseEventBuilder +{ + protected $taskLinkId = 0; + + /** + * Set taskLinkId + * + * @param int $taskLinkId + * @return $this + */ + public function withTaskLinkId($taskLinkId) + { + $this->taskLinkId = $taskLinkId; + return $this; + } + + /** + * Build event data + * + * @access public + * @return TaskLinkEvent|null + */ + public function buildEvent() + { + $taskLink = $this->taskLinkModel->getById($this->taskLinkId); + + if (empty($taskLink)) { + $this->logger->debug(__METHOD__.': TaskLink not found'); + return null; + } + + return new TaskLinkEvent(array( + 'task_link' => $taskLink, + 'task' => $this->taskFinderModel->getDetails($taskLink['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 === TaskLinkModel::EVENT_CREATE_UPDATE) { + return e('%s set a new internal link for the task #%d', $author, $eventData['task']['id']); + } elseif ($eventName === TaskLinkModel::EVENT_DELETE) { + return e('%s removed an internal link for 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 === TaskLinkModel::EVENT_CREATE_UPDATE) { + return e('A new internal link for the task #%d have been defined', $eventData['task']['id']); + } elseif ($eventName === TaskLinkModel::EVENT_DELETE) { + return e('Internal link removed for the task #%d', $eventData['task']['id']); + } + + return ''; + } +} |