1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<?php
namespace Kanboard\Job;
use Kanboard\Event\GenericEvent;
/**
* Class NotificationJob
*
* @package Kanboard\Job
* @author Frederic Guillot
*/
class NotificationJob extends BaseJob
{
/**
* Set job parameters
*
* @param GenericEvent $event
* @param string $eventName
* @param string $eventObjectName
* @return $this
*/
public function withParams(GenericEvent $event, $eventName, $eventObjectName)
{
$this->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->userNotificationModel->sendUserNotification($event['mention'], $eventName, $eventData);
} else {
$this->userNotificationModel->sendNotifications($eventName, $eventData);
$this->projectNotificationModel->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->taskFinderModel->getDetails($event['task_id']);
break;
default:
$values = $event;
}
return $values;
}
}
|