Total Complexity | 71 |
Total Lines | 773 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
Complex classes like ApplicationByJobController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ApplicationByJobController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class ApplicationByJobController extends Controller |
||
27 | { |
||
28 | /** |
||
29 | * Display a listing of the applications for given jobPoster. |
||
30 | * |
||
31 | * @param \App\Models\JobPoster $jobPoster Incoming JobPoster object. |
||
32 | * @return \Illuminate\Http\Response |
||
33 | */ |
||
34 | public function index(JobPoster $jobPoster) |
||
35 | { |
||
36 | $applications = $jobPoster->submitted_applications() |
||
37 | ->with([ |
||
38 | 'veteran_status', |
||
39 | 'citizenship_declaration', |
||
40 | 'application_review', |
||
41 | 'applicant.user', |
||
42 | 'job_poster.criteria', |
||
43 | ]) |
||
44 | ->get(); |
||
45 | return view('manager/review_applications', [ |
||
46 | // Localization Strings. |
||
47 | 'jobs_l10n' => Lang::get('manager/job_index'), |
||
48 | // Data. |
||
49 | 'job' => $jobPoster->toApiArray(), |
||
50 | 'applications' => $applications, |
||
51 | 'review_statuses' => ReviewStatus::all() |
||
52 | ]); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Return the current applicant's application for a given Job Poster. |
||
57 | * |
||
58 | * @param \App\Models\JobPoster $jobPoster Incoming JobPoster object. |
||
59 | * @return mixed|\App\Models\JobApplication |
||
60 | */ |
||
61 | protected function getApplicationFromJob(JobPoster $jobPoster) |
||
62 | { |
||
63 | $application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
||
|
|||
64 | ->where('job_poster_id', $jobPoster->id)->first(); |
||
65 | if ($application == null) { |
||
66 | $application = new JobApplication(); |
||
67 | $application->job_poster_id = $jobPoster->id; |
||
68 | $application->applicant_id = Auth::user()->applicant->id; |
||
69 | $application->application_status_id = ApplicationStatus::where('name', 'draft')->firstOrFail()->id; |
||
70 | $application->save(); |
||
71 | } |
||
72 | return $application; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Show the form for editing Application basics for the specified job. |
||
77 | * |
||
78 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
79 | * @return \Illuminate\Http\Response |
||
80 | */ |
||
81 | public function editBasics(JobPoster $jobPoster) |
||
82 | { |
||
83 | $applicant = Auth::user()->applicant; |
||
84 | $application = $this->getApplicationFromJob($jobPoster); |
||
85 | |||
86 | // Ensure user has permissions to view and update application. |
||
87 | $this->authorize('view', $application); |
||
88 | $this->authorize('update', $application); |
||
89 | |||
90 | return view( |
||
91 | 'applicant/application_post_01', |
||
92 | [ |
||
93 | // Application Template Data. |
||
94 | 'application_step' => 1, |
||
95 | 'application_template' => Lang::get('applicant/application_template'), |
||
96 | 'language_options' => PreferredLanguage::all(), |
||
97 | 'citizenship_options' => CitizenshipDeclaration::all(), |
||
98 | 'veteran_options' => VeteranStatus::all(), |
||
99 | 'preferred_language_template' => Lang::get('common/preferred_language'), |
||
100 | 'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'), |
||
101 | 'veteran_status_template' => Lang::get('common/veteran_status'), |
||
102 | // Job Data. |
||
103 | 'job' => $jobPoster, |
||
104 | // Applicant Data. |
||
105 | 'applicant' => $applicant, |
||
106 | 'job_application' => $application, |
||
107 | // Submission. |
||
108 | 'form_submit_action' => route('job.application.update.1', $jobPoster) |
||
109 | ] |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Show the form for editing Application Experience for the specified job. |
||
115 | * |
||
116 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
117 | * @return \Illuminate\Http\Response |
||
118 | */ |
||
119 | public function editExperience(JobPoster $jobPoster) |
||
120 | { |
||
121 | $applicant = Auth::user()->applicant; |
||
122 | $application = $this->getApplicationFromJob($jobPoster); |
||
123 | |||
124 | // Ensure user has permissions to view and update application. |
||
125 | $this->authorize('view', $application); |
||
126 | $this->authorize('update', $application); |
||
127 | |||
128 | return view( |
||
129 | 'applicant/application_post_02', |
||
130 | [ |
||
131 | // Application Template Data. |
||
132 | 'application_step' => 2, |
||
133 | 'application_template' => Lang::get('applicant/application_template'), |
||
134 | // Job Data. |
||
135 | 'job' => $jobPoster, |
||
136 | // Applicant Data. |
||
137 | 'applicant' => $applicant, |
||
138 | 'job_application' => $application, |
||
139 | // Submission. |
||
140 | 'form_submit_action' => route('job.application.update.2', $jobPoster) |
||
141 | ] |
||
142 | ); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Show the form for editing Application Essential Skills for the specified job. |
||
147 | * |
||
148 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
149 | * @return \Illuminate\Http\Response |
||
150 | */ |
||
151 | public function editEssentialSkills(JobPoster $jobPoster) |
||
152 | { |
||
153 | $applicant = Auth::user()->applicant; |
||
154 | $application = $this->getApplicationFromJob($jobPoster); |
||
155 | |||
156 | // Ensure user has permissions to view and update application. |
||
157 | $this->authorize('view', $application); |
||
158 | $this->authorize('update', $application); |
||
159 | |||
160 | $criteria = [ |
||
161 | 'essential' => $jobPoster->criteria->filter(function ($value, $key) { |
||
162 | return $value->criteria_type->name == 'essential'; |
||
163 | }), |
||
164 | 'asset' => $jobPoster->criteria->filter(function ($value, $key) { |
||
165 | return $value->criteria_type->name == 'asset'; |
||
166 | }), |
||
167 | ]; |
||
168 | |||
169 | return view( |
||
170 | 'applicant/application_post_03', |
||
171 | [ |
||
172 | // Application Template Data. |
||
173 | 'application_step' => 3, |
||
174 | 'application_template' => Lang::get('applicant/application_template'), |
||
175 | // Job Data. |
||
176 | 'job' => $jobPoster, |
||
177 | // Skills Data. |
||
178 | 'skills' => Skill::all(), |
||
179 | 'skill_template' => Lang::get('common/skills'), |
||
180 | 'criteria' => $criteria, |
||
181 | // Applicant Data. |
||
182 | 'applicant' => $applicant, |
||
183 | 'job_application' => $application, |
||
184 | // Submission. |
||
185 | 'form_submit_action' => route('job.application.update.3', $jobPoster) |
||
186 | ] |
||
187 | ); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Show the form for editing Application Asset Skills for the specified job. |
||
192 | * |
||
193 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
194 | * @return \Illuminate\Http\Response |
||
195 | */ |
||
196 | public function editAssetSkills(JobPoster $jobPoster) |
||
197 | { |
||
198 | $applicant = Auth::user()->applicant; |
||
199 | $application = $this->getApplicationFromJob($jobPoster); |
||
200 | |||
201 | // Ensure user has permissions to view and update application. |
||
202 | $this->authorize('view', $application); |
||
203 | $this->authorize('update', $application); |
||
204 | |||
205 | $criteria = [ |
||
206 | 'essential' => $jobPoster->criteria->filter(function ($value, $key) { |
||
207 | return $value->criteria_type->name == 'essential'; |
||
208 | }), |
||
209 | 'asset' => $jobPoster->criteria->filter(function ($value, $key) { |
||
210 | return $value->criteria_type->name == 'asset'; |
||
211 | }), |
||
212 | ]; |
||
213 | |||
214 | return view( |
||
215 | 'applicant/application_post_04', |
||
216 | [ |
||
217 | // Application Template Data. |
||
218 | 'application_step' => 4, |
||
219 | 'application_template' => Lang::get('applicant/application_template'), |
||
220 | // Job Data. |
||
221 | 'job' => $jobPoster, |
||
222 | // Skills Data. |
||
223 | 'skills' => Skill::all(), |
||
224 | 'skill_template' => Lang::get('common/skills'), |
||
225 | 'criteria' => $criteria, |
||
226 | // Applicant Data. |
||
227 | 'applicant' => $applicant, |
||
228 | 'job_application' => $application, |
||
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 Incoming Job Poster object. |
||
239 | * @return \Illuminate\Http\Response |
||
240 | */ |
||
241 | public function preview(JobPoster $jobPoster) |
||
242 | { |
||
243 | $applicant = Auth::user()->applicant; |
||
244 | $application = $this->getApplicationFromJob($jobPoster); |
||
245 | |||
246 | $this->authorize('view', $application); |
||
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( |
||
257 | '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 | // Job Data. |
||
266 | 'job' => $jobPoster, |
||
267 | // Skills Data. |
||
268 | 'skills' => Skill::all(), |
||
269 | 'skill_template' => Lang::get('common/skills'), |
||
270 | 'criteria' => $criteria, |
||
271 | // Applicant Data. |
||
272 | 'applicant' => $applicant, |
||
273 | 'job_application' => $application, |
||
274 | ] |
||
275 | ); |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * Show the Confirm Submit page for the application for the specified job. |
||
280 | * |
||
281 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
282 | * @return \Illuminate\Http\Response |
||
283 | */ |
||
284 | public function confirm(JobPoster $jobPoster) |
||
285 | { |
||
286 | $applicant = Auth::user()->applicant; |
||
287 | $application = $this->getApplicationFromJob($jobPoster); |
||
288 | |||
289 | $this->authorize('update', $application); |
||
290 | |||
291 | return view( |
||
292 | 'applicant/application_post_06', |
||
293 | [ |
||
294 | // Application Template Data. |
||
295 | 'application_step' => 6, |
||
296 | 'application_template' => Lang::get('applicant/application_template'), |
||
297 | // Used by tracker partial. |
||
298 | 'job' => $jobPoster, |
||
299 | 'job_application' => $application, |
||
300 | // Submission. |
||
301 | 'form_submit_action' => route('job.application.submit', $jobPoster) |
||
302 | ] |
||
303 | ); |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * Show the application submission information. |
||
308 | * |
||
309 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
310 | * @return \Illuminate\Http\Response |
||
311 | */ |
||
312 | public function complete(JobPoster $jobPoster) |
||
333 | ] |
||
334 | ); |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * Update the Application Basics in storage for the specified job. |
||
339 | * |
||
340 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
341 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
342 | * @return \Illuminate\Http\Response |
||
343 | */ |
||
344 | public function updateBasics(Request $request, JobPoster $jobPoster) |
||
390 | } |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * Update the Application Basics in storage for the specified job. |
||
395 | * |
||
396 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
397 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
398 | * @return \Illuminate\Http\Response |
||
399 | */ |
||
400 | public function updateExperience(Request $request, JobPoster $jobPoster) |
||
401 | { |
||
402 | $applicant = Auth::user()->applicant; |
||
403 | $application = $this->getApplicationFromJob($jobPoster); |
||
404 | |||
405 | // Ensure user has permissions to update this application. |
||
406 | $this->authorize('update', $application); |
||
407 | |||
408 | // Record that the user has saved their experience for this application. |
||
409 | $application->experience_saved = true; |
||
410 | $application->save(); |
||
411 | |||
412 | $degrees = $request->input('degrees'); |
||
413 | |||
414 | $request->validate([ |
||
415 | 'degrees.new.*.degree_type_id' => 'required', |
||
416 | 'degrees.new.*.area_of_study' => 'required', |
||
417 | 'degrees.new.*.institution' => 'required', |
||
418 | 'degrees.new.*.thesis' => 'nullable', |
||
419 | 'degrees.new.*.start_date' => 'required|date', |
||
420 | 'degrees.new.*.end_date' => 'required|date', |
||
421 | 'degrees.new.*.blockcert_url' => 'nullable|string', |
||
422 | ]); |
||
423 | |||
424 | // Save new degrees. |
||
425 | if (isset($degrees['new'])) { |
||
426 | foreach ($degrees['new'] as $degreeInput) { |
||
427 | $degree = new Degree(); |
||
428 | $degree->applicant_id = $applicant->id; |
||
429 | $degree->fill([ |
||
430 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
431 | 'area_of_study' => $degreeInput['area_of_study'], |
||
432 | 'institution' => $degreeInput['institution'], |
||
433 | 'thesis' => $degreeInput['thesis'], |
||
434 | 'start_date' => $degreeInput['start_date'], |
||
435 | 'end_date' => $degreeInput['end_date'], |
||
436 | 'blockcert_url' => $degreeInput['blockcert_url'], |
||
437 | ]); |
||
438 | $degree->save(); |
||
439 | } |
||
440 | } |
||
441 | |||
442 | // Update old degrees. |
||
443 | if (isset($degrees['old'])) { |
||
444 | foreach ($degrees['old'] as $id => $degreeInput) { |
||
445 | // Ensure this degree belongs to this applicant. |
||
446 | $degree = $applicant->degrees->firstWhere('id', $id); |
||
447 | if ($degree != null) { |
||
448 | $degree->fill([ |
||
449 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
450 | 'area_of_study' => $degreeInput['area_of_study'], |
||
451 | 'institution' => $degreeInput['institution'], |
||
452 | 'thesis' => $degreeInput['thesis'], |
||
453 | 'start_date' => $degreeInput['start_date'], |
||
454 | 'end_date' => $degreeInput['end_date'], |
||
455 | 'blockcert_url' => $degreeInput['blockcert_url'], |
||
456 | ]); |
||
457 | $degree->save(); |
||
458 | } else { |
||
459 | Log::warning("Applicant $applicant->id attempted to update degree with invalid id: $id"); |
||
460 | } |
||
461 | } |
||
462 | } |
||
463 | |||
464 | $courses = $request->input('courses'); |
||
465 | |||
466 | $request->validate([ |
||
467 | 'courses.new.*.name' => 'required', |
||
468 | 'courses.new.*.institution' => 'required', |
||
469 | 'courses.new.*.course_status_id' => 'required', |
||
470 | 'courses.new.*.start_date' => 'required|date', |
||
471 | 'courses.new.*.end_date' => 'required|date', |
||
472 | ]); |
||
473 | |||
474 | // Save new courses. |
||
475 | if (isset($courses['new'])) { |
||
476 | foreach ($courses['new'] as $courseInput) { |
||
477 | $course = new Course(); |
||
478 | $course->applicant_id = $applicant->id; |
||
479 | $course->fill([ |
||
480 | 'name' => $courseInput['name'], |
||
481 | 'institution' => $courseInput['institution'], |
||
482 | 'course_status_id' => $courseInput['course_status_id'], |
||
483 | 'start_date' => $courseInput['start_date'], |
||
484 | 'end_date' => $courseInput['end_date'] |
||
485 | ]); |
||
486 | $course->save(); |
||
487 | } |
||
488 | } |
||
489 | |||
490 | // Update old courses. |
||
491 | if (isset($courses['old'])) { |
||
492 | foreach ($courses['old'] as $id => $courseInput) { |
||
493 | // Ensure this course belongs to this applicant. |
||
494 | $course = $applicant->courses->firstWhere('id', $id); |
||
495 | if ($course != null) { |
||
496 | $course->fill([ |
||
497 | 'name' => $courseInput['name'], |
||
498 | 'institution' => $courseInput['institution'], |
||
499 | 'course_status_id' => $courseInput['course_status_id'], |
||
500 | 'start_date' => $courseInput['start_date'], |
||
501 | 'end_date' => $courseInput['end_date'] |
||
502 | ]); |
||
503 | $course->save(); |
||
504 | } else { |
||
505 | Log::warning("Applicant $applicant->id attempted to update course with invalid id: $id"); |
||
506 | } |
||
507 | } |
||
508 | } |
||
509 | |||
510 | $work_experiences = $request->input('work_experiences'); |
||
511 | |||
512 | $request->validate([ |
||
513 | 'work_experiences.new.*.role' => 'required', |
||
514 | 'work_experiences.new.*.company' => 'required', |
||
515 | 'work_experiences.new.*.description' => 'required', |
||
516 | 'work_experiences.new.*.start_date' => 'required|date', |
||
517 | 'work_experiences.new.*.end_date' => 'required|date', |
||
518 | ]); |
||
519 | |||
520 | // Save new work_experiences. |
||
521 | if (isset($work_experiences['new'])) { |
||
522 | foreach ($work_experiences['new'] as $workExperienceInput) { |
||
523 | $workExperience = new WorkExperience(); |
||
524 | $workExperience->applicant_id = $applicant->id; |
||
525 | $workExperience->fill([ |
||
526 | 'role' => $workExperienceInput['role'], |
||
527 | 'company' => $workExperienceInput['company'], |
||
528 | 'description' => $workExperienceInput['description'], |
||
529 | 'start_date' => $workExperienceInput['start_date'], |
||
530 | 'end_date' => $workExperienceInput['end_date'] |
||
531 | ]); |
||
532 | $workExperience->save(); |
||
533 | } |
||
534 | } |
||
535 | |||
536 | // Update old work_experiences. |
||
537 | if (isset($work_experiences['old'])) { |
||
538 | foreach ($work_experiences['old'] as $id => $workExperienceInput) { |
||
539 | // Ensure this work_experience belongs to this applicant. |
||
540 | $workExperience = $applicant->work_experiences->firstWhere('id', $id); |
||
541 | if ($workExperience != null) { |
||
542 | $workExperience->fill([ |
||
543 | 'role' => $workExperienceInput['role'], |
||
544 | 'company' => $workExperienceInput['company'], |
||
545 | 'description' => $workExperienceInput['description'], |
||
546 | 'start_date' => $workExperienceInput['start_date'], |
||
547 | 'end_date' => $workExperienceInput['end_date'] |
||
548 | ]); |
||
549 | $workExperience->save(); |
||
550 | } else { |
||
551 | Log::warning("Applicant $applicant->id attempted to update work_experience with invalid id: $id"); |
||
552 | } |
||
553 | } |
||
554 | } |
||
555 | |||
556 | // Redirect to correct page. |
||
557 | switch ($request->input('submit')) { |
||
558 | case 'save_and_quit': |
||
559 | return redirect()->route('applications.index'); |
||
560 | break; |
||
561 | case 'save_and_continue': |
||
562 | case 'next': |
||
563 | return redirect()->route('job.application.edit.3', $jobPoster); |
||
564 | break; |
||
565 | case 'previous': |
||
566 | return redirect()->route('job.application.edit.1', $jobPoster); |
||
567 | break; |
||
568 | default: |
||
569 | return redirect()->back()->withInput(); |
||
570 | } |
||
571 | } |
||
572 | |||
573 | /** |
||
574 | * Update the Application Essential Skills in storage for the specified job. |
||
575 | * |
||
576 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
577 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
578 | * @return \Illuminate\Http\Response |
||
579 | */ |
||
580 | public function updateEssentialSkills(Request $request, JobPoster $jobPoster) |
||
654 | } |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * Update the Application Asset Skills in storage for the specified job. |
||
659 | * |
||
660 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
661 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
662 | * @return \Illuminate\Http\Response |
||
663 | */ |
||
664 | public function updateAssetSkills(Request $request, JobPoster $jobPoster) |
||
665 | { |
||
666 | $applicant = Auth::user()->applicant; |
||
667 | $application = $this->getApplicationFromJob($jobPoster); |
||
668 | |||
669 | // Ensure user has permissions to update this application. |
||
670 | $this->authorize('update', $application); |
||
671 | |||
672 | $skillDeclarations = $request->input('skill_declarations'); |
||
673 | $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
||
674 | |||
675 | // Save new skill declarartions. |
||
676 | if (isset($skillDeclarations['new'])) { |
||
677 | foreach ($skillDeclarations['new'] as $skillType => $typeInput) { |
||
678 | foreach ($typeInput as $criterion_id => $skillDeclarationInput) { |
||
679 | $skillDeclaration = new SkillDeclaration(); |
||
680 | $skillDeclaration->applicant_id = $applicant->id; |
||
681 | $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id; |
||
682 | $skillDeclaration->skill_status_id = $claimedStatusId; |
||
683 | $skillDeclaration->fill([ |
||
684 | 'description' => $skillDeclarationInput['description'], |
||
685 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
686 | ]); |
||
687 | $skillDeclaration->save(); |
||
688 | |||
689 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
690 | $skillDeclaration->references()->sync($referenceIds); |
||
691 | |||
692 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
693 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
694 | } |
||
695 | } |
||
696 | } |
||
697 | |||
698 | // Update old declarations. |
||
699 | if (isset($skillDeclarations['old'])) { |
||
700 | foreach ($skillDeclarations['old'] as $skillType => $typeInput) { |
||
701 | foreach ($typeInput as $id => $skillDeclarationInput) { |
||
702 | // Ensure this declaration belongs to this applicant. |
||
703 | $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
||
704 | if ($skillDeclaration != null) { |
||
705 | // skill_id and skill_status cannot be changed. |
||
1 ignored issue
–
show
|
|||
706 | $skillDeclaration->fill([ |
||
707 | 'description' => $skillDeclarationInput['description'], |
||
708 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
709 | ]); |
||
710 | $skillDeclaration->save(); |
||
711 | |||
712 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
713 | $skillDeclaration->references()->sync($referenceIds); |
||
714 | |||
715 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
716 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
717 | } else { |
||
718 | Log::warning("Applicant $applicant->id attempted to update skill declaration with invalid id: $id"); |
||
719 | } |
||
720 | } |
||
721 | } |
||
722 | } |
||
723 | |||
724 | // Redirect to correct page. |
||
725 | switch ($request->input('submit')) { |
||
726 | case 'save_and_quit': |
||
727 | return redirect()->route('applications.index'); |
||
728 | break; |
||
729 | case 'save_and_continue': |
||
730 | case 'next': |
||
731 | return redirect()->route('job.application.edit.5', $jobPoster); |
||
732 | break; |
||
733 | case 'previous': |
||
734 | return redirect()->route('job.application.edit.3', $jobPoster); |
||
735 | break; |
||
736 | default: |
||
737 | return redirect()->back()->withInput(); |
||
738 | } |
||
739 | } |
||
740 | |||
741 | /** |
||
742 | * Submit the Application for the specified job. |
||
743 | * |
||
744 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
745 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
746 | * @return \Illuminate\Http\Response |
||
747 | */ |
||
748 | public function submit(Request $request, JobPoster $jobPoster) |
||
799 | } |
||
800 | } |
||
801 | } |
||
802 |