| Total Complexity | 70 |
| Total Lines | 733 |
| 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 |
||
| 28 | class ApplicationByJobController extends Controller |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * Display a listing of the resource. |
||
| 32 | * |
||
| 33 | * @return \Illuminate\Http\Response |
||
| 34 | */ |
||
| 35 | public function index() |
||
| 37 | // |
||
| 38 | } |
||
| 39 | |||
| 40 | protected function getApplicationFromJob(JobPoster $jobPoster) { |
||
| 41 | $application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
||
| 42 | ->where('job_poster_id', $jobPoster->id)->first(); |
||
| 43 | if ($application == null) { |
||
| 44 | $application = new JobApplication(); |
||
| 45 | $application->job_poster_id = $jobPoster->id; |
||
| 46 | $application->applicant_id = Auth::user()->applicant->id; |
||
| 47 | $application->application_status_id = ApplicationStatus::where('name', 'draft')->firstOrFail()->id; |
||
| 48 | $application->save(); |
||
| 49 | } |
||
| 50 | return $application; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Show the form for editing Application basics for the specified job. |
||
| 55 | * |
||
| 56 | * @param \App\Models\JobPoster $jobPoster |
||
| 57 | * @return \Illuminate\Http\Response |
||
| 58 | */ |
||
| 59 | public function edit_basics(JobPoster $jobPoster) |
||
| 60 | { |
||
| 61 | |||
| 62 | $applicant = Auth::user()->applicant; |
||
| 63 | |||
| 64 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 65 | |||
| 66 | //Ensure user has permissions to view and update application |
||
| 67 | $this->authorize('view', $application); |
||
| 68 | $this->authorize('update', $application); |
||
| 69 | |||
| 70 | return view('applicant/application_post_01', [ |
||
|
1 ignored issue
–
show
|
|||
| 71 | |||
| 72 | /* Application Template Data */ |
||
| 73 | "application_step" => 1, |
||
| 74 | "application_template" => Lang::get("applicant/application_template"), |
||
| 75 | "language_options" => PreferredLanguage::all(), |
||
| 76 | "citizenship_options" => CitizenshipDeclaration::all(), |
||
| 77 | "veteran_options" => VeteranStatus::all(), |
||
| 78 | "preferred_language_template" => Lang::get('common/preferred_language'), |
||
| 79 | "citizenship_declaration_template" => Lang::get('common/citizenship_declaration'), |
||
| 80 | "veteran_status_template" => Lang::get('common/veteran_status'), |
||
| 81 | |||
| 82 | /* Job Data */ |
||
| 83 | "job" => $jobPoster, |
||
| 84 | |||
| 85 | /* Applicant Data */ |
||
| 86 | "applicant" => $applicant, |
||
| 87 | "job_application" => $application, |
||
| 88 | |||
| 89 | /* Submission */ |
||
| 90 | "form_submit_action" => route('job.application.update.1', $jobPoster) |
||
| 91 | |||
| 92 | ]); |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Show the form for editing Application Experience for the specified job. |
||
| 98 | * |
||
| 99 | * @param \App\Models\JobPoster $jobPoster |
||
| 100 | * @return \Illuminate\Http\Response |
||
| 101 | */ |
||
| 102 | public function edit_experience(JobPoster $jobPoster) |
||
| 103 | { |
||
| 104 | |||
| 105 | $applicant = Auth::user()->applicant; |
||
| 106 | |||
| 107 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 108 | |||
| 109 | //Ensure user has permissions to view and update application |
||
| 110 | $this->authorize('view', $application); |
||
| 111 | $this->authorize('update', $application); |
||
| 112 | |||
| 113 | return view('applicant/application_post_02', [ |
||
|
1 ignored issue
–
show
|
|||
| 114 | |||
| 115 | /* Application Template Data */ |
||
| 116 | "application_step" => 2, |
||
| 117 | "application_template" => Lang::get("applicant/application_template"), |
||
| 118 | |||
| 119 | /* Job Data */ |
||
| 120 | "job" => $jobPoster, |
||
| 121 | |||
| 122 | /* Applicant Data */ |
||
| 123 | "applicant" => $applicant, |
||
| 124 | "job_application" => $application, |
||
| 125 | |||
| 126 | /* Submission */ |
||
| 127 | "form_submit_action" => route('job.application.update.2', $jobPoster) |
||
| 128 | |||
| 129 | ]); |
||
| 130 | |||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Show the form for editing Application Essential Skills for the specified job. |
||
| 135 | * |
||
| 136 | * @param \App\Models\JobPoster $jobPoster |
||
| 137 | * @return \Illuminate\Http\Response |
||
| 138 | */ |
||
| 139 | public function edit_essential_skills(JobPoster $jobPoster) |
||
| 140 | { |
||
| 141 | |||
| 142 | $applicant = Auth::user()->applicant; |
||
| 143 | |||
| 144 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 145 | |||
| 146 | //Ensure user has permissions to view and update application |
||
| 147 | $this->authorize('view', $application); |
||
| 148 | $this->authorize('update', $application); |
||
| 149 | |||
| 150 | $criteria = [ |
||
| 151 | 'essential' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 152 | return $value->criteria_type->name == 'essential'; |
||
| 153 | }), |
||
| 154 | 'asset' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 155 | return $value->criteria_type->name == 'asset'; |
||
| 156 | }), |
||
| 157 | ]; |
||
| 158 | |||
| 159 | return view('applicant/application_post_03', [ |
||
|
1 ignored issue
–
show
|
|||
| 160 | |||
| 161 | /* Application Template Data */ |
||
| 162 | "application_step" => 3, |
||
| 163 | "application_template" => Lang::get("applicant/application_template"), |
||
| 164 | |||
| 165 | /* Job Data */ |
||
| 166 | "job" => $jobPoster, |
||
| 167 | |||
| 168 | /* Skills Data */ |
||
| 169 | "skills" => Skill::all(), |
||
| 170 | "skill_template" => Lang::get("common/skills"), |
||
| 171 | "criteria" => $criteria, |
||
| 172 | |||
| 173 | /* Applicant Data */ |
||
| 174 | "applicant" => $applicant, |
||
| 175 | "job_application" => $application, |
||
| 176 | |||
| 177 | /* Submission */ |
||
| 178 | "form_submit_action" => route('job.application.update.3', $jobPoster) |
||
| 179 | |||
| 180 | ]); |
||
| 181 | |||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Show the form for editing Application Asset Skills for the specified job. |
||
| 186 | * |
||
| 187 | * @param \App\Models\JobPoster $jobPoster |
||
| 188 | * @return \Illuminate\Http\Response |
||
| 189 | */ |
||
| 190 | public function edit_asset_skills(JobPoster $jobPoster) |
||
| 191 | { |
||
| 192 | |||
| 193 | $applicant = Auth::user()->applicant; |
||
| 194 | |||
| 195 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 196 | |||
| 197 | //Ensure user has permissions to view and update application |
||
| 198 | $this->authorize('view', $application); |
||
| 199 | $this->authorize('update', $application); |
||
| 200 | |||
| 201 | $criteria = [ |
||
| 202 | 'essential' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 203 | return $value->criteria_type->name == 'essential'; |
||
| 204 | }), |
||
| 205 | 'asset' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 206 | return $value->criteria_type->name == 'asset'; |
||
| 207 | }), |
||
| 208 | ]; |
||
| 209 | |||
| 210 | return view('applicant/application_post_04', [ |
||
|
1 ignored issue
–
show
|
|||
| 211 | |||
| 212 | /* Application Template Data */ |
||
| 213 | "application_step" => 4, |
||
| 214 | "application_template" => Lang::get("applicant/application_template"), |
||
| 215 | |||
| 216 | /* Job Data */ |
||
| 217 | "job" => $jobPoster, |
||
| 218 | |||
| 219 | /* Skills Data */ |
||
| 220 | "skills" => Skill::all(), |
||
| 221 | "skill_template" => Lang::get("common/skills"), |
||
| 222 | "criteria" => $criteria, |
||
| 223 | |||
| 224 | /* Applicant Data */ |
||
| 225 | "applicant" => $applicant, |
||
| 226 | "job_application" => $application, |
||
| 227 | |||
| 228 | /* Submission */ |
||
| 229 | "form_submit_action" => route('job.application.update.4', $jobPoster) |
||
| 230 | |||
| 231 | ]); |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Show the Application Preview for the application for the specified job. |
||
| 236 | * |
||
| 237 | * @param \App\Models\JobPoster $jobPoster |
||
| 238 | * @return \Illuminate\Http\Response |
||
| 239 | */ |
||
| 240 | public function preview(JobPoster $jobPoster) { |
||
| 241 | |||
| 242 | $applicant = Auth::user()->applicant; |
||
| 243 | |||
| 244 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 245 | |||
| 246 | //TODO: Right now preview can't have the update gate, because we use the |
||
| 247 | // same view for viewing even after its been submitted. These should |
||
| 248 | // be seperate views, and then Preview can require the update permission. |
||
| 249 | //Ensure user has permissions to view and update application |
||
| 250 | $this->authorize('view', $application); |
||
| 251 | //$this->authorize('update', $application); |
||
| 252 | |||
| 253 | $criteria = [ |
||
| 254 | 'essential' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 255 | return $value->criteria_type->name == 'essential'; |
||
| 256 | }), |
||
| 257 | 'asset' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 258 | return $value->criteria_type->name == 'asset'; |
||
| 259 | }), |
||
| 260 | ]; |
||
| 261 | |||
| 262 | return view('applicant/application_post_05', [ |
||
|
1 ignored issue
–
show
|
|||
| 263 | |||
| 264 | /* Application Template Data */ |
||
| 265 | "application_step" => 5, |
||
| 266 | "application_template" => Lang::get("applicant/application_template"), |
||
| 267 | "preferred_language_template" => Lang::get('common/preferred_language'), |
||
| 268 | "citizenship_declaration_template" => Lang::get('common/citizenship_declaration'), |
||
| 269 | "veteran_status_template" => Lang::get('common/veteran_status'), |
||
| 270 | |||
| 271 | /* Job Data */ |
||
| 272 | "job" => $jobPoster, |
||
| 273 | |||
| 274 | /* Skills Data */ |
||
| 275 | "skills" => Skill::all(), |
||
| 276 | "skill_template" => Lang::get("common/skills"), |
||
| 277 | "criteria" => $criteria, |
||
| 278 | |||
| 279 | /* Applicant Data */ |
||
| 280 | "applicant" => $applicant, |
||
| 281 | "job_application" => $application, |
||
| 282 | |||
| 283 | /* Submission */ |
||
| 284 | "form_submit_action" => route('job.application.submit', $jobPoster) |
||
| 285 | |||
| 286 | ]); |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Show the application submission information. |
||
| 291 | * |
||
| 292 | * @param \App\Models\JobPoster $jobPoster |
||
| 293 | * @return \Illuminate\Http\Response |
||
| 294 | */ |
||
| 295 | public function complete(JobPoster $jobPoster) { |
||
| 296 | |||
| 297 | /* Include Applicant Data */ |
||
| 298 | |||
| 299 | $applicant = Auth::user()->applicant; |
||
| 300 | |||
| 301 | /* Include Application Data */ |
||
| 302 | |||
| 303 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 304 | |||
| 305 | //Ensure user has permissions to view application |
||
| 306 | $this->authorize('view', $application); |
||
| 307 | |||
| 308 | /* Return the Completion View */ |
||
| 309 | |||
| 310 | return view('applicant/application_post_complete', [ |
||
|
1 ignored issue
–
show
|
|||
| 311 | |||
| 312 | /* Application Template Data */ |
||
| 313 | "application_template" => Lang::get("applicant/application_template"), |
||
| 314 | |||
| 315 | /* Job Data */ |
||
| 316 | "job" => $jobPoster, |
||
| 317 | |||
| 318 | /* Applicant Data */ |
||
| 319 | "applicant" => $applicant, |
||
| 320 | "job_application" => $application |
||
| 321 | |||
| 322 | ]); |
||
| 323 | |||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Update the Application Basics in storage for the specified job. |
||
| 328 | * |
||
| 329 | * @param \Illuminate\Http\Request $request |
||
| 330 | * @param \App\Models\JobPoster $jobPoster |
||
| 331 | * @return \Illuminate\Http\Response |
||
| 332 | */ |
||
| 333 | public function update_basics(Request $request, JobPoster $jobPoster) |
||
| 334 | { |
||
| 335 | $applicant = Auth::user()->applicant; |
||
| 336 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 337 | |||
| 338 | //Ensure user has permissions to update this application |
||
| 339 | $this->authorize('update', $application); |
||
| 340 | |||
| 341 | $application->fill([ |
||
| 342 | 'citizenship_declaration_id' => $request->input('citizenship_declaration_id'), |
||
| 343 | 'veteran_status_id' => $request->input('veteran_status_id'), |
||
| 344 | 'preferred_language_id' => $request->input('preferred_language_id'), |
||
| 345 | ]); |
||
| 346 | $application->save(); |
||
| 347 | |||
| 348 | $questions = $jobPoster->job_poster_questions; |
||
| 349 | $questionsInput = $request->input('questions'); |
||
| 350 | foreach($questions as $question) { |
||
| 351 | $answer = null; |
||
| 352 | if (isset($questionsInput[$question->id])) { |
||
| 353 | $answer = $questionsInput[$question->id]; |
||
| 354 | } |
||
| 355 | $answerObj = $application->job_application_answers |
||
| 356 | ->firstWhere('job_poster_question_id', $question->id); |
||
| 357 | if ($answerObj == null) { |
||
| 358 | $answerObj = new JobApplicationAnswer(); |
||
| 359 | $answerObj->job_poster_question_id = $question->id; |
||
| 360 | $answerObj->job_application_id = $application->id; |
||
| 361 | } |
||
| 362 | $answerObj->answer = $answer; |
||
| 363 | $answerObj->save(); |
||
| 364 | } |
||
| 365 | |||
| 366 | //Redirect to correct page |
||
| 367 | switch($request->input('submit')) { |
||
| 368 | case 'save_and_quit': |
||
| 369 | case 'previous': |
||
| 370 | return redirect()->route('applications.index'); |
||
|
1 ignored issue
–
show
|
|||
| 371 | break; |
||
| 372 | case 'save_and_continue': |
||
| 373 | case 'next': |
||
| 374 | return redirect()->route('job.application.edit.2', $jobPoster); |
||
|
1 ignored issue
–
show
|
|||
| 375 | break; |
||
| 376 | default: |
||
| 377 | return redirect()->back()->withInput(); |
||
|
1 ignored issue
–
show
|
|||
| 378 | break; |
||
| 379 | } |
||
| 380 | } |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Update the Application Basics in storage for the specified job. |
||
| 384 | * |
||
| 385 | * @param \Illuminate\Http\Request $request |
||
| 386 | * @param \App\Models\JobPoster $jobPoster |
||
| 387 | * @return \Illuminate\Http\Response |
||
| 388 | */ |
||
| 389 | public function update_experience(Request $request, JobPoster $jobPoster) |
||
| 390 | { |
||
| 391 | $applicant = Auth::user()->applicant; |
||
| 392 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 393 | |||
| 394 | //Ensure user has permissions to update this application |
||
| 395 | $this->authorize('update', $application); |
||
| 396 | |||
| 397 | $degrees = $request->input('degrees'); |
||
| 398 | |||
| 399 | //Save new degrees |
||
| 400 | if (isset($degrees['new'])) { |
||
| 401 | foreach($degrees['new'] as $degreeInput) { |
||
| 402 | $degree = new Degree(); |
||
| 403 | $degree->applicant_id = $applicant->id; |
||
| 404 | $degree->fill([ |
||
| 405 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
| 406 | 'area_of_study' => $degreeInput['area_of_study'], |
||
| 407 | 'institution' => $degreeInput['institution'], |
||
| 408 | 'thesis' => $degreeInput['thesis'], |
||
| 409 | 'start_date' => $degreeInput['start_date'], |
||
| 410 | 'end_date' => $degreeInput['end_date'] |
||
| 411 | ]); |
||
| 412 | $degree->save(); |
||
| 413 | } |
||
| 414 | } |
||
| 415 | |||
| 416 | //Update old degrees |
||
| 417 | if (isset($degrees['old'])) { |
||
| 418 | foreach($degrees['old'] as $id=>$degreeInput) { |
||
| 419 | //Ensure this degree belongs to this applicant |
||
| 420 | $degree = $applicant->degrees->firstWhere('id', $id); |
||
| 421 | if ($degree != null) { |
||
| 422 | $degree->fill([ |
||
| 423 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
| 424 | 'area_of_study' => $degreeInput['area_of_study'], |
||
| 425 | 'institution' => $degreeInput['institution'], |
||
| 426 | 'thesis' => $degreeInput['thesis'], |
||
| 427 | 'start_date' => $degreeInput['start_date'], |
||
| 428 | 'end_date' => $degreeInput['end_date'] |
||
| 429 | ]); |
||
| 430 | $degree->save(); |
||
| 431 | } else { |
||
| 432 | Log::warning('Applicant '.$applicant->id.' attempted to update degree with invalid id '.$id); |
||
| 433 | } |
||
| 434 | } |
||
| 435 | } |
||
| 436 | |||
| 437 | $courses = $request->input('courses'); |
||
| 438 | |||
| 439 | //Save new courses |
||
| 440 | if (isset($courses['new'])) { |
||
| 441 | foreach($courses['new'] as $courseInput) { |
||
| 442 | $course = new Course(); |
||
| 443 | $course->applicant_id = $applicant->id; |
||
| 444 | $course->fill([ |
||
| 445 | 'name' => $courseInput['name'], |
||
| 446 | 'institution' => $courseInput['institution'], |
||
| 447 | 'course_status_id' => $courseInput['course_status_id'], |
||
| 448 | 'start_date' => $courseInput['start_date'], |
||
| 449 | 'end_date' => $courseInput['end_date'] |
||
| 450 | ]); |
||
| 451 | $course->save(); |
||
| 452 | } |
||
| 453 | } |
||
| 454 | |||
| 455 | //Update old courses |
||
| 456 | if (isset($courses['old'])) { |
||
| 457 | foreach($courses['old'] as $id=>$courseInput) { |
||
| 458 | //Ensure this course belongs to this applicant |
||
| 459 | $course = $applicant->courses->firstWhere('id', $id); |
||
| 460 | if ($course != null) { |
||
| 461 | $course->fill([ |
||
| 462 | 'name' => $courseInput['name'], |
||
| 463 | 'institution' => $courseInput['institution'], |
||
| 464 | 'course_status_id' => $courseInput['course_status_id'], |
||
| 465 | 'start_date' => $courseInput['start_date'], |
||
| 466 | 'end_date' => $courseInput['end_date'] |
||
| 467 | ]); |
||
| 468 | $course->save(); |
||
| 469 | } else { |
||
| 470 | Log::warning('Applicant '.$applicant->id.' attempted to update course with invalid id '.$id); |
||
| 471 | } |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | $work_experiences = $request->input('work_experiences'); |
||
| 476 | |||
| 477 | //Save new work_experiences |
||
| 478 | if (isset($work_experiences['new'])) { |
||
| 479 | foreach($work_experiences['new'] as $workExperienceInput) { |
||
| 480 | $workExperience = new WorkExperience(); |
||
| 481 | $workExperience->applicant_id = $applicant->id; |
||
| 482 | $workExperience->fill([ |
||
| 483 | 'role' => $workExperienceInput['role'], |
||
| 484 | 'company' => $workExperienceInput['company'], |
||
| 485 | 'description' => $workExperienceInput['description'], |
||
| 486 | 'start_date' => $workExperienceInput['start_date'], |
||
| 487 | 'end_date' => $workExperienceInput['end_date'] |
||
| 488 | ]); |
||
| 489 | $workExperience->save(); |
||
| 490 | } |
||
| 491 | } |
||
| 492 | |||
| 493 | //Update old work_experiences |
||
| 494 | if (isset($work_experiences['old'])) { |
||
| 495 | foreach($work_experiences['old'] as $id=>$workExperienceInput) { |
||
| 496 | //Ensure this work_experience belongs to this applicant |
||
| 497 | $workExperience = $applicant->work_experiences->firstWhere('id', $id); |
||
| 498 | if ($workExperience != null) { |
||
| 499 | $workExperience->fill([ |
||
| 500 | 'role' => $workExperienceInput['role'], |
||
| 501 | 'company' => $workExperienceInput['company'], |
||
| 502 | 'description' => $workExperienceInput['description'], |
||
| 503 | 'start_date' => $workExperienceInput['start_date'], |
||
| 504 | 'end_date' => $workExperienceInput['end_date'] |
||
| 505 | ]); |
||
| 506 | $workExperience->save(); |
||
| 507 | } else { |
||
| 508 | Log::warning('Applicant '.$applicant->id.' attempted to update work_experience with invalid id '.$id); |
||
| 509 | } |
||
| 510 | } |
||
| 511 | } |
||
| 512 | |||
| 513 | //Redirect to correct page |
||
| 514 | switch($request->input('submit')) { |
||
| 515 | case 'save_and_quit': |
||
| 516 | return redirect()->route('applications.index'); |
||
|
1 ignored issue
–
show
|
|||
| 517 | break; |
||
| 518 | case 'save_and_continue': |
||
| 519 | case 'next': |
||
| 520 | return redirect()->route('job.application.edit.3', $jobPoster); |
||
|
1 ignored issue
–
show
|
|||
| 521 | break; |
||
| 522 | case 'previous': |
||
| 523 | return redirect()->route('job.application.edit.1', $jobPoster); |
||
|
1 ignored issue
–
show
|
|||
| 524 | break; |
||
| 525 | default: |
||
| 526 | return redirect()->back()->withInput(); |
||
|
1 ignored issue
–
show
|
|||
| 527 | break; |
||
| 528 | } |
||
| 529 | } |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Update the Application Essential Skills in storage for the specified job. |
||
| 533 | * |
||
| 534 | * @param \Illuminate\Http\Request $request |
||
| 535 | * @param \App\Models\JobPoster $jobPoster |
||
| 536 | * @return \Illuminate\Http\Response |
||
| 537 | */ |
||
| 538 | public function update_essential_skills(Request $request, JobPoster $jobPoster) |
||
| 539 | { |
||
| 540 | $applicant = Auth::user()->applicant; |
||
| 541 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 542 | |||
| 543 | //Ensure user has permissions to update this application |
||
| 544 | $this->authorize('update', $application); |
||
| 545 | |||
| 546 | $skillDeclarations = $request->input('skill_declarations'); |
||
| 547 | $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
||
| 548 | |||
| 549 | //Save new skill declarartions |
||
| 550 | if (isset($skillDeclarations['new'])) { |
||
| 551 | foreach($skillDeclarations['new'] as $skillType => $typeInput) { |
||
| 552 | foreach($typeInput as $criterion_id=>$skillDeclarationInput) { |
||
| 553 | $skillDeclaration = new SkillDeclaration(); |
||
| 554 | $skillDeclaration->applicant_id = $applicant->id; |
||
| 555 | $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id; |
||
| 556 | $skillDeclaration->skill_status_id = $claimedStatusId; |
||
| 557 | $skillDeclaration->fill([ |
||
| 558 | 'description' => $skillDeclarationInput['description'], |
||
| 559 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 560 | ]); |
||
| 561 | $skillDeclaration->save(); |
||
| 562 | |||
| 563 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 564 | $skillDeclaration->references()->sync($referenceIds); |
||
| 565 | |||
| 566 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 567 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 568 | } |
||
| 569 | } |
||
| 570 | } |
||
| 571 | |||
| 572 | //Update old declarations |
||
| 573 | if (isset($skillDeclarations['old'])) { |
||
| 574 | foreach($skillDeclarations['old'] as $skillType => $typeInput) { |
||
| 575 | foreach($typeInput as $id=>$skillDeclarationInput) { |
||
| 576 | //Ensure this declaration belongs to this applicant |
||
| 577 | $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
||
| 578 | if ($skillDeclaration != null) { |
||
| 579 | //skill_id and skill_status cannot be changed |
||
| 580 | $skillDeclaration->fill([ |
||
| 581 | 'description' => $skillDeclarationInput['description'], |
||
| 582 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 583 | ]); |
||
| 584 | $skillDeclaration->save(); |
||
| 585 | |||
| 586 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 587 | $skillDeclaration->references()->sync($referenceIds); |
||
| 588 | |||
| 589 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 590 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 591 | } else { |
||
| 592 | Log::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id); |
||
| 593 | } |
||
| 594 | } |
||
| 595 | } |
||
| 596 | } |
||
| 597 | |||
| 598 | //Redirect to correct page |
||
| 599 | switch($request->input('submit')) { |
||
| 600 | case 'save_and_quit': |
||
| 601 | return redirect()->route('applications.index'); |
||
|
1 ignored issue
–
show
|
|||
| 602 | break; |
||
| 603 | case 'save_and_continue': |
||
| 604 | case 'next': |
||
| 605 | return redirect()->route('job.application.edit.4', $jobPoster); |
||
|
1 ignored issue
–
show
|
|||
| 606 | break; |
||
| 607 | case 'previous': |
||
| 608 | return redirect()->route('job.application.edit.2', $jobPoster); |
||
|
1 ignored issue
–
show
|
|||
| 609 | break; |
||
| 610 | default: |
||
| 611 | return redirect()->back()->withInput(); |
||
|
1 ignored issue
–
show
|
|||
| 612 | break; |
||
| 613 | } |
||
| 614 | } |
||
| 615 | |||
| 616 | /** |
||
| 617 | * Update the Application Asset Skills in storage for the specified job. |
||
| 618 | * |
||
| 619 | * @param \Illuminate\Http\Request $request |
||
| 620 | * @param \App\Models\JobPoster $jobPoster |
||
| 621 | * @return \Illuminate\Http\Response |
||
| 622 | */ |
||
| 623 | public function update_asset_skills(Request $request, JobPoster $jobPoster) |
||
| 698 | } |
||
| 699 | } |
||
| 700 | |||
| 701 | /** |
||
| 702 | * Submit the Application for the specified job. |
||
| 703 | * |
||
| 704 | * @param \Illuminate\Http\Request $request |
||
| 705 | * @param \App\Models\JobPoster $jobPoster |
||
| 706 | * @return \Illuminate\Http\Response |
||
| 707 | */ |
||
| 708 | public function submit(Request $request, JobPoster $jobPoster) |
||
| 761 | } |
||
| 762 | } |
||
| 763 | } |
||
| 764 |