|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Created by Reliese Model. |
|
5
|
|
|
* Date: Thu, 12 Jul 2018 22:39:27 +0000. |
|
6
|
|
|
*/ |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
namespace App\Models; |
|
9
|
|
|
use App\Models\Lookup\VeteranStatus; |
|
10
|
|
|
use App\Models\Lookup\PreferredLanguage; |
|
11
|
|
|
use App\Models\Lookup\CitizenshipDeclaration; |
|
12
|
|
|
use App\Models\Applicant; |
|
13
|
|
|
use App\Models\SkillDeclaration; |
|
14
|
|
|
use App\Models\ApplicationReview; |
|
15
|
|
|
use Illuminate\Notifications\Notifiable; |
|
16
|
|
|
use App\Events\ApplicationSaved; |
|
17
|
|
|
use App\Events\ApplicationRetrieved; |
|
18
|
|
|
use App\Services\Validation\ApplicationValidator; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class JobApplication |
|
22
|
|
|
* |
|
23
|
|
|
* @property int $id |
|
24
|
|
|
* @property int $job_poster_id |
|
25
|
|
|
* @property int $application_status_id |
|
26
|
|
|
* @property int $citizenship_declaration_id |
|
27
|
|
|
* @property int $veteran_status_id |
|
28
|
|
|
* @property int $preferred_language_id |
|
29
|
|
|
* @property int $applicant_id |
|
30
|
|
|
* @property int $applicant_snapshot_id |
|
31
|
|
|
* @property string $submission_signature |
|
32
|
|
|
* @property string $submission_date |
|
33
|
|
|
* @property boolean $experience_saved |
|
34
|
|
|
* @property \Jenssegers\Date\Date $created_at |
|
35
|
|
|
* @property \Jenssegers\Date\Date $updated_at |
|
36
|
|
|
* |
|
37
|
|
|
* @property \App\Models\Applicant $applicant |
|
38
|
|
|
* @property \App\Models\Applicant $applicant_snapshot |
|
39
|
|
|
* @property \App\Models\Lookup\ApplicationStatus $application_status |
|
40
|
|
|
* @property \App\Models\Lookup\CitizenshipDeclaration $citizenship_declaration |
|
41
|
|
|
* @property \App\Models\Lookup\VeteranStatus $veteran_status |
|
42
|
|
|
* @property \App\Models\Lookup\PreferredLanguage $preferred_language |
|
43
|
|
|
* @property \App\Models\JobPoster $job_poster |
|
44
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_application_answers |
|
45
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $skill_declarations |
|
46
|
|
|
* @property \App\Models\ApplicationReview $application_review |
|
47
|
|
|
*/ |
|
|
|
|
|
|
48
|
|
|
class JobApplication extends BaseModel { |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
use Notifiable; |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
protected $dispatchesEvents = [ |
|
53
|
|
|
'retrieved' => ApplicationRetrieved::class, |
|
54
|
|
|
'saved' => ApplicationSaved::class, |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
protected $casts = [ |
|
58
|
|
|
'job_poster_id' => 'int', |
|
59
|
|
|
'application_status_id' => 'int', |
|
60
|
|
|
'citizenship_declaration_id' => 'int', |
|
61
|
|
|
'veteran_status_id' => 'int', |
|
62
|
|
|
'preferred_language_id' => 'int', |
|
63
|
|
|
'applicant_id' => 'int', |
|
64
|
|
|
'applicant_snapshot_id' => 'int', |
|
65
|
|
|
'submission_signature' => 'string', |
|
66
|
|
|
'submission_date' => 'string', |
|
67
|
|
|
'experience_saved' => 'boolean', |
|
68
|
|
|
]; |
|
69
|
|
|
protected $fillable = [ |
|
70
|
|
|
'citizenship_declaration_id', |
|
71
|
|
|
'veteran_status_id', |
|
72
|
|
|
'preferred_language_id', |
|
73
|
|
|
'submission_signature', |
|
74
|
|
|
'submission_date', |
|
75
|
|
|
'experience_saved', |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
protected function createApplicantSnapshot($applicant_id) { |
|
|
|
|
|
|
79
|
|
|
$applicant = Applicant::where('id', $applicant_id)->firstOrFail(); |
|
80
|
|
|
|
|
81
|
|
|
$snapshot = $applicant->replicate(); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function applicant() { |
|
|
|
|
|
|
86
|
|
|
return $this->belongsTo(\App\Models\Applicant::class); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function applicant_snapshot() { |
|
|
|
|
|
|
90
|
|
|
return $this->belongsTo(\App\Models\Applicant::class, 'applicant_snapshot_id'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
14 |
|
public function application_status() { |
|
|
|
|
|
|
94
|
14 |
|
return $this->belongsTo(\App\Models\Lookup\ApplicationStatus::class); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function citizenship_declaration() { |
|
|
|
|
|
|
98
|
|
|
return $this->belongsTo(\App\Models\Lookup\CitizenshipDeclaration::class); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function veteran_status() { |
|
|
|
|
|
|
102
|
|
|
return $this->belongsTo(\App\Models\Lookup\VeteranStatus::class); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function preferred_language() { |
|
|
|
|
|
|
106
|
|
|
return $this->belongsTo(\App\Models\Lookup\PreferredLanguage::class); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function job_poster() { |
|
|
|
|
|
|
110
|
|
|
return $this->belongsTo(\App\Models\JobPoster::class); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function job_application_answers() { |
|
|
|
|
|
|
114
|
|
|
return $this->hasMany(\App\Models\JobApplicationAnswer::class); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function skill_declarations() { |
|
|
|
|
|
|
118
|
|
|
return $this->applicant->skill_declarations() |
|
119
|
|
|
->whereIn('skill_id', $this->job_poster->criteria->pluck('skill_id')); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function application_review() { |
|
|
|
|
|
|
123
|
|
|
return $this->hasOne(ApplicationReview::class); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Return either 'complete', 'incomplete' or 'error', depending on the |
|
128
|
|
|
* status of the requested section. |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $section Should be one of: |
|
|
|
|
|
|
131
|
|
|
* 'basics' |
|
|
|
|
|
|
132
|
|
|
* 'experience' |
|
|
|
|
|
|
133
|
|
|
* 'essential_skills' |
|
|
|
|
|
|
134
|
|
|
* 'asset_skills' |
|
|
|
|
|
|
135
|
|
|
* 'preview' |
|
|
|
|
|
|
136
|
|
|
* |
|
137
|
|
|
* @return string $status 'complete', 'incomplete' or 'error' |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getSectionStatus(string $section) { |
|
140
|
|
|
//TODO: determine whether sections are complete or invalid |
|
141
|
|
|
$validator = new ApplicationValidator(); |
|
142
|
|
|
$status = 'incomplete'; |
|
143
|
|
|
switch($section) { |
|
144
|
|
|
case 'basics': |
|
145
|
|
|
if ($validator->basicsComplete($this)) { |
|
146
|
|
|
$status = 'complete'; |
|
147
|
|
|
} |
|
148
|
|
|
break; |
|
149
|
|
|
case 'experience': |
|
150
|
|
|
if ($validator->experienceComplete($this)) { |
|
151
|
|
|
$status = 'complete'; |
|
152
|
|
|
} |
|
153
|
|
|
break; |
|
154
|
|
|
case 'essential_skills': |
|
155
|
|
|
if ($validator->essentialSkillsComplete($this)) { |
|
156
|
|
|
$status = 'complete'; |
|
157
|
|
|
} |
|
158
|
|
|
break; |
|
159
|
|
|
case 'asset_skills': |
|
160
|
|
|
if ($validator->assetSkillsComplete($this)) { |
|
161
|
|
|
$status = 'complete'; |
|
162
|
|
|
} |
|
163
|
|
|
break; |
|
164
|
|
|
case 'preview': |
|
165
|
|
|
if ($validator->basicsComplete($this) && |
|
166
|
|
|
$validator->experienceComplete($this) && |
|
|
|
|
|
|
167
|
|
|
$validator->essentialSkillsComplete($this) && |
|
|
|
|
|
|
168
|
|
|
$validator->assetSkillsComplete($this)) { |
|
|
|
|
|
|
169
|
|
|
$status = 'complete'; |
|
170
|
|
|
} |
|
171
|
|
|
break; |
|
172
|
|
|
case 'confirm': |
|
173
|
|
|
if ($validator->affirmationComplete($this)) { |
|
174
|
|
|
$status = 'complete'; |
|
175
|
|
|
} |
|
176
|
|
|
break; |
|
177
|
|
|
default: |
|
178
|
|
|
$status = 'error'; |
|
179
|
|
|
break; |
|
180
|
|
|
} |
|
181
|
|
|
return $status; |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|