From b9f2d5650d464983a80f84f3ed0845028a355c92 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 24 May 2016 20:30:31 -0400 Subject: Added NotificationJob --- app/Job/NotificationJob.php | 85 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 app/Job/NotificationJob.php (limited to 'app/Job') diff --git a/app/Job/NotificationJob.php b/app/Job/NotificationJob.php new file mode 100644 index 00000000..d5fce222 --- /dev/null +++ b/app/Job/NotificationJob.php @@ -0,0 +1,85 @@ +jobParams = array($event->getAll(), $eventName, $eventObjectName); + return $this; + } + + /** + * Execute job + * + * @param array $event + * @param string $eventName + * @param string $eventObjectName + */ + public function execute(array $event, $eventName, $eventObjectName) + { + $eventData = $this->getEventData($event, $eventObjectName); + + if (! empty($eventData)) { + if (! empty($event['mention'])) { + $this->userNotification->sendUserNotification($event['mention'], $eventName, $eventData); + } else { + $this->userNotification->sendNotifications($eventName, $eventData); + $this->projectNotification->sendNotifications($eventData['task']['project_id'], $eventName, $eventData); + } + } + } + + /** + * Get event data + * + * @param array $event + * @param string $eventObjectName + * @return array + */ + public function getEventData(array $event, $eventObjectName) + { + $values = array(); + + if (! empty($event['changes'])) { + $values['changes'] = $event['changes']; + } + + switch ($eventObjectName) { + case 'Kanboard\Event\TaskEvent': + $values['task'] = $this->taskFinder->getDetails($event['task_id']); + break; + case 'Kanboard\Event\SubtaskEvent': + $values['subtask'] = $this->subtask->getById($event['id'], true); + $values['task'] = $this->taskFinder->getDetails($values['subtask']['task_id']); + break; + case 'Kanboard\Event\FileEvent': + $values['file'] = $event; + $values['task'] = $this->taskFinder->getDetails($values['file']['task_id']); + break; + case 'Kanboard\Event\CommentEvent': + $values['comment'] = $this->comment->getById($event['id']); + $values['task'] = $this->taskFinder->getDetails($values['comment']['task_id']); + break; + } + + return $values; + } +} -- cgit v1.2.3