1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coyote\Notifications\Job; |
4
|
|
|
|
5
|
|
|
use Coyote\Job; |
6
|
|
|
use Coyote\Services\Notification\DatabaseChannel; |
7
|
|
|
use Coyote\Services\Notification\NotificationInterface; |
8
|
|
|
use Coyote\Services\UrlBuilder; |
9
|
|
|
use Illuminate\Bus\Queueable; |
10
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
11
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
12
|
|
|
use Illuminate\Notifications\Notification; |
13
|
|
|
use Illuminate\Support\Facades\Storage; |
14
|
|
|
|
15
|
|
|
class ApplicationSentNotification extends Notification implements ShouldQueue, NotificationInterface |
16
|
|
|
{ |
17
|
|
|
use Queueable; |
18
|
|
|
|
19
|
|
|
const ID = \Coyote\Notification::JOB_APPLICATION; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Job\Application |
23
|
|
|
*/ |
24
|
|
|
private $application; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param Job\Application $application |
28
|
|
|
*/ |
29
|
|
|
public function __construct(Job\Application $application) |
30
|
|
|
{ |
31
|
|
|
$this->application = $application; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
public function via() |
38
|
|
|
{ |
39
|
|
|
return ['mail', DatabaseChannel::class]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param Job $job |
44
|
|
|
* @return MailMessage |
45
|
|
|
*/ |
46
|
|
|
public function toMail(Job $job) |
47
|
|
|
{ |
48
|
|
|
$message = (new MailMessage()) |
49
|
|
|
->subject(sprintf('[%s] %s', $this->application->name, $job->title)) |
50
|
|
|
->replyTo($this->application->email, $this->application->name) |
51
|
|
|
->view('emails.job.application', [ |
52
|
|
|
'application' => $this->application->toArray(), |
53
|
|
|
'job' => $job |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
if ($this->application->cv) { |
57
|
|
|
$data = Storage::disk('local')->get('cv/' . $this->application->cv); |
58
|
|
|
|
59
|
|
|
$message->attachData($data, $this->application->realFilename()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $message; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param Job $job |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
|
public function toDatabase($job) |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
'object_id' => $this->objectId(), |
74
|
|
|
'user_id' => $job->user_id, |
75
|
|
|
'type_id' => static::ID, |
76
|
|
|
'subject' => $this->application->job->title, |
77
|
|
|
'excerpt' => null, |
78
|
|
|
'url' => UrlBuilder::job($this->application->job), |
79
|
|
|
'id' => $this->id |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function objectId() |
87
|
|
|
{ |
88
|
|
|
return substr(md5(uniqid()), 16); // uniq ID for each notification. notification won't be grouped |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
public function sender() |
95
|
|
|
{ |
96
|
|
|
return [ |
97
|
|
|
'name' => $this->application->name, |
98
|
|
|
'user_id' => null |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
protected function redirectionUrl() |
106
|
|
|
{ |
107
|
|
|
return route('user.notifications.url', [$this->id]); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|