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