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