1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Mail; |
4
|
|
|
|
5
|
|
|
use App\Models\JobPoster; |
6
|
|
|
use App\Models\Lookup\CitizenshipDeclaration; |
7
|
|
|
use App\Models\Lookup\VeteranStatus; |
8
|
|
|
use App\Models\User; |
9
|
|
|
use Illuminate\Bus\Queueable; |
10
|
|
|
use Illuminate\Mail\Mailable; |
11
|
|
|
use Illuminate\Queue\SerializesModels; |
12
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
13
|
|
|
use Illuminate\Support\Facades\App; |
14
|
|
|
use Illuminate\Support\Facades\Config; |
15
|
|
|
use Illuminate\Support\Facades\Lang; |
16
|
|
|
use Illuminate\Support\Facades\Log; |
17
|
|
|
use Jenssegers\Date\Date; |
18
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
19
|
|
|
|
20
|
|
|
class ScreenCandidatesPrompt extends Mailable implements ShouldQueue |
21
|
|
|
{ |
22
|
|
|
use Queueable, SerializesModels; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The Job Poster instance. |
26
|
|
|
* |
27
|
|
|
* @var JobPoster |
28
|
|
|
*/ |
29
|
|
|
public $job; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Create a new message instance. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function __construct(JobPoster $job) |
37
|
|
|
{ |
38
|
|
|
$this->job = $job; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Build the message. |
43
|
|
|
* |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
|
|
public function build() |
47
|
|
|
{ |
48
|
|
|
// Get emails of all Hr Advisors who have claimed job. |
49
|
|
|
$hr_advisors_emails = []; |
50
|
|
|
$hr_advisors = $this->job->hr_advisors; |
51
|
|
|
|
52
|
|
|
foreach ($hr_advisors as $advisor) { |
53
|
|
|
$email = User::where('id', $advisor->user_id)->first()->email; |
54
|
|
|
array_push($hr_advisors_emails, $email); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Get date 2 weeks after job poster closes. |
58
|
|
|
$date_in_two_weeks = humanizeLastDay($this->job->close_date_time->addWeeks(2)); |
59
|
|
|
$date_in_two_weeks_fr = humanizeLastDay($this->job->close_date_time->addWeeks(2), 'fr'); |
60
|
|
|
|
61
|
|
|
// Number of applicants. |
62
|
|
|
$num_of_applicants = $this->job->job_applications->count(); |
63
|
|
|
|
64
|
|
|
// Number of non-citizens. |
65
|
|
|
$canadian_citizen = CitizenshipDeclaration::where('name', 'citizen')->first()->id; |
66
|
|
|
$num_of_noncitizens = $this->job->job_applications |
67
|
|
|
->where('citizenship_declaration_id', '!=', $canadian_citizen) |
68
|
|
|
->count(); |
69
|
|
|
|
70
|
|
|
// Number of veterans. |
71
|
|
|
$non_veteran = VeteranStatus::where('name', 'none')->first()->id; |
72
|
|
|
$num_of_veterans = $this->job->job_applications |
73
|
|
|
->where('veteran_status_id', '!=', $non_veteran) |
74
|
|
|
->count(); |
75
|
|
|
|
76
|
|
|
$position = $this->job->getTranslations('title'); |
77
|
|
|
$classification = $this->job->getClassificationMessageAttribute(); |
78
|
|
|
$subject = Lang::get('common/notifications/screen_candidates.subject', [ 'position' => $position['en'], 'classification' => $classification ]) . ' / ' . Lang::get('common/notifications/screen_candidates.subject', [ 'position' => $position['fr'], 'classification' => $classification ], 'fr'); |
79
|
|
|
|
80
|
|
|
return $this->subject($subject) |
81
|
|
|
->cc($hr_advisors_emails) |
82
|
|
|
->cc(config('mail.admin_address')) |
|
|
|
|
83
|
|
|
->markdown('emails.job_posters.screen_candidates_plain', [ |
84
|
|
|
'drop_off_date' => [ |
85
|
|
|
'en' => $date_in_two_weeks, |
86
|
|
|
'fr' => $date_in_two_weeks_fr, |
87
|
|
|
], |
88
|
|
|
'manager_portal_link' => [ |
89
|
|
|
'en' => route('manager.home'), |
|
|
|
|
90
|
|
|
'fr' => LaravelLocalization::getLocalizedURL('fr', route('manager.home')), |
91
|
|
|
], |
92
|
|
|
'num_of_applicants' => $num_of_applicants, |
93
|
|
|
'num_of_noncitizens' => $num_of_noncitizens, |
94
|
|
|
'num_of_veterans' => $num_of_veterans, |
95
|
|
|
'position' => $position, |
96
|
|
|
'position_link' => [ |
97
|
|
|
'en' => route('jobs.summary', $this->job->id), |
98
|
|
|
'fr' => LaravelLocalization::getLocalizedURL('fr', route('jobs.summary', $this->job->id)), |
99
|
|
|
], |
100
|
|
|
'talent_cloud_email' => config('mail.admin_address'), |
101
|
|
|
]); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|