|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Mail; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\JobApplication; |
|
6
|
|
|
use App\Traits\ApiMailable; |
|
7
|
|
|
use Illuminate\Bus\Queueable; |
|
8
|
|
|
use Illuminate\Mail\Mailable; |
|
9
|
|
|
use Illuminate\Queue\SerializesModels; |
|
10
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
11
|
|
|
use Illuminate\Support\Facades\Lang; |
|
12
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
|
13
|
|
|
|
|
14
|
|
|
class MicroReferenceMail extends Mailable implements ShouldQueue |
|
15
|
|
|
{ |
|
16
|
|
|
use Queueable, SerializesModels, ApiMailable; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The application for which we need to make a reference check. |
|
20
|
|
|
* |
|
21
|
|
|
* @var \App\Models\JobApplication |
|
22
|
|
|
*/ |
|
23
|
|
|
public $application; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* If true, this is for the applicant's Director reference. |
|
27
|
|
|
* If false, this is for the applicant's secondary reference. |
|
28
|
|
|
* |
|
29
|
|
|
* @var boolean |
|
30
|
|
|
*/ |
|
31
|
|
|
public $is_director; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
public function __construct(JobApplication $application, bool $is_director) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->application = $application; |
|
38
|
|
|
$this->is_director = $is_director; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Build the message. |
|
43
|
|
|
* |
|
44
|
|
|
* @return $this |
|
45
|
|
|
*/ |
|
46
|
|
|
public function build() |
|
47
|
|
|
{ |
|
48
|
|
|
$essential_criteria = $this->application->job_poster->criteria->where('criteria_type.name', 'essential'); |
|
49
|
|
|
$reference_email = $this->is_director |
|
50
|
|
|
? $this->application->director_email |
|
51
|
|
|
: $this->application->reference_email; |
|
52
|
|
|
$reference_name = $this->is_director |
|
53
|
|
|
? $this->application->director_name |
|
54
|
|
|
: $this->application->reference_name; |
|
55
|
|
|
$mail = $this->subject(Lang::get('manager/micro_reference_mail.subject')) |
|
56
|
|
|
->from(config('mail.from.address'), config('mail.from.name')) |
|
|
|
|
|
|
57
|
|
|
->markdown('emails.micro_reference', [ |
|
58
|
|
|
'reference_name' => $reference_name, |
|
59
|
|
|
'homepage_url' => route('response.index'), |
|
|
|
|
|
|
60
|
|
|
'homepage_url_fr' => LaravelLocalization::getLocalizedURL('fr', route('response.index')), |
|
61
|
|
|
'applicant_name' => $this->application->applicant->user->full_name, |
|
62
|
|
|
'is_director' => $this->is_director, |
|
63
|
|
|
'criteria' => $essential_criteria, |
|
64
|
|
|
]); |
|
65
|
|
|
if (isset($reference_email)) { |
|
66
|
|
|
$mail->to($reference_email, $reference_name ?? null); |
|
67
|
|
|
} |
|
68
|
|
|
return $mail; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|