1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Lang; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use App\Models\Lookup\ApplicationStatus; |
8
|
|
|
use App\Models\Lookup\VeteranStatus; |
9
|
|
|
use App\Models\Lookup\PreferredLanguage; |
10
|
|
|
use App\Models\Lookup\CitizenshipDeclaration; |
11
|
|
|
use App\Models\Applicant; |
12
|
|
|
use App\Models\JobPoster; |
13
|
|
|
use App\Models\JobApplication; |
14
|
|
|
use App\Models\JobApplicationAnswer; |
15
|
|
|
use App\Models\SkillDeclaration; |
16
|
|
|
use App\Models\Skill; |
17
|
|
|
use App\Models\Lookup\SkillStatus; |
18
|
|
|
use App\Models\Degree; |
19
|
|
|
use App\Models\Lookup\CriteriaType; |
20
|
|
|
use App\Models\Criteria; |
21
|
|
|
use App\Models\Course; |
22
|
|
|
use App\Models\WorkExperience; |
23
|
|
|
use App\Services\Validation\ApplicationValidator; |
24
|
|
|
use Illuminate\Support\Facades\Auth; |
25
|
|
|
use Illuminate\Support\Facades\Log; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class ApplicationByJobController extends Controller |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Display a listing of the resource. |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Http\Response |
34
|
|
|
*/ |
35
|
|
|
public function index() |
36
|
|
|
{ |
37
|
|
|
// |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function getApplicationFromJob(JobPoster $jobPoster) { |
|
|
|
|
41
|
|
|
$application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
|
|
|
|
42
|
|
|
->where('job_poster_id', $jobPoster->id)->first(); |
43
|
|
|
if ($application == null) { |
44
|
|
|
$application = new JobApplication(); |
45
|
|
|
$application->job_poster_id = $jobPoster->id; |
46
|
|
|
$application->applicant_id = Auth::user()->applicant->id; |
47
|
|
|
$application->application_status_id = ApplicationStatus::where('name', 'draft')->firstOrFail()->id; |
48
|
|
|
$application->save(); |
49
|
|
|
} |
50
|
|
|
return $application; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Show the form for editing Application basics for the specified job. |
55
|
|
|
* |
56
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
57
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
58
|
|
|
*/ |
59
|
|
|
public function edit_basics(JobPoster $jobPoster) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
|
62
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
63
|
|
|
|
64
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
65
|
|
|
|
66
|
|
|
//Ensure user has permissions to view and update application |
67
|
|
|
$this->authorize('view', $application); |
68
|
|
|
$this->authorize('update', $application); |
69
|
|
|
|
70
|
|
|
return view('applicant/application_post_01', [ |
|
|
|
|
71
|
|
|
|
72
|
|
|
/* Application Template Data */ |
73
|
|
|
"application_step" => 1, |
74
|
|
|
"application_template" => Lang::get("applicant/application_template"), |
75
|
|
|
"language_options" => PreferredLanguage::all(), |
76
|
|
|
"citizenship_options" => CitizenshipDeclaration::all(), |
77
|
|
|
"veteran_options" => VeteranStatus::all(), |
78
|
|
|
"preferred_language_template" => Lang::get('common/preferred_language'), |
79
|
|
|
"citizenship_declaration_template" => Lang::get('common/citizenship_declaration'), |
80
|
|
|
"veteran_status_template" => Lang::get('common/veteran_status'), |
81
|
|
|
|
82
|
|
|
/* Job Data */ |
83
|
|
|
"job" => $jobPoster, |
84
|
|
|
|
85
|
|
|
/* Applicant Data */ |
86
|
|
|
"applicant" => $applicant, |
87
|
|
|
"job_application" => $application, |
88
|
|
|
|
89
|
|
|
/* Submission */ |
90
|
|
|
"form_submit_action" => route('job.application.update.1', $jobPoster) |
91
|
|
|
|
92
|
|
|
]); |
|
|
|
|
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Show the form for editing Application Experience for the specified job. |
98
|
|
|
* |
99
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
100
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
101
|
|
|
*/ |
102
|
|
|
public function edit_experience(JobPoster $jobPoster) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
|
105
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
106
|
|
|
|
107
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
108
|
|
|
|
109
|
|
|
//Ensure user has permissions to view and update application |
110
|
|
|
$this->authorize('view', $application); |
111
|
|
|
$this->authorize('update', $application); |
112
|
|
|
|
113
|
|
|
return view('applicant/application_post_02', [ |
|
|
|
|
114
|
|
|
|
115
|
|
|
/* Application Template Data */ |
116
|
|
|
"application_step" => 2, |
117
|
|
|
"application_template" => Lang::get("applicant/application_template"), |
118
|
|
|
|
119
|
|
|
/* Job Data */ |
120
|
|
|
"job" => $jobPoster, |
121
|
|
|
|
122
|
|
|
/* Applicant Data */ |
123
|
|
|
"applicant" => $applicant, |
124
|
|
|
"job_application" => $application, |
125
|
|
|
|
126
|
|
|
/* Submission */ |
127
|
|
|
"form_submit_action" => route('job.application.update.2', $jobPoster) |
128
|
|
|
|
129
|
|
|
]); |
|
|
|
|
130
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Show the form for editing Application Essential Skills for the specified job. |
135
|
|
|
* |
136
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
137
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
138
|
|
|
*/ |
139
|
|
|
public function edit_essential_skills(JobPoster $jobPoster) |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
|
142
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
143
|
|
|
|
144
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
145
|
|
|
|
146
|
|
|
//Ensure user has permissions to view and update application |
147
|
|
|
$this->authorize('view', $application); |
148
|
|
|
$this->authorize('update', $application); |
149
|
|
|
|
150
|
|
|
$criteria = [ |
151
|
|
|
'essential' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
152
|
|
|
return $value->criteria_type->name == 'essential'; |
153
|
|
|
}), |
|
|
|
|
154
|
|
|
'asset' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
155
|
|
|
return $value->criteria_type->name == 'asset'; |
156
|
|
|
}), |
|
|
|
|
157
|
|
|
]; |
158
|
|
|
|
159
|
|
|
return view('applicant/application_post_03', [ |
|
|
|
|
160
|
|
|
|
161
|
|
|
/* Application Template Data */ |
162
|
|
|
"application_step" => 3, |
163
|
|
|
"application_template" => Lang::get("applicant/application_template"), |
164
|
|
|
|
165
|
|
|
/* Job Data */ |
166
|
|
|
"job" => $jobPoster, |
167
|
|
|
|
168
|
|
|
/* Skills Data */ |
169
|
|
|
"skills" => Skill::all(), |
170
|
|
|
"skill_template" => Lang::get("common/skills"), |
171
|
|
|
"criteria" => $criteria, |
172
|
|
|
|
173
|
|
|
/* Applicant Data */ |
174
|
|
|
"applicant" => $applicant, |
175
|
|
|
"job_application" => $application, |
176
|
|
|
|
177
|
|
|
/* Submission */ |
178
|
|
|
"form_submit_action" => route('job.application.update.3', $jobPoster) |
179
|
|
|
|
180
|
|
|
]); |
|
|
|
|
181
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Show the form for editing Application Asset Skills for the specified job. |
186
|
|
|
* |
187
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
188
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
189
|
|
|
*/ |
190
|
|
|
public function edit_asset_skills(JobPoster $jobPoster) |
|
|
|
|
191
|
|
|
{ |
192
|
|
|
|
193
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
194
|
|
|
|
195
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
196
|
|
|
|
197
|
|
|
//Ensure user has permissions to view and update application |
198
|
|
|
$this->authorize('view', $application); |
199
|
|
|
$this->authorize('update', $application); |
200
|
|
|
|
201
|
|
|
$criteria = [ |
202
|
|
|
'essential' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
203
|
|
|
return $value->criteria_type->name == 'essential'; |
204
|
|
|
}), |
|
|
|
|
205
|
|
|
'asset' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
206
|
|
|
return $value->criteria_type->name == 'asset'; |
207
|
|
|
}), |
|
|
|
|
208
|
|
|
]; |
209
|
|
|
|
210
|
|
|
return view('applicant/application_post_04', [ |
|
|
|
|
211
|
|
|
|
212
|
|
|
/* Application Template Data */ |
213
|
|
|
"application_step" => 4, |
214
|
|
|
"application_template" => Lang::get("applicant/application_template"), |
215
|
|
|
|
216
|
|
|
/* Job Data */ |
217
|
|
|
"job" => $jobPoster, |
218
|
|
|
|
219
|
|
|
/* Skills Data */ |
220
|
|
|
"skills" => Skill::all(), |
221
|
|
|
"skill_template" => Lang::get("common/skills"), |
222
|
|
|
"criteria" => $criteria, |
223
|
|
|
|
224
|
|
|
/* Applicant Data */ |
225
|
|
|
"applicant" => $applicant, |
226
|
|
|
"job_application" => $application, |
227
|
|
|
|
228
|
|
|
/* Submission */ |
229
|
|
|
"form_submit_action" => route('job.application.update.4', $jobPoster) |
230
|
|
|
|
231
|
|
|
]); |
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Show the Application Preview for the application for the specified job. |
236
|
|
|
* |
237
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
238
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
239
|
|
|
*/ |
240
|
|
|
public function preview(JobPoster $jobPoster) { |
241
|
|
|
|
242
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
243
|
|
|
|
244
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
245
|
|
|
|
246
|
|
|
$this->authorize('view', $application); |
247
|
|
|
|
248
|
|
|
$criteria = [ |
249
|
|
|
'essential' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
250
|
|
|
return $value->criteria_type->name == 'essential'; |
251
|
|
|
}), |
|
|
|
|
252
|
|
|
'asset' => $jobPoster->criteria->filter(function($value, $key) { |
|
|
|
|
253
|
|
|
return $value->criteria_type->name == 'asset'; |
254
|
|
|
}), |
|
|
|
|
255
|
|
|
]; |
256
|
|
|
|
257
|
|
|
return view('applicant/application_post_05', [ |
|
|
|
|
258
|
|
|
|
259
|
|
|
/* Application Template Data */ |
260
|
|
|
"application_step" => 5, |
261
|
|
|
"application_template" => Lang::get("applicant/application_template"), |
262
|
|
|
"preferred_language_template" => Lang::get('common/preferred_language'), |
263
|
|
|
"citizenship_declaration_template" => Lang::get('common/citizenship_declaration'), |
264
|
|
|
"veteran_status_template" => Lang::get('common/veteran_status'), |
265
|
|
|
|
266
|
|
|
/* Job Data */ |
267
|
|
|
"job" => $jobPoster, |
268
|
|
|
|
269
|
|
|
/* Skills Data */ |
270
|
|
|
"skills" => Skill::all(), |
271
|
|
|
"skill_template" => Lang::get("common/skills"), |
272
|
|
|
"criteria" => $criteria, |
273
|
|
|
|
274
|
|
|
/* Applicant Data */ |
275
|
|
|
"applicant" => $applicant, |
276
|
|
|
"job_application" => $application, |
277
|
|
|
]); |
|
|
|
|
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Show the Confirm Submit page for the application for the specified job. |
282
|
|
|
* |
283
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
284
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
285
|
|
|
*/ |
286
|
|
|
public function confirm(JobPoster $jobPoster) |
287
|
|
|
{ |
288
|
|
|
|
289
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
290
|
|
|
|
291
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
292
|
|
|
|
293
|
|
|
$this->authorize('update', $application); |
294
|
|
|
|
295
|
|
|
return view('applicant/application_post_06', [ |
|
|
|
|
296
|
|
|
/* Application Template Data */ |
297
|
|
|
"application_step" => 6, |
298
|
|
|
"application_template" => Lang::get("applicant/application_template"), |
299
|
|
|
|
300
|
|
|
/* Used by tracker partial */ |
301
|
|
|
"job" => $jobPoster, |
302
|
|
|
"job_application" => $application, |
303
|
|
|
|
304
|
|
|
/* Submission */ |
305
|
|
|
"form_submit_action" => route('job.application.submit', $jobPoster) |
306
|
|
|
]); |
|
|
|
|
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Show the application submission information. |
311
|
|
|
* |
312
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
313
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
314
|
|
|
*/ |
315
|
|
|
public function complete(JobPoster $jobPoster) { |
316
|
|
|
|
317
|
|
|
/* Include Applicant Data */ |
318
|
|
|
|
319
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
320
|
|
|
|
321
|
|
|
/* Include Application Data */ |
322
|
|
|
|
323
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
324
|
|
|
|
325
|
|
|
//Ensure user has permissions to view application |
326
|
|
|
$this->authorize('view', $application); |
327
|
|
|
|
328
|
|
|
/* Return the Completion View */ |
329
|
|
|
|
330
|
|
|
return view('applicant/application_post_complete', [ |
|
|
|
|
331
|
|
|
|
332
|
|
|
/* Application Template Data */ |
333
|
|
|
"application_template" => Lang::get("applicant/application_template"), |
334
|
|
|
|
335
|
|
|
/* Job Data */ |
336
|
|
|
"job" => $jobPoster, |
337
|
|
|
|
338
|
|
|
/* Applicant Data */ |
339
|
|
|
"applicant" => $applicant, |
340
|
|
|
"job_application" => $application |
341
|
|
|
|
342
|
|
|
]); |
|
|
|
|
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Update the Application Basics in storage for the specified job. |
347
|
|
|
* |
348
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
349
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
350
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
351
|
|
|
*/ |
352
|
|
|
public function update_basics(Request $request, JobPoster $jobPoster) |
|
|
|
|
353
|
|
|
{ |
354
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
355
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
356
|
|
|
|
357
|
|
|
//Ensure user has permissions to update this application |
358
|
|
|
$this->authorize('update', $application); |
359
|
|
|
|
360
|
|
|
$application->fill([ |
|
|
|
|
361
|
|
|
'citizenship_declaration_id' => $request->input('citizenship_declaration_id'), |
362
|
|
|
'veteran_status_id' => $request->input('veteran_status_id'), |
363
|
|
|
'preferred_language_id' => $request->input('preferred_language_id'), |
364
|
|
|
]); |
|
|
|
|
365
|
|
|
$application->save(); |
366
|
|
|
|
367
|
|
|
$questions = $jobPoster->job_poster_questions; |
368
|
|
|
$questionsInput = $request->input('questions'); |
369
|
|
|
foreach($questions as $question) { |
|
|
|
|
370
|
|
|
$answer = null; |
371
|
|
|
if (isset($questionsInput[$question->id])) { |
372
|
|
|
$answer = $questionsInput[$question->id]; |
373
|
|
|
} |
374
|
|
|
$answerObj = $application->job_application_answers |
375
|
|
|
->firstWhere('job_poster_question_id', $question->id); |
376
|
|
|
if ($answerObj == null) { |
377
|
|
|
$answerObj = new JobApplicationAnswer(); |
378
|
|
|
$answerObj->job_poster_question_id = $question->id; |
379
|
|
|
$answerObj->job_application_id = $application->id; |
380
|
|
|
} |
381
|
|
|
$answerObj->answer = $answer; |
382
|
|
|
$answerObj->save(); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
//Redirect to correct page |
386
|
|
|
switch($request->input('submit')) { |
387
|
|
|
case 'save_and_quit': |
388
|
|
|
case 'previous': |
389
|
|
|
return redirect()->route('applications.index'); |
|
|
|
|
390
|
|
|
break; |
|
|
|
|
391
|
|
|
case 'save_and_continue': |
392
|
|
|
case 'next': |
393
|
|
|
return redirect()->route('job.application.edit.2', $jobPoster); |
|
|
|
|
394
|
|
|
break; |
395
|
|
|
default: |
396
|
|
|
return redirect()->back()->withInput(); |
|
|
|
|
397
|
|
|
break; |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Update the Application Basics in storage for the specified job. |
403
|
|
|
* |
404
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
405
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
406
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
407
|
|
|
*/ |
408
|
|
|
public function update_experience(Request $request, JobPoster $jobPoster) |
|
|
|
|
409
|
|
|
{ |
410
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
411
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
412
|
|
|
|
413
|
|
|
//Ensure user has permissions to update this application |
414
|
|
|
$this->authorize('update', $application); |
415
|
|
|
|
416
|
|
|
// Record that the user has saved their experience for this application |
417
|
|
|
$application->experience_saved = true; |
418
|
|
|
$application->save(); |
419
|
|
|
|
420
|
|
|
$degrees = $request->input('degrees'); |
421
|
|
|
|
422
|
|
|
//Save new degrees |
423
|
|
|
if (isset($degrees['new'])) { |
424
|
|
|
foreach($degrees['new'] as $degreeInput) { |
|
|
|
|
425
|
|
|
$degree = new Degree(); |
426
|
|
|
$degree->applicant_id = $applicant->id; |
427
|
|
|
$degree->fill([ |
|
|
|
|
428
|
|
|
'degree_type_id' => $degreeInput['degree_type_id'], |
429
|
|
|
'area_of_study' => $degreeInput['area_of_study'], |
430
|
|
|
'institution' => $degreeInput['institution'], |
431
|
|
|
'thesis' => $degreeInput['thesis'], |
432
|
|
|
'start_date' => $degreeInput['start_date'], |
433
|
|
|
'end_date' => $degreeInput['end_date'] |
434
|
|
|
]); |
|
|
|
|
435
|
|
|
$degree->save(); |
436
|
|
|
} |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
//Update old degrees |
440
|
|
|
if (isset($degrees['old'])) { |
441
|
|
|
foreach($degrees['old'] as $id=>$degreeInput) { |
|
|
|
|
442
|
|
|
//Ensure this degree belongs to this applicant |
443
|
|
|
$degree = $applicant->degrees->firstWhere('id', $id); |
444
|
|
|
if ($degree != null) { |
445
|
|
|
$degree->fill([ |
|
|
|
|
446
|
|
|
'degree_type_id' => $degreeInput['degree_type_id'], |
447
|
|
|
'area_of_study' => $degreeInput['area_of_study'], |
448
|
|
|
'institution' => $degreeInput['institution'], |
449
|
|
|
'thesis' => $degreeInput['thesis'], |
450
|
|
|
'start_date' => $degreeInput['start_date'], |
451
|
|
|
'end_date' => $degreeInput['end_date'] |
452
|
|
|
]); |
|
|
|
|
453
|
|
|
$degree->save(); |
454
|
|
|
} else { |
455
|
|
|
Log::warning('Applicant '.$applicant->id.' attempted to update degree with invalid id '.$id); |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
$courses = $request->input('courses'); |
461
|
|
|
|
462
|
|
|
//Save new courses |
463
|
|
|
if (isset($courses['new'])) { |
464
|
|
|
foreach($courses['new'] as $courseInput) { |
|
|
|
|
465
|
|
|
$course = new Course(); |
466
|
|
|
$course->applicant_id = $applicant->id; |
467
|
|
|
$course->fill([ |
|
|
|
|
468
|
|
|
'name' => $courseInput['name'], |
469
|
|
|
'institution' => $courseInput['institution'], |
470
|
|
|
'course_status_id' => $courseInput['course_status_id'], |
471
|
|
|
'start_date' => $courseInput['start_date'], |
472
|
|
|
'end_date' => $courseInput['end_date'] |
473
|
|
|
]); |
|
|
|
|
474
|
|
|
$course->save(); |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
//Update old courses |
479
|
|
|
if (isset($courses['old'])) { |
480
|
|
|
foreach($courses['old'] as $id=>$courseInput) { |
|
|
|
|
481
|
|
|
//Ensure this course belongs to this applicant |
482
|
|
|
$course = $applicant->courses->firstWhere('id', $id); |
483
|
|
|
if ($course != null) { |
484
|
|
|
$course->fill([ |
|
|
|
|
485
|
|
|
'name' => $courseInput['name'], |
486
|
|
|
'institution' => $courseInput['institution'], |
487
|
|
|
'course_status_id' => $courseInput['course_status_id'], |
488
|
|
|
'start_date' => $courseInput['start_date'], |
489
|
|
|
'end_date' => $courseInput['end_date'] |
490
|
|
|
]); |
|
|
|
|
491
|
|
|
$course->save(); |
492
|
|
|
} else { |
493
|
|
|
Log::warning('Applicant '.$applicant->id.' attempted to update course with invalid id '.$id); |
494
|
|
|
} |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
$work_experiences = $request->input('work_experiences'); |
499
|
|
|
|
500
|
|
|
//Save new work_experiences |
501
|
|
|
if (isset($work_experiences['new'])) { |
502
|
|
|
foreach($work_experiences['new'] as $workExperienceInput) { |
|
|
|
|
503
|
|
|
$workExperience = new WorkExperience(); |
504
|
|
|
$workExperience->applicant_id = $applicant->id; |
505
|
|
|
$workExperience->fill([ |
|
|
|
|
506
|
|
|
'role' => $workExperienceInput['role'], |
507
|
|
|
'company' => $workExperienceInput['company'], |
508
|
|
|
'description' => $workExperienceInput['description'], |
509
|
|
|
'start_date' => $workExperienceInput['start_date'], |
510
|
|
|
'end_date' => $workExperienceInput['end_date'] |
511
|
|
|
]); |
|
|
|
|
512
|
|
|
$workExperience->save(); |
513
|
|
|
} |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
//Update old work_experiences |
517
|
|
|
if (isset($work_experiences['old'])) { |
518
|
|
|
foreach($work_experiences['old'] as $id=>$workExperienceInput) { |
|
|
|
|
519
|
|
|
//Ensure this work_experience belongs to this applicant |
520
|
|
|
$workExperience = $applicant->work_experiences->firstWhere('id', $id); |
521
|
|
|
if ($workExperience != null) { |
522
|
|
|
$workExperience->fill([ |
|
|
|
|
523
|
|
|
'role' => $workExperienceInput['role'], |
524
|
|
|
'company' => $workExperienceInput['company'], |
525
|
|
|
'description' => $workExperienceInput['description'], |
526
|
|
|
'start_date' => $workExperienceInput['start_date'], |
527
|
|
|
'end_date' => $workExperienceInput['end_date'] |
528
|
|
|
]); |
|
|
|
|
529
|
|
|
$workExperience->save(); |
530
|
|
|
} else { |
531
|
|
|
Log::warning('Applicant '.$applicant->id.' attempted to update work_experience with invalid id '.$id); |
532
|
|
|
} |
533
|
|
|
} |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
//Redirect to correct page |
537
|
|
|
switch($request->input('submit')) { |
538
|
|
|
case 'save_and_quit': |
539
|
|
|
return redirect()->route('applications.index'); |
|
|
|
|
540
|
|
|
break; |
|
|
|
|
541
|
|
|
case 'save_and_continue': |
542
|
|
|
case 'next': |
543
|
|
|
return redirect()->route('job.application.edit.3', $jobPoster); |
|
|
|
|
544
|
|
|
break; |
545
|
|
|
case 'previous': |
546
|
|
|
return redirect()->route('job.application.edit.1', $jobPoster); |
|
|
|
|
547
|
|
|
break; |
548
|
|
|
default: |
549
|
|
|
return redirect()->back()->withInput(); |
|
|
|
|
550
|
|
|
break; |
551
|
|
|
} |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Update the Application Essential Skills in storage for the specified job. |
556
|
|
|
* |
557
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
558
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
559
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
560
|
|
|
*/ |
561
|
|
|
public function update_essential_skills(Request $request, JobPoster $jobPoster) |
|
|
|
|
562
|
|
|
{ |
563
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
564
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
565
|
|
|
|
566
|
|
|
//Ensure user has permissions to update this application |
567
|
|
|
$this->authorize('update', $application); |
568
|
|
|
|
569
|
|
|
$skillDeclarations = $request->input('skill_declarations'); |
570
|
|
|
$claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
571
|
|
|
|
572
|
|
|
//Save new skill declarartions |
573
|
|
|
if (isset($skillDeclarations['new'])) { |
574
|
|
|
foreach($skillDeclarations['new'] as $skillType => $typeInput) { |
|
|
|
|
575
|
|
|
foreach($typeInput as $criterion_id=>$skillDeclarationInput) { |
|
|
|
|
576
|
|
|
$skillDeclaration = new SkillDeclaration(); |
577
|
|
|
$skillDeclaration->applicant_id = $applicant->id; |
578
|
|
|
$skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id; |
579
|
|
|
$skillDeclaration->skill_status_id = $claimedStatusId; |
580
|
|
|
$skillDeclaration->fill([ |
|
|
|
|
581
|
|
|
'description' => $skillDeclarationInput['description'], |
582
|
|
|
'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
583
|
|
|
]); |
|
|
|
|
584
|
|
|
$skillDeclaration->save(); |
585
|
|
|
|
586
|
|
|
$referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
587
|
|
|
$skillDeclaration->references()->sync($referenceIds); |
588
|
|
|
|
589
|
|
|
$sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
590
|
|
|
$skillDeclaration->work_samples()->sync($sampleIds); |
591
|
|
|
} |
592
|
|
|
} |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
//Update old declarations |
596
|
|
|
if (isset($skillDeclarations['old'])) { |
597
|
|
|
foreach($skillDeclarations['old'] as $skillType => $typeInput) { |
|
|
|
|
598
|
|
|
foreach($typeInput as $id=>$skillDeclarationInput) { |
|
|
|
|
599
|
|
|
//Ensure this declaration belongs to this applicant |
600
|
|
|
$skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
601
|
|
|
if ($skillDeclaration != null) { |
602
|
|
|
//skill_id and skill_status cannot be changed |
603
|
|
|
$skillDeclaration->fill([ |
|
|
|
|
604
|
|
|
'description' => $skillDeclarationInput['description'], |
605
|
|
|
'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
606
|
|
|
]); |
|
|
|
|
607
|
|
|
$skillDeclaration->save(); |
608
|
|
|
|
609
|
|
|
$referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
610
|
|
|
$skillDeclaration->references()->sync($referenceIds); |
611
|
|
|
|
612
|
|
|
$sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
613
|
|
|
$skillDeclaration->work_samples()->sync($sampleIds); |
614
|
|
|
} else { |
615
|
|
|
Log::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id); |
616
|
|
|
} |
617
|
|
|
} |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
//Redirect to correct page |
622
|
|
|
switch($request->input('submit')) { |
623
|
|
|
case 'save_and_quit': |
624
|
|
|
return redirect()->route('applications.index'); |
|
|
|
|
625
|
|
|
break; |
|
|
|
|
626
|
|
|
case 'save_and_continue': |
627
|
|
|
case 'next': |
628
|
|
|
return redirect()->route('job.application.edit.4', $jobPoster); |
|
|
|
|
629
|
|
|
break; |
630
|
|
|
case 'previous': |
631
|
|
|
return redirect()->route('job.application.edit.2', $jobPoster); |
|
|
|
|
632
|
|
|
break; |
633
|
|
|
default: |
634
|
|
|
return redirect()->back()->withInput(); |
|
|
|
|
635
|
|
|
break; |
636
|
|
|
} |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Update the Application Asset Skills in storage for the specified job. |
641
|
|
|
* |
642
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
643
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
644
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
645
|
|
|
*/ |
646
|
|
|
public function update_asset_skills(Request $request, JobPoster $jobPoster) |
|
|
|
|
647
|
|
|
{ |
648
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
649
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
650
|
|
|
|
651
|
|
|
//Ensure user has permissions to update this application |
652
|
|
|
$this->authorize('update', $application); |
653
|
|
|
|
654
|
|
|
$skillDeclarations = $request->input('skill_declarations'); |
655
|
|
|
$claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
656
|
|
|
|
657
|
|
|
//Save new skill declarartions |
658
|
|
|
if (isset($skillDeclarations['new'])) { |
659
|
|
|
foreach($skillDeclarations['new'] as $skillType => $typeInput) { |
|
|
|
|
660
|
|
|
foreach($typeInput as $criterion_id=>$skillDeclarationInput) { |
|
|
|
|
661
|
|
|
$skillDeclaration = new SkillDeclaration(); |
662
|
|
|
$skillDeclaration->applicant_id = $applicant->id; |
663
|
|
|
$skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id; |
664
|
|
|
$skillDeclaration->skill_status_id = $claimedStatusId; |
665
|
|
|
$skillDeclaration->fill([ |
|
|
|
|
666
|
|
|
'description' => $skillDeclarationInput['description'], |
667
|
|
|
'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
668
|
|
|
]); |
|
|
|
|
669
|
|
|
$skillDeclaration->save(); |
670
|
|
|
|
671
|
|
|
$referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
672
|
|
|
$skillDeclaration->references()->sync($referenceIds); |
673
|
|
|
|
674
|
|
|
$sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
675
|
|
|
$skillDeclaration->work_samples()->sync($sampleIds); |
676
|
|
|
} |
677
|
|
|
} |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
//Update old declarations |
681
|
|
|
if (isset($skillDeclarations['old'])) { |
682
|
|
|
foreach($skillDeclarations['old'] as $skillType => $typeInput) { |
|
|
|
|
683
|
|
|
foreach($typeInput as $id=>$skillDeclarationInput) { |
|
|
|
|
684
|
|
|
//Ensure this declaration belongs to this applicant |
685
|
|
|
$skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
686
|
|
|
if ($skillDeclaration != null) { |
687
|
|
|
//skill_id and skill_status cannot be changed |
688
|
|
|
$skillDeclaration->fill([ |
|
|
|
|
689
|
|
|
'description' => $skillDeclarationInput['description'], |
690
|
|
|
'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
691
|
|
|
]); |
|
|
|
|
692
|
|
|
$skillDeclaration->save(); |
693
|
|
|
|
694
|
|
|
$referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
695
|
|
|
$skillDeclaration->references()->sync($referenceIds); |
696
|
|
|
|
697
|
|
|
$sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
698
|
|
|
$skillDeclaration->work_samples()->sync($sampleIds); |
699
|
|
|
} else { |
700
|
|
|
Log::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id); |
701
|
|
|
} |
702
|
|
|
} |
703
|
|
|
} |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
//Redirect to correct page |
707
|
|
|
switch($request->input('submit')) { |
708
|
|
|
case 'save_and_quit': |
709
|
|
|
return redirect()->route('applications.index'); |
|
|
|
|
710
|
|
|
break; |
|
|
|
|
711
|
|
|
case 'save_and_continue': |
712
|
|
|
case 'next': |
713
|
|
|
return redirect()->route('job.application.edit.5', $jobPoster); |
|
|
|
|
714
|
|
|
break; |
715
|
|
|
case 'previous': |
716
|
|
|
return redirect()->route('job.application.edit.3', $jobPoster); |
|
|
|
|
717
|
|
|
break; |
718
|
|
|
default: |
719
|
|
|
return redirect()->back()->withInput(); |
|
|
|
|
720
|
|
|
break; |
721
|
|
|
} |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
/** |
725
|
|
|
* Submit the Application for the specified job. |
726
|
|
|
* |
727
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
728
|
|
|
* @param \App\Models\JobPoster $jobPoster |
|
|
|
|
729
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
730
|
|
|
*/ |
731
|
|
|
public function submit(Request $request, JobPoster $jobPoster) |
732
|
|
|
{ |
733
|
|
|
$applicant = Auth::user()->applicant; |
|
|
|
|
734
|
|
|
$application = $this->getApplicationFromJob($jobPoster); |
735
|
|
|
|
736
|
|
|
//Ensure user has permissions to update this application |
737
|
|
|
$this->authorize('update', $application); |
738
|
|
|
|
739
|
|
|
//Only complete submission if submit button was pressed |
740
|
|
|
if ($request->input('submit') == "submit") { |
741
|
|
|
|
742
|
|
|
$request->validate([ |
|
|
|
|
743
|
|
|
'submission_signature' => [ |
744
|
|
|
'required', |
745
|
|
|
'string', |
746
|
|
|
'max:191', |
747
|
|
|
], |
748
|
|
|
'submission_date' => [ |
749
|
|
|
'required', |
750
|
|
|
'string', |
751
|
|
|
'max:191', |
752
|
|
|
] |
753
|
|
|
]); |
|
|
|
|
754
|
|
|
|
755
|
|
|
//Save any final info |
756
|
|
|
$application->fill([ |
|
|
|
|
757
|
|
|
'submission_signature' => $request->input('submission_signature'), |
758
|
|
|
'submission_date' => $request->input('submission_date'), |
759
|
|
|
]); |
|
|
|
|
760
|
|
|
|
761
|
|
|
$validator = new ApplicationValidator(); |
762
|
|
|
$validator->validate($application); |
763
|
|
|
|
764
|
|
|
//Change status to 'submitted' |
765
|
|
|
$application->application_status_id = ApplicationStatus::where('name', 'submitted')->firstOrFail()->id; |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
$application->save(); |
769
|
|
|
|
770
|
|
|
//Redirect to correct page |
771
|
|
|
switch($request->input('submit')) { |
772
|
|
|
case 'save_and_quit': |
773
|
|
|
return redirect()->route('applications.index'); |
|
|
|
|
774
|
|
|
break; |
|
|
|
|
775
|
|
|
case 'submit': |
776
|
|
|
return redirect()->route('job.application.complete', $jobPoster); |
|
|
|
|
777
|
|
|
break; |
778
|
|
|
case 'previous': |
779
|
|
|
return redirect()->route('job.application.edit.4', $jobPoster); |
|
|
|
|
780
|
|
|
break; |
781
|
|
|
default: |
782
|
|
|
return redirect()->back()->withInput(); |
|
|
|
|
783
|
|
|
break; |
784
|
|
|
} |
785
|
|
|
} |
786
|
|
|
} |
787
|
|
|
|