|
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 boolean $language_requirement_confirmed |
|
35
|
|
|
* @property \Jenssegers\Date\Date $created_at |
|
36
|
|
|
* @property \Jenssegers\Date\Date $updated_at |
|
37
|
|
|
* |
|
38
|
|
|
* @property \App\Models\Applicant $applicant |
|
39
|
|
|
* @property \App\Models\Applicant $applicant_snapshot |
|
40
|
|
|
* @property \App\Models\Lookup\ApplicationStatus $application_status |
|
41
|
|
|
* @property \App\Models\Lookup\CitizenshipDeclaration $citizenship_declaration |
|
42
|
|
|
* @property \App\Models\Lookup\VeteranStatus $veteran_status |
|
43
|
|
|
* @property \App\Models\Lookup\PreferredLanguage $preferred_language |
|
44
|
|
|
* @property \App\Models\JobPoster $job_poster |
|
45
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $job_application_answers |
|
46
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $skill_declarations |
|
47
|
|
|
* @property \App\Models\ApplicationReview $application_review |
|
48
|
|
|
*/ |
|
49
|
|
|
class JobApplication extends BaseModel { |
|
50
|
|
|
|
|
51
|
|
|
use Notifiable; |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
protected $dispatchesEvents = [ |
|
|
|
|
|
|
54
|
|
|
'retrieved' => ApplicationRetrieved::class, |
|
55
|
|
|
'saved' => ApplicationSaved::class, |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
protected $casts = [ |
|
|
|
|
|
|
59
|
|
|
'job_poster_id' => 'int', |
|
60
|
|
|
'application_status_id' => 'int', |
|
61
|
|
|
'citizenship_declaration_id' => 'int', |
|
62
|
|
|
'veteran_status_id' => 'int', |
|
63
|
|
|
'preferred_language_id' => 'int', |
|
64
|
|
|
'applicant_id' => 'int', |
|
65
|
|
|
'applicant_snapshot_id' => 'int', |
|
66
|
|
|
'submission_signature' => 'string', |
|
67
|
|
|
'submission_date' => 'string', |
|
68
|
|
|
'experience_saved' => 'boolean', |
|
69
|
|
|
'language_requirement_confirmed' => 'boolean' |
|
70
|
|
|
]; |
|
71
|
|
|
protected $fillable = [ |
|
|
|
|
|
|
72
|
|
|
'citizenship_declaration_id', |
|
73
|
|
|
'language_requirement_confirmed', |
|
74
|
|
|
'veteran_status_id', |
|
75
|
|
|
'preferred_language_id', |
|
76
|
|
|
'submission_signature', |
|
77
|
|
|
'submission_date', |
|
78
|
|
|
'experience_saved', |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* The accessors to append to the model's array/json form. |
|
83
|
|
|
* |
|
84
|
|
|
* @var array |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
|
|
protected $appends = ['meets_essential_criteria']; |
|
87
|
|
|
|
|
88
|
|
|
protected function createApplicantSnapshot($applicant_id) { |
|
|
|
|
|
|
89
|
|
|
$applicant = Applicant::where('id', $applicant_id)->firstOrFail(); |
|
90
|
|
|
|
|
91
|
|
|
$snapshot = $applicant->replicate(); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
} |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
1 |
|
public function applicant() { |
|
|
|
|
|
|
96
|
1 |
|
return $this->belongsTo(\App\Models\Applicant::class); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function applicant_snapshot() { |
|
|
|
|
|
|
100
|
|
|
return $this->belongsTo(\App\Models\Applicant::class, 'applicant_snapshot_id'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
12 |
|
public function application_status() { |
|
|
|
|
|
|
104
|
12 |
|
return $this->belongsTo(\App\Models\Lookup\ApplicationStatus::class); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function citizenship_declaration() { |
|
|
|
|
|
|
108
|
|
|
return $this->belongsTo(\App\Models\Lookup\CitizenshipDeclaration::class); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function veteran_status() { |
|
|
|
|
|
|
112
|
|
|
return $this->belongsTo(\App\Models\Lookup\VeteranStatus::class); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function preferred_language() { |
|
|
|
|
|
|
116
|
|
|
return $this->belongsTo(\App\Models\Lookup\PreferredLanguage::class); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
public function job_poster() { |
|
|
|
|
|
|
120
|
1 |
|
return $this->belongsTo(\App\Models\JobPoster::class); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function job_application_answers() { |
|
|
|
|
|
|
124
|
|
|
return $this->hasMany(\App\Models\JobApplicationAnswer::class); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
1 |
|
public function skill_declarations() { |
|
|
|
|
|
|
128
|
1 |
|
return $this->applicant->skill_declarations() |
|
129
|
1 |
|
->whereIn('skill_id', $this->job_poster->criteria->pluck('skill_id')); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function application_review() { |
|
|
|
|
|
|
133
|
|
|
return $this->hasOne(ApplicationReview::class); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Return either 'complete', 'incomplete' or 'error', depending on the |
|
138
|
|
|
* status of the requested section. |
|
139
|
|
|
* |
|
140
|
|
|
* @param string $section Should be one of: |
|
|
|
|
|
|
141
|
|
|
* 'basics' |
|
142
|
|
|
* 'experience' |
|
143
|
|
|
* 'essential_skills' |
|
144
|
|
|
* 'asset_skills' |
|
145
|
|
|
* 'preview' |
|
146
|
|
|
* |
|
147
|
|
|
* @return string $status 'complete', 'incomplete' or 'error' |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getSectionStatus(string $section) { |
|
|
|
|
|
|
150
|
|
|
//TODO: determine whether sections are complete or invalid |
|
151
|
|
|
$validator = new ApplicationValidator(); |
|
152
|
|
|
$status = 'incomplete'; |
|
153
|
|
|
switch($section) { |
|
|
|
|
|
|
154
|
|
|
case 'basics': |
|
155
|
|
|
if ($validator->basicsComplete($this)) { |
|
156
|
|
|
$status = 'complete'; |
|
157
|
|
|
} |
|
158
|
|
|
break; |
|
159
|
|
|
case 'experience': |
|
160
|
|
|
if ($validator->experienceComplete($this)) { |
|
161
|
|
|
$status = 'complete'; |
|
162
|
|
|
} |
|
163
|
|
|
break; |
|
164
|
|
|
case 'essential_skills': |
|
165
|
|
|
if ($validator->essentialSkillsComplete($this)) { |
|
166
|
|
|
$status = 'complete'; |
|
167
|
|
|
} |
|
168
|
|
|
break; |
|
169
|
|
|
case 'asset_skills': |
|
170
|
|
|
if ($validator->assetSkillsComplete($this)) { |
|
171
|
|
|
$status = 'complete'; |
|
172
|
|
|
} |
|
173
|
|
|
break; |
|
174
|
|
|
case 'preview': |
|
175
|
|
|
if ($validator->basicsComplete($this) && |
|
176
|
|
|
$validator->experienceComplete($this) && |
|
177
|
|
|
$validator->essentialSkillsComplete($this) && |
|
178
|
|
|
$validator->assetSkillsComplete($this)) { |
|
179
|
|
|
$status = 'complete'; |
|
180
|
|
|
} |
|
181
|
|
|
break; |
|
182
|
|
|
case 'confirm': |
|
183
|
|
|
if ($validator->affirmationComplete($this)) { |
|
184
|
|
|
$status = 'complete'; |
|
185
|
|
|
} |
|
186
|
|
|
break; |
|
187
|
|
|
default: |
|
188
|
|
|
$status = 'error'; |
|
189
|
|
|
break; |
|
190
|
|
|
} |
|
191
|
|
|
return $status; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Returns true if this application meets all the essential criteria. |
|
196
|
|
|
* That means it has attached an SkillDeclaration for each essential criterion, |
|
197
|
|
|
* with a level at least as high as the required level. |
|
198
|
|
|
* |
|
199
|
|
|
* @return boolean |
|
200
|
|
|
*/ |
|
201
|
1 |
|
public function meetsEssentialCriteria(): bool |
|
202
|
|
|
{ |
|
203
|
1 |
|
$essentialCriteria = $this->job_poster->criteria->filter( |
|
204
|
|
|
function ($value, $key) { |
|
|
|
|
|
|
205
|
1 |
|
return $value->criteria_type->name == 'essential'; |
|
206
|
1 |
|
} |
|
207
|
|
|
); |
|
208
|
1 |
|
foreach ($essentialCriteria as $criterion) { |
|
209
|
1 |
|
$skillDeclaration = $this->skill_declarations->where("skill_id", $criterion->skill_id)->first(); |
|
210
|
1 |
|
if ($skillDeclaration === null || |
|
211
|
1 |
|
$skillDeclaration->skill_level_id < $criterion->skill_level_id) { |
|
212
|
1 |
|
return false; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
1 |
|
return true; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Accessor for meetsEssentialCriteria function, which |
|
220
|
|
|
* allows this value to be automtacially appended to array/json representation. |
|
221
|
|
|
* |
|
222
|
|
|
* @return boolean |
|
223
|
|
|
*/ |
|
224
|
|
|
public function getMeetsEssentialCriteriaAttribute():bool |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->meetsEssentialCriteria(); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|