Repository navigation
Expand file tree
/
Copy pathErrorExecutionNotification.php
More file actions
120 lines (104 loc) · 3.23 KB
/
Copy pathErrorExecutionNotification.php
File metadata and controls
120 lines (104 loc) · 3.23 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace ProcessMaker\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Arr;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
class ErrorExecutionNotification extends Notification
{
use Queueable;
private $tokenInterface;
private $message;
private $errorHandling;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(TokenInterface $tokenInterface, $message = '', $errorHandling = [])
{
$this->tokenInterface = $tokenInterface;
$this->message = $message;
$this->errorHandling = $errorHandling;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
$via = [];
if (Arr::get($this->errorHandling, 'inapp_notification') === true) {
$via[] = 'broadcast';
$via[] = NotificationChannel::class;
}
if (Arr::get($this->errorHandling, 'email_notification') === true) {
$via[] = 'mail';
}
return $via;
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$data = $this->toArray($notifiable);
$title = $data['message'];
return (new MailMessage)
->error()
->subject($data['name'])
->greeting($data['name'])
->salutation('')
->line($data['message'])
->action(__('View Request'), url($data['url']))
->line($this->message);
}
/**
* Get the broadcast representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\BroadcastMessage
*/
public function toBroadcast($notifiable)
{
return new BroadcastMessage($this->toArray($notifiable));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return $this->toArray($notifiable);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
$processRequest = $this->tokenInterface->processRequest;
return [
'type' => 'ERROR_EXECUTION',
'message' => __('Execution Error') . ': ' . $this->tokenInterface->process->name . ' #' . $processRequest->id . ' - ' . $this->tokenInterface->element_name,
'name' => $processRequest->name,
'processName' => $processRequest->name,
'request_id' => $processRequest->id,
'user_id' => $notifiable->id,
'dateTime' => $processRequest->updated_at->toIso8601String(),
'uid' => $processRequest->id,
'url' => '/requests/' . $processRequest->id,
];
}
}