Passed
Push — feature/screen-candidates-emai... ( 7a1461 )
by Yonathan
04:14
created

ScreenCandidatesPrompt::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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
17
class ScreenCandidatesPrompt extends Mailable implements ShouldQueue
18
{
19
    use Queueable, SerializesModels;
20
21
    /**
22
     * The Job Poster instance.
23
     *
24
     * @var JobPoster
25
     */
26
    public $job;
27
28
    /**
29
     * Create a new message instance.
30
     *
31
     * @return void
32
     */
33
    public function __construct(JobPoster $job)
34
    {
35
        $this->job = $job;
36
    }
37
38
    /**
39
     * Build the message.
40
     *
41
     * @return $this
42
     */
43
    public function build()
44
    {
45
        // Get emails of all Hr Advisors who have claimed job.
46
        $hr_advisors_emails = [];
47
        $hr_advisors = $this->job->hr_advisors;
48
49
        foreach ($hr_advisors as $advisor) {
50
            $email = User::where('id', $advisor->user_id)->first()->email;
51
            array_push($hr_advisors_emails, $email);
52
        }
53
54
        // Get date 2 weeks after job poster closes.
55
        $dateFormat = Config::get('app.date_format');
56
        $locale = App::getLocale();
57
        $timestamp_in_two_weeks = strtotime('+2 weeks', $this->job->close_date_time->timestamp);
58
        $date_in_two_weeks = date($dateFormat[$locale], $timestamp_in_two_weeks);
59
60
        // Number of applicants.
61
        $num_of_applicants = $this->job->job_applications->count();
62
63
        // Number of non-citizens.
64
        $canadian_citizen = CitizenshipDeclaration::where('name', 'citizen')->first()->id;
65
        $num_of_noncitizens = $this->job->job_applications
66
                                ->where('citizenship_declaration_id', '!=', $canadian_citizen)
67
                                ->count();
68
69
        // Number of veterans.
70
        $non_veteran = VeteranStatus::where('name', 'none')->first()->id;
71
        $num_of_veterans = $this->job->job_applications
72
                            ->where('veteran_status_id', '!=', $non_veteran)
73
                            ->count();
74
75
        $position = $this->job->getTranslations('title');
76
        $classification = $this->job->getClassificationMessageAttribute();
77
        $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');
78
79
        return $this->subject($subject)
80
                    ->cc($hr_advisors_emails)
81
                    ->markdown('emails.job_posters.screen_candidates_plain', [
82
                        'drop_off_date' => $date_in_two_weeks,
83
                        'manager_portal_link' => [
84
                            'en' => Lang::get('common/notifications/screen_candidates.manager_portal_link'),
85
                            'fr' => Lang::get('common/notifications/screen_candidates.manager_portal_link', [], 'fr'),
86
                        ],
87
                        'num_of_applicants' => $num_of_applicants,
88
                        'num_of_noncitizens' => $num_of_noncitizens,
89
                        'num_of_veterans' => $num_of_veterans,
90
                        'position' => $position,
91
                        'position_link' => [
92
                            'en' => Lang::get('common/notifications/screen_candidates.position_link', ['id' => $this->job->id]),
93
                            'fr' => Lang::get('common/notifications/screen_candidates.position_link', ['id' => $this->job->id], 'fr'),
94
                        ],
95
                        'talent_cloud_email' => config('mail.admin_address'),
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
                        'talent_cloud_email' => /** @scrutinizer ignore-call */ config('mail.admin_address'),
Loading history...
96
                    ]);
97
    }
98
}
99