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