| Total Complexity | 104 |
| Total Lines | 940 |
| Duplicated Lines | 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 |
||
| 31 | class ApplicationByJobController extends Controller |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * Display a listing of the applications for given jobPoster. |
||
| 35 | * |
||
| 36 | * @param \App\Models\JobPoster $jobPoster Incoming JobPoster object. |
||
| 37 | * @return \Illuminate\Http\Response |
||
| 38 | */ |
||
| 39 | public function index(JobPoster $jobPoster) |
||
| 40 | { |
||
| 41 | $jobPoster->loadMissing(['criteria', 'talent_stream_category', 'job_skill_level']); |
||
| 42 | |||
| 43 | $view = 'manager/review_applications'; |
||
| 44 | $jobTitle = $jobPoster->title; |
||
| 45 | $disableCloneJs = false; |
||
| 46 | if ($jobPoster->department_id === config('app.strategic_response_department_id')) { |
||
|
|
|||
| 47 | $view = 'response/screening/index'; |
||
| 48 | // Hacky workaround for Accordion JS firing on the screening page. |
||
| 49 | $disableCloneJs = true; |
||
| 50 | if ($jobPoster->talent_stream_category && $jobPoster->job_skill_level) { |
||
| 51 | $jobTitle = $jobPoster->talent_stream_category->name . ' - ' . $jobPoster->job_skill_level->name; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | $applications = $jobPoster->submitted_applications() |
||
| 55 | ->with([ |
||
| 56 | 'veteran_status', |
||
| 57 | 'citizenship_declaration', |
||
| 58 | 'application_review', |
||
| 59 | 'applicant.user', |
||
| 60 | ]) |
||
| 61 | ->get(); |
||
| 62 | |||
| 63 | $viewData = [ |
||
| 64 | // Localization Strings. |
||
| 65 | 'jobs_l10n' => Lang::get('manager/job_index'), |
||
| 66 | 'response' => Lang::get('response/screening'), |
||
| 67 | // Data. |
||
| 68 | 'job' => new JsonResource($jobPoster), |
||
| 69 | 'response_job_title' => $jobTitle, |
||
| 70 | 'job_id' => $jobPoster->id, |
||
| 71 | 'is_hr_portal' => WhichPortal::isHrPortal(), |
||
| 72 | 'portal' => WhichPortal::isHrPortal() ? 'hr' : 'manager', |
||
| 73 | 'applications' => $applications, |
||
| 74 | 'review_statuses' => ReviewStatus::all(), |
||
| 75 | 'isHrAdvisor' => Auth::user()->isHrAdvisor(), |
||
| 76 | ]; |
||
| 77 | |||
| 78 | if ($disableCloneJs) { |
||
| 79 | $viewData['disable_clone_js'] = true; |
||
| 80 | } |
||
| 81 | |||
| 82 | return view($view, $viewData); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Return the current applicant's application for a given Job Poster. |
||
| 87 | * |
||
| 88 | * @param \App\Models\JobPoster $jobPoster Incoming JobPoster object. |
||
| 89 | * @return mixed|\App\Models\JobApplication |
||
| 90 | */ |
||
| 91 | protected function getApplicationFromJob(JobPoster $jobPoster) |
||
| 92 | { |
||
| 93 | $application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
||
| 94 | ->where('job_poster_id', $jobPoster->id)->first(); |
||
| 95 | if ($application == null) { |
||
| 96 | $application = new JobApplication(); |
||
| 97 | $application->job_poster_id = $jobPoster->id; |
||
| 98 | $application->applicant_id = Auth::user()->applicant->id; |
||
| 99 | $application->application_status_id = ApplicationStatus::where('name', 'draft')->firstOrFail()->id; |
||
| 100 | $application->save(); |
||
| 101 | } |
||
| 102 | return $application; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Show the form for editing Application basics for the specified job. |
||
| 107 | * |
||
| 108 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 109 | * @return \Illuminate\Http\Response |
||
| 110 | */ |
||
| 111 | public function editBasics(JobPoster $jobPoster) |
||
| 112 | { |
||
| 113 | $applicant = Auth::user()->applicant; |
||
| 114 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 115 | |||
| 116 | // Ensure user has permissions to view and update application. |
||
| 117 | $this->authorize('view', $application); |
||
| 118 | $this->authorize('update', $application); |
||
| 119 | |||
| 120 | $viewTemplate = $jobPoster->isInStrategicResponseDepartment() |
||
| 121 | ? 'applicant/strategic_response_application/application_post_01' |
||
| 122 | : 'applicant/application_post_01'; |
||
| 123 | |||
| 124 | $jobTitle = $jobPoster->isInStrategicResponseDepartment() |
||
| 125 | ? "{$jobPoster->talent_stream_category->name} - {$jobPoster->job_skill_level->name}" |
||
| 126 | : $jobPoster->title; |
||
| 127 | $headerTitle = Lang::get('applicant/application_template')['title'] . ": {$jobTitle}"; |
||
| 128 | |||
| 129 | return view( |
||
| 130 | $viewTemplate, |
||
| 131 | [ |
||
| 132 | // Application Template Data. |
||
| 133 | 'application_step' => 1, |
||
| 134 | 'application_template' => Lang::get('applicant/application_template'), |
||
| 135 | 'language_options' => PreferredLanguage::all(), |
||
| 136 | 'citizenship_options' => CitizenshipDeclaration::all(), |
||
| 137 | 'veteran_options' => VeteranStatus::all(), |
||
| 138 | 'security_clearance_options' => SecurityClearance::all(), |
||
| 139 | 'preferred_language_template' => Lang::get('common/preferred_language'), |
||
| 140 | 'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'), |
||
| 141 | 'veteran_status_template' => Lang::get('common/veteran_status'), |
||
| 142 | 'header' => [ |
||
| 143 | 'title' => $headerTitle, |
||
| 144 | ], |
||
| 145 | 'custom_breadcrumbs' => $this->customBreadcrumbs($jobPoster, 1), |
||
| 146 | // Job Data. |
||
| 147 | 'job' => $jobPoster, |
||
| 148 | // Applicant Data. |
||
| 149 | 'applicant' => $applicant, |
||
| 150 | 'job_application' => $application, |
||
| 151 | // Submission. |
||
| 152 | 'form_submit_action' => route('job.application.update.1', $jobPoster), |
||
| 153 | 'gov_email_pattern' => GovernmentEmailRule::PATTERN |
||
| 154 | ] |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Show the form for editing Application Experience for the specified job. |
||
| 160 | * |
||
| 161 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 162 | * @return \Illuminate\Http\Response |
||
| 163 | */ |
||
| 164 | public function editExperience(JobPoster $jobPoster) |
||
| 199 | ] |
||
| 200 | ); |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Show the form for editing Application Essential Skills for the specified job. |
||
| 205 | * |
||
| 206 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 207 | * @return \Illuminate\Http\Response |
||
| 208 | */ |
||
| 209 | public function editEssentialSkills(JobPoster $jobPoster) |
||
| 210 | { |
||
| 211 | $applicant = Auth::user()->applicant; |
||
| 212 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 213 | |||
| 214 | // Ensure user has permissions to view and update application. |
||
| 215 | $this->authorize('view', $application); |
||
| 216 | $this->authorize('update', $application); |
||
| 217 | |||
| 218 | $criteria = $jobPoster->criteria->filter(function ($value, $key) { |
||
| 219 | return $value->criteria_type->name == 'essential' |
||
| 220 | && $value->skill->skill_type->name == 'hard'; |
||
| 221 | }); |
||
| 222 | |||
| 223 | $viewTemplate = $jobPoster->isInStrategicResponseDepartment() |
||
| 224 | ? 'applicant/strategic_response_application/application_post_03' |
||
| 225 | : 'applicant/application_post_03'; |
||
| 226 | |||
| 227 | $jobTitle = $jobPoster->isInStrategicResponseDepartment() |
||
| 228 | ? "{$jobPoster->talent_stream_category->name} - {$jobPoster->job_skill_level->name}" |
||
| 229 | : $jobPoster->title; |
||
| 230 | $headerTitle = Lang::get('applicant/application_template')['title'] . ": {$jobTitle}"; |
||
| 231 | |||
| 232 | return view( |
||
| 233 | $viewTemplate, |
||
| 234 | [ |
||
| 235 | // Application Template Data. |
||
| 236 | 'application_step' => 3, |
||
| 237 | 'application_template' => Lang::get('applicant/application_template'), |
||
| 238 | 'header' => [ |
||
| 239 | 'title' => $headerTitle, |
||
| 240 | ], |
||
| 241 | 'custom_breadcrumbs' => $this->customBreadcrumbs($jobPoster, 3), |
||
| 242 | // Job Data. |
||
| 243 | 'job' => $jobPoster, |
||
| 244 | // Skills Data. |
||
| 245 | 'skills' => Skill::all(), |
||
| 246 | 'skill_template' => Lang::get('common/skills'), |
||
| 247 | 'criteria' => $criteria, |
||
| 248 | // Applicant Data. |
||
| 249 | 'applicant' => $applicant, |
||
| 250 | 'job_application' => $application, |
||
| 251 | // Submission. |
||
| 252 | 'form_submit_action' => route('job.application.update.3', $jobPoster) |
||
| 253 | ] |
||
| 254 | ); |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Show the form for editing Application Asset Skills for the specified job. |
||
| 259 | * |
||
| 260 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 261 | * @return \Illuminate\Http\Response |
||
| 262 | */ |
||
| 263 | public function editAssetSkills(JobPoster $jobPoster) |
||
| 308 | ] |
||
| 309 | ); |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Show the Application Preview for the application for the specified job. |
||
| 314 | * |
||
| 315 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 316 | * @return \Illuminate\Http\Response |
||
| 317 | */ |
||
| 318 | public function preview(JobPoster $jobPoster) |
||
| 319 | { |
||
| 320 | $applicant = Auth::user()->applicant; |
||
| 321 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 322 | |||
| 323 | $this->authorize('view', $application); |
||
| 324 | |||
| 325 | $essential_criteria = $jobPoster->criteria->filter(function ($value, $key) { |
||
| 326 | return $value->criteria_type->name == 'essential' |
||
| 327 | && $value->skill->skill_type->name == 'hard'; |
||
| 328 | }); |
||
| 329 | $asset_criteria = $jobPoster->criteria->filter(function ($value, $key) { |
||
| 330 | return $value->criteria_type->name == 'asset' |
||
| 331 | && $value->skill->skill_type->name == 'hard'; |
||
| 332 | }); |
||
| 333 | |||
| 334 | $skillDeclarations = $application->isDraft() |
||
| 335 | ? $applicant->skill_declarations |
||
| 336 | : $application->skill_declarations; |
||
| 337 | $degrees = $application->isDraft() |
||
| 338 | ? $applicant->degrees |
||
| 339 | : $application->degrees; |
||
| 340 | $courses = $application->isDraft() |
||
| 341 | ? $applicant->courses |
||
| 342 | : $application->courses; |
||
| 343 | $work_experiences = $application->isDraft() |
||
| 344 | ? $applicant->work_experiences |
||
| 345 | : $application->work_experiences; |
||
| 346 | $work_samples = $application->isDraft() |
||
| 347 | ? $applicant->work_samples |
||
| 348 | : $application->work_samples; |
||
| 349 | |||
| 350 | $viewTemplate = $jobPoster->isInStrategicResponseDepartment() |
||
| 351 | ? 'applicant/strategic_response_application/application_post_05' |
||
| 352 | : 'applicant/application_post_05'; |
||
| 353 | $jobTitle = $jobPoster->isInStrategicResponseDepartment() |
||
| 354 | ? "{$jobPoster->talent_stream_category->name} - {$jobPoster->job_skill_level->name}" |
||
| 355 | : $jobPoster->title; |
||
| 356 | $headerTitle = Lang::get('applicant/application_template')['title'] . ": {$jobTitle}"; |
||
| 357 | |||
| 358 | return view( |
||
| 359 | $viewTemplate, |
||
| 360 | [ |
||
| 361 | // Application Template Data. |
||
| 362 | 'application_step' => 5, |
||
| 363 | 'application_template' => Lang::get('applicant/application_template'), |
||
| 364 | 'preferred_language_template' => Lang::get('common/preferred_language'), |
||
| 365 | 'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'), |
||
| 366 | 'veteran_status_template' => Lang::get('common/veteran_status'), |
||
| 367 | 'header' => [ |
||
| 368 | 'title' => $headerTitle, |
||
| 369 | ], |
||
| 370 | 'custom_breadcrumbs' => $this->customBreadcrumbs($jobPoster, 5), |
||
| 371 | // Job Data. |
||
| 372 | 'job' => $jobPoster, |
||
| 373 | // Skills Data. |
||
| 374 | 'skills' => Skill::all(), |
||
| 375 | 'skill_template' => Lang::get('common/skills'), |
||
| 376 | 'essential_criteria' => $essential_criteria, |
||
| 377 | 'asset_criteria' => $asset_criteria, |
||
| 378 | // Applicant Data. |
||
| 379 | 'applicant' => $applicant, |
||
| 380 | 'job_application' => $application, |
||
| 381 | 'skill_declarations' => $skillDeclarations, |
||
| 382 | 'degrees' => $degrees, |
||
| 383 | 'courses' => $courses, |
||
| 384 | 'work_experiences' => $work_experiences, |
||
| 385 | 'work_samples' => $work_samples, |
||
| 386 | 'is_manager_view' => WhichPortal::isManagerPortal(), |
||
| 387 | 'is_draft' => $application->application_status->name == 'draft', |
||
| 388 | ] |
||
| 389 | ); |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Show the Confirm Submit page for the application for the specified job. |
||
| 394 | * |
||
| 395 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 396 | * @return \Illuminate\Http\Response |
||
| 397 | */ |
||
| 398 | public function confirm(JobPoster $jobPoster) |
||
| 399 | { |
||
| 400 | $applicant = Auth::user()->applicant; |
||
| 401 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 402 | |||
| 403 | $this->authorize('update', $application); |
||
| 404 | |||
| 405 | $viewTemplate = $jobPoster->isInStrategicResponseDepartment() |
||
| 406 | ? 'applicant/strategic_response_application/application_post_06' |
||
| 407 | : 'applicant/application_post_06'; |
||
| 408 | $jobTitle = $jobPoster->isInStrategicResponseDepartment() |
||
| 409 | ? "{$jobPoster->talent_stream_category->name} - {$jobPoster->job_skill_level->name}" |
||
| 410 | : $jobPoster->title; |
||
| 411 | $headerTitle = Lang::get('applicant/application_template')['title'] . ": {$jobTitle}"; |
||
| 412 | |||
| 413 | return view( |
||
| 414 | $viewTemplate, |
||
| 415 | [ |
||
| 416 | // Application Template Data. |
||
| 417 | 'application_step' => 6, |
||
| 418 | 'application_template' => Lang::get('applicant/application_template'), |
||
| 419 | 'header' => [ |
||
| 420 | 'title' => $headerTitle, |
||
| 421 | ], |
||
| 422 | 'custom_breadcrumbs' => $this->customBreadcrumbs($jobPoster, 6), |
||
| 423 | // Used by tracker partial. |
||
| 424 | 'job' => $jobPoster, |
||
| 425 | 'job_application' => $application, |
||
| 426 | // Submission. |
||
| 427 | 'form_submit_action' => route('job.application.submit', $jobPoster) |
||
| 428 | ] |
||
| 429 | ); |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Show the application submission information. |
||
| 434 | * |
||
| 435 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 436 | * @return \Illuminate\Http\Response |
||
| 437 | */ |
||
| 438 | public function complete(JobPoster $jobPoster) |
||
| 470 | ] |
||
| 471 | ); |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Update the Application Basics in storage for the specified job. |
||
| 476 | * |
||
| 477 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
| 478 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 479 | * @return \Illuminate\Http\Response |
||
| 480 | */ |
||
| 481 | public function updateBasics(Request $request, JobPoster $jobPoster) |
||
| 482 | { |
||
| 483 | $applicant = Auth::user()->applicant; |
||
| 484 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 485 | |||
| 486 | // Ensure user has permissions to update this application. |
||
| 487 | $this->authorize('update', $application); |
||
| 488 | |||
| 489 | $application->fill([ |
||
| 490 | 'citizenship_declaration_id' => $request->input('citizenship_declaration_id'), |
||
| 491 | 'veteran_status_id' => $request->input('veteran_status_id'), |
||
| 492 | 'preferred_language_id' => $request->input('preferred_language_id'), |
||
| 493 | 'language_requirement_confirmed' => $request->input('language_requirement_confirmed', false), |
||
| 494 | |||
| 495 | // The following fields are exclusive Strategic Talent Response applications. |
||
| 496 | 'director_name' => $request->input('director_name'), |
||
| 497 | 'director_title' => $request->input('director_title'), |
||
| 498 | 'director_email' => $request->input('director_email'), |
||
| 499 | 'reference_name' => $request->input('reference_name'), |
||
| 500 | 'reference_title' => $request->input('reference_title'), |
||
| 501 | 'reference_email' => $request->input('reference_email'), |
||
| 502 | 'gov_email' => $request->input('gov_email'), |
||
| 503 | 'physical_office_willing' => $request->input('physical_office_willing', false), |
||
| 504 | 'security_clearance_id' => $request->input('security_clearance_id'), |
||
| 505 | ]); |
||
| 506 | $application->save(); |
||
| 507 | |||
| 508 | $questions = $jobPoster->job_poster_questions; |
||
| 509 | $questionsInput = $request->input('questions'); |
||
| 510 | foreach ($questions as $question) { |
||
| 511 | $answer = null; |
||
| 512 | if (isset($questionsInput[$question->id])) { |
||
| 513 | $answer = $questionsInput[$question->id]; |
||
| 514 | } |
||
| 515 | $answerObj = $application->job_application_answers |
||
| 516 | ->firstWhere('job_poster_question_id', $question->id); |
||
| 517 | if ($answerObj == null) { |
||
| 518 | $answerObj = new JobApplicationAnswer(); |
||
| 519 | $answerObj->job_poster_question_id = $question->id; |
||
| 520 | $answerObj->job_application_id = $application->id; |
||
| 521 | } |
||
| 522 | $answerObj->answer = $answer; |
||
| 523 | $answerObj->save(); |
||
| 524 | } |
||
| 525 | |||
| 526 | // Redirect to correct page. |
||
| 527 | switch ($request->input('submit')) { |
||
| 528 | case 'save_and_quit': |
||
| 529 | case 'save_and_return': |
||
| 530 | return redirect()->route('applications.index'); |
||
| 531 | break; |
||
| 532 | case 'save_and_continue': |
||
| 533 | case 'next': |
||
| 534 | $next_step = $jobPoster->isInStrategicResponseDepartment() ? 3 : 2; |
||
| 535 | return redirect()->route("job.application.edit.${next_step}", $jobPoster); |
||
| 536 | break; |
||
| 537 | default: |
||
| 538 | return redirect()->back()->withInput(); |
||
| 539 | } |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Update the Application Basics in storage for the specified job. |
||
| 544 | * |
||
| 545 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
| 546 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 547 | * @return \Illuminate\Http\Response |
||
| 548 | */ |
||
| 549 | public function updateExperience(Request $request, JobPoster $jobPoster) |
||
| 550 | { |
||
| 551 | $applicant = Auth::user()->applicant; |
||
| 552 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 553 | |||
| 554 | // Ensure user has permissions to update this application. |
||
| 555 | $this->authorize('update', $application); |
||
| 556 | |||
| 557 | // Record that the user has saved their experience for this application. |
||
| 558 | $application->experience_saved = true; |
||
| 559 | $application->save(); |
||
| 560 | |||
| 561 | $degrees = $request->input('degrees'); |
||
| 562 | |||
| 563 | $request->validate([ |
||
| 564 | 'degrees.new.*.degree_type_id' => 'required', |
||
| 565 | 'degrees.new.*.area_of_study' => 'required', |
||
| 566 | 'degrees.new.*.institution' => 'required', |
||
| 567 | 'degrees.new.*.thesis' => 'nullable', |
||
| 568 | 'degrees.new.*.start_date' => 'required|date', |
||
| 569 | 'degrees.new.*.end_date' => 'required|date', |
||
| 570 | 'degrees.new.*.blockcert_url' => 'nullable|string', |
||
| 571 | ]); |
||
| 572 | |||
| 573 | // Save new degrees. |
||
| 574 | if (isset($degrees['new'])) { |
||
| 575 | foreach ($degrees['new'] as $degreeInput) { |
||
| 576 | $degree = new Degree(); |
||
| 577 | $degree->fill([ |
||
| 578 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
| 579 | 'area_of_study' => $degreeInput['area_of_study'], |
||
| 580 | 'institution' => $degreeInput['institution'], |
||
| 581 | 'thesis' => $degreeInput['thesis'], |
||
| 582 | 'start_date' => $degreeInput['start_date'], |
||
| 583 | 'end_date' => $degreeInput['end_date'], |
||
| 584 | 'blockcert_url' => $degreeInput['blockcert_url'], |
||
| 585 | ]); |
||
| 586 | $applicant->degrees()->save($degree); |
||
| 587 | } |
||
| 588 | } |
||
| 589 | |||
| 590 | // Update old degrees. |
||
| 591 | if (isset($degrees['old'])) { |
||
| 592 | foreach ($degrees['old'] as $id => $degreeInput) { |
||
| 593 | // Ensure this degree belongs to this applicant. |
||
| 594 | $degree = $applicant->degrees->firstWhere('id', $id); |
||
| 595 | if ($degree != null) { |
||
| 596 | $degree->fill([ |
||
| 597 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
| 598 | 'area_of_study' => $degreeInput['area_of_study'], |
||
| 599 | 'institution' => $degreeInput['institution'], |
||
| 600 | 'thesis' => $degreeInput['thesis'], |
||
| 601 | 'start_date' => $degreeInput['start_date'], |
||
| 602 | 'end_date' => $degreeInput['end_date'], |
||
| 603 | 'blockcert_url' => $degreeInput['blockcert_url'], |
||
| 604 | ]); |
||
| 605 | $degree->save(); |
||
| 606 | } else { |
||
| 607 | Log::warning("Applicant $applicant->id attempted to update degree with invalid id: $id"); |
||
| 608 | } |
||
| 609 | } |
||
| 610 | } |
||
| 611 | |||
| 612 | $courses = $request->input('courses'); |
||
| 613 | |||
| 614 | $request->validate([ |
||
| 615 | 'courses.new.*.name' => 'required', |
||
| 616 | 'courses.new.*.institution' => 'required', |
||
| 617 | 'courses.new.*.course_status_id' => 'required', |
||
| 618 | 'courses.new.*.start_date' => 'required|date', |
||
| 619 | 'courses.new.*.end_date' => 'required|date', |
||
| 620 | ]); |
||
| 621 | |||
| 622 | // Save new courses. |
||
| 623 | if (isset($courses['new'])) { |
||
| 624 | foreach ($courses['new'] as $courseInput) { |
||
| 625 | $course = new Course(); |
||
| 626 | $course->fill([ |
||
| 627 | 'name' => $courseInput['name'], |
||
| 628 | 'institution' => $courseInput['institution'], |
||
| 629 | 'course_status_id' => $courseInput['course_status_id'], |
||
| 630 | 'start_date' => $courseInput['start_date'], |
||
| 631 | 'end_date' => $courseInput['end_date'] |
||
| 632 | ]); |
||
| 633 | $applicant->courses()->save($course); |
||
| 634 | } |
||
| 635 | } |
||
| 636 | |||
| 637 | // Update old courses. |
||
| 638 | if (isset($courses['old'])) { |
||
| 639 | foreach ($courses['old'] as $id => $courseInput) { |
||
| 640 | // Ensure this course belongs to this applicant. |
||
| 641 | $course = $applicant->courses->firstWhere('id', $id); |
||
| 642 | if ($course != null) { |
||
| 643 | $course->fill([ |
||
| 644 | 'name' => $courseInput['name'], |
||
| 645 | 'institution' => $courseInput['institution'], |
||
| 646 | 'course_status_id' => $courseInput['course_status_id'], |
||
| 647 | 'start_date' => $courseInput['start_date'], |
||
| 648 | 'end_date' => $courseInput['end_date'] |
||
| 649 | ]); |
||
| 650 | $course->save(); |
||
| 651 | } else { |
||
| 652 | Log::warning("Applicant $applicant->id attempted to update course with invalid id: $id"); |
||
| 653 | } |
||
| 654 | } |
||
| 655 | } |
||
| 656 | |||
| 657 | $work_experiences = $request->input('work_experiences'); |
||
| 658 | |||
| 659 | $request->validate([ |
||
| 660 | 'work_experiences.new.*.role' => 'required', |
||
| 661 | 'work_experiences.new.*.company' => 'required', |
||
| 662 | 'work_experiences.new.*.description' => 'required', |
||
| 663 | 'work_experiences.new.*.start_date' => 'required|date', |
||
| 664 | 'work_experiences.new.*.end_date' => 'required|date', |
||
| 665 | ]); |
||
| 666 | |||
| 667 | // Save new work_experiences. |
||
| 668 | if (isset($work_experiences['new'])) { |
||
| 669 | foreach ($work_experiences['new'] as $workExperienceInput) { |
||
| 670 | $workExperience = new WorkExperience(); |
||
| 671 | $workExperience->fill([ |
||
| 672 | 'role' => $workExperienceInput['role'], |
||
| 673 | 'company' => $workExperienceInput['company'], |
||
| 674 | 'description' => $workExperienceInput['description'], |
||
| 675 | 'start_date' => $workExperienceInput['start_date'], |
||
| 676 | 'end_date' => $workExperienceInput['end_date'] |
||
| 677 | ]); |
||
| 678 | $applicant->work_experiences()->save($workExperience); |
||
| 679 | } |
||
| 680 | } |
||
| 681 | |||
| 682 | // Update old work_experiences. |
||
| 683 | if (isset($work_experiences['old'])) { |
||
| 684 | foreach ($work_experiences['old'] as $id => $workExperienceInput) { |
||
| 685 | // Ensure this work_experience belongs to this applicant. |
||
| 686 | $workExperience = $applicant->work_experiences->firstWhere('id', $id); |
||
| 687 | if ($workExperience != null) { |
||
| 688 | $workExperience->fill([ |
||
| 689 | 'role' => $workExperienceInput['role'], |
||
| 690 | 'company' => $workExperienceInput['company'], |
||
| 691 | 'description' => $workExperienceInput['description'], |
||
| 692 | 'start_date' => $workExperienceInput['start_date'], |
||
| 693 | 'end_date' => $workExperienceInput['end_date'] |
||
| 694 | ]); |
||
| 695 | $workExperience->save(); |
||
| 696 | } else { |
||
| 697 | Log::warning("Applicant $applicant->id attempted to update work_experience with invalid id: $id"); |
||
| 698 | } |
||
| 699 | } |
||
| 700 | } |
||
| 701 | |||
| 702 | // Redirect to correct page. |
||
| 703 | switch ($request->input('submit')) { |
||
| 704 | case 'save_and_quit': |
||
| 705 | return redirect()->route('applications.index'); |
||
| 706 | break; |
||
| 707 | case 'save_and_continue': |
||
| 708 | case 'next': |
||
| 709 | return redirect()->route('job.application.edit.3', $jobPoster); |
||
| 710 | break; |
||
| 711 | case 'save_and_return': |
||
| 712 | return redirect()->route('job.application.edit.1', $jobPoster); |
||
| 713 | break; |
||
| 714 | default: |
||
| 715 | return redirect()->back()->withInput(); |
||
| 716 | } |
||
| 717 | } |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Update the Application Essential Skills in storage for the specified job. |
||
| 721 | * |
||
| 722 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
| 723 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 724 | * @return \Illuminate\Http\Response |
||
| 725 | */ |
||
| 726 | public function updateEssentialSkills(Request $request, JobPoster $jobPoster) |
||
| 727 | { |
||
| 728 | $applicant = Auth::user()->applicant; |
||
| 729 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 730 | |||
| 731 | // Ensure user has permissions to update this application. |
||
| 732 | $this->authorize('update', $application); |
||
| 733 | |||
| 734 | $skillDeclarations = $request->input('skill_declarations'); |
||
| 735 | $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
||
| 736 | |||
| 737 | // Save new skill declarations. |
||
| 738 | if (isset($skillDeclarations['new'])) { |
||
| 739 | foreach ($skillDeclarations['new'] as $skillType => $typeInput) { |
||
| 740 | foreach ($typeInput as $criterion_id => $skillDeclarationInput) { |
||
| 741 | $skillDeclaration = new SkillDeclaration(); |
||
| 742 | $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id; |
||
| 743 | $skillDeclaration->skill_status_id = $claimedStatusId; |
||
| 744 | $skillDeclaration->fill([ |
||
| 745 | 'description' => $skillDeclarationInput['description'], |
||
| 746 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 747 | ]); |
||
| 748 | $applicant->skill_declarations()->save($skillDeclaration); |
||
| 749 | |||
| 750 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 751 | $skillDeclaration->references()->sync($referenceIds); |
||
| 752 | |||
| 753 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 754 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 755 | } |
||
| 756 | } |
||
| 757 | } |
||
| 758 | |||
| 759 | // Update old declarations. |
||
| 760 | if (isset($skillDeclarations['old'])) { |
||
| 761 | foreach ($skillDeclarations['old'] as $skillType => $typeInput) { |
||
| 762 | foreach ($typeInput as $id => $skillDeclarationInput) { |
||
| 763 | // Ensure this declaration belongs to this applicant. |
||
| 764 | $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
||
| 765 | if ($skillDeclaration != null) { |
||
| 766 | // skill_id and skill_status cannot be changed. |
||
| 767 | $skillDeclaration->fill([ |
||
| 768 | 'description' => $skillDeclarationInput['description'], |
||
| 769 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 770 | ]); |
||
| 771 | $skillDeclaration->save(); |
||
| 772 | |||
| 773 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 774 | $skillDeclaration->references()->sync($referenceIds); |
||
| 775 | |||
| 776 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 777 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 778 | } else { |
||
| 779 | Log::warning("Applicant $applicant->id attempted to update skill declaration with invalid id: $id"); |
||
| 780 | } |
||
| 781 | } |
||
| 782 | } |
||
| 783 | } |
||
| 784 | |||
| 785 | // Redirect to correct page. |
||
| 786 | switch ($request->input('submit')) { |
||
| 787 | case 'save_and_quit': |
||
| 788 | return redirect()->route('applications.index'); |
||
| 789 | break; |
||
| 790 | case 'save_and_continue': |
||
| 791 | case 'next': |
||
| 792 | return redirect()->route('job.application.edit.4', $jobPoster); |
||
| 793 | break; |
||
| 794 | case 'save_and_return': |
||
| 795 | return redirect()->route('job.application.edit.2', $jobPoster); |
||
| 796 | break; |
||
| 797 | default: |
||
| 798 | return redirect()->back()->withInput(); |
||
| 799 | } |
||
| 800 | } |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Update the Application Asset Skills in storage for the specified job. |
||
| 804 | * |
||
| 805 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
| 806 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 807 | * @return \Illuminate\Http\Response |
||
| 808 | */ |
||
| 809 | public function updateAssetSkills(Request $request, JobPoster $jobPoster) |
||
| 810 | { |
||
| 811 | $applicant = Auth::user()->applicant; |
||
| 812 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 813 | |||
| 814 | // Ensure user has permissions to update this application. |
||
| 815 | $this->authorize('update', $application); |
||
| 816 | |||
| 817 | $skillDeclarations = $request->input('skill_declarations'); |
||
| 818 | $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
||
| 819 | |||
| 820 | // Save new skill declarations. |
||
| 821 | if (isset($skillDeclarations['new'])) { |
||
| 822 | foreach ($skillDeclarations['new'] as $skillType => $typeInput) { |
||
| 823 | foreach ($typeInput as $criterion_id => $skillDeclarationInput) { |
||
| 824 | $skillDeclaration = new SkillDeclaration(); |
||
| 825 | $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id; |
||
| 826 | $skillDeclaration->skill_status_id = $claimedStatusId; |
||
| 827 | $skillDeclaration->fill([ |
||
| 828 | 'description' => $skillDeclarationInput['description'], |
||
| 829 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 830 | ]); |
||
| 831 | $applicant->skill_declarations()->save($skillDeclaration); |
||
| 832 | |||
| 833 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 834 | $skillDeclaration->references()->sync($referenceIds); |
||
| 835 | |||
| 836 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 837 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 838 | } |
||
| 839 | } |
||
| 840 | } |
||
| 841 | |||
| 842 | // Update old declarations. |
||
| 843 | if (isset($skillDeclarations['old'])) { |
||
| 844 | foreach ($skillDeclarations['old'] as $skillType => $typeInput) { |
||
| 845 | foreach ($typeInput as $id => $skillDeclarationInput) { |
||
| 846 | // Ensure this declaration belongs to this applicant. |
||
| 847 | $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
||
| 848 | if ($skillDeclaration != null) { |
||
| 849 | // skill_id and skill_status cannot be changed. |
||
| 850 | $skillDeclaration->fill([ |
||
| 851 | 'description' => $skillDeclarationInput['description'], |
||
| 852 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 853 | ]); |
||
| 854 | $skillDeclaration->save(); |
||
| 855 | |||
| 856 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 857 | $skillDeclaration->references()->sync($referenceIds); |
||
| 858 | |||
| 859 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 860 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 861 | } else { |
||
| 862 | Log::warning("Applicant $applicant->id attempted to update skill declaration with invalid id: $id"); |
||
| 863 | } |
||
| 864 | } |
||
| 865 | } |
||
| 866 | } |
||
| 867 | |||
| 868 | // Redirect to correct page. |
||
| 869 | switch ($request->input('submit')) { |
||
| 870 | case 'save_and_quit': |
||
| 871 | return redirect()->route('applications.index'); |
||
| 872 | break; |
||
| 873 | case 'save_and_continue': |
||
| 874 | case 'next': |
||
| 875 | return redirect()->route('job.application.edit.5', $jobPoster); |
||
| 876 | break; |
||
| 877 | case 'save_and_return': |
||
| 878 | return redirect()->route('job.application.edit.3', $jobPoster); |
||
| 879 | break; |
||
| 880 | default: |
||
| 881 | return redirect()->back()->withInput(); |
||
| 882 | } |
||
| 883 | } |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Submit the Application for the specified job. |
||
| 887 | * |
||
| 888 | * @param \Illuminate\Http\Request $request Incoming Request object. |
||
| 889 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 890 | * @return \Illuminate\Http\Response |
||
| 891 | */ |
||
| 892 | public function submit(Request $request, JobPoster $jobPoster) |
||
| 953 | } |
||
| 954 | } |
||
| 955 | |||
| 956 | /** |
||
| 957 | * Custom breadcrumbs for application process. |
||
| 958 | * |
||
| 959 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
| 960 | * @param string $application_step Current step in application. |
||
| 961 | * @return array |
||
| 962 | */ |
||
| 963 | public function customBreadcrumbs(JobPoster $jobPoster, string $application_step) |
||
| 974 |