|
1
|
|
|
<?php namespace JobApis\JobsToMail\Notifications; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Bus\Queueable; |
|
4
|
|
|
use Illuminate\Notifications\Notification; |
|
5
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
6
|
|
|
use Illuminate\Queue\SerializesModels; |
|
7
|
|
|
use JobApis\JobsToMail\Models\Search; |
|
8
|
|
|
use JobApis\JobsToMail\Notifications\Messages\JobMailMessage; |
|
9
|
|
|
|
|
10
|
|
|
class JobsCollected extends Notification implements ShouldQueue |
|
11
|
|
|
{ |
|
12
|
|
|
use Queueable, SerializesModels; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var array of Job objects |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $jobs; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Search |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $search; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a new notification instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $jobs |
|
28
|
|
|
* @param Search $search |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
4 |
|
public function __construct(array $jobs, Search $search) |
|
33
|
|
|
{ |
|
34
|
4 |
|
$this->jobs = $jobs; |
|
35
|
4 |
|
$this->search = $search; |
|
36
|
4 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get the notification's delivery channels. |
|
40
|
|
|
* |
|
41
|
|
|
* @param mixed $notifiable |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function via($notifiable) |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
1 |
|
return ['mail', 'database']; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the array representation of the notification for saving to the database. |
|
51
|
|
|
* |
|
52
|
|
|
* @param mixed $notifiable |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function toArray($notifiable) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
return [ |
|
58
|
1 |
|
'search_id' => $this->search->id, |
|
59
|
1 |
|
'jobs' => $this->jobs, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the mail representation of the notification. |
|
65
|
|
|
* |
|
66
|
|
|
* @param mixed $notifiable |
|
67
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public function toMail($notifiable) |
|
70
|
|
|
{ |
|
71
|
|
|
// Instantiate the message |
|
72
|
1 |
|
$message = new JobMailMessage(); |
|
73
|
|
|
|
|
74
|
|
|
// Add user and search ID to view data |
|
75
|
1 |
|
$message->viewData['user_id'] = $notifiable->id; |
|
76
|
1 |
|
$message->viewData['search_id'] = $this->search->id; |
|
77
|
|
|
|
|
78
|
|
|
// Update the subject |
|
79
|
1 |
|
$message->subject(count($this->jobs).' new jobs found especially for you'); |
|
80
|
|
|
|
|
81
|
|
|
// Add a jobs-hub ad |
|
82
|
1 |
|
$message->advertisement('upgrade'); |
|
83
|
|
|
|
|
84
|
|
|
// Update the message text |
|
85
|
1 |
|
$message->greeting('Hello,') |
|
86
|
1 |
|
->line('We found the following jobs that we think |
|
87
|
|
|
you\'ll be interested in based on your search:') |
|
88
|
1 |
|
->line("\"{$this->search->keyword} in {$this->search->location}\""); |
|
89
|
|
|
|
|
90
|
|
|
// Add jobs |
|
91
|
1 |
|
foreach (array_slice($this->jobs, 0, 10) as $job) { |
|
92
|
1 |
|
$message->listing($job); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
// Add a link to download the collection |
|
96
|
1 |
|
$message->action( |
|
97
|
1 |
|
'View More', |
|
98
|
1 |
|
url('/notifications/' . $this->id) |
|
|
|
|
|
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
1 |
|
return $message; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.