Total Complexity | 8 |
Total Lines | 127 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
17 | class SkillsController extends Controller |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Show the form for editing the logged-in applicant's skills |
||
22 | * |
||
23 | * @param Request $request |
||
1 ignored issue
–
show
|
|||
24 | * @return \Illuminate\Http\RedirectResponse |
||
25 | */ |
||
26 | public function editAuthenticated(Request $request): \Illuminate\Http\RedirectResponse |
||
27 | { |
||
28 | $applicant = $request->user()->applicant; |
||
29 | return redirect(route('profile.skills.edit', $applicant)); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Show the form for editing the applicant's skills |
||
34 | * |
||
35 | * @param Request $request |
||
1 ignored issue
–
show
|
|||
36 | * @param \App\Models\Applicant $applicant |
||
1 ignored issue
–
show
|
|||
37 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
||
38 | */ |
||
39 | public function edit(Request $request, Applicant $applicant) |
||
40 | { |
||
41 | $skills = Skill::all(); |
||
42 | |||
43 | return view('applicant/profile_03_skills', [ |
||
44 | 'applicant' => $applicant, |
||
45 | 'profile' => Lang::get('applicant/profile_skills'), |
||
46 | 'skills' => $skills |
||
47 | ]); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Create the particular skill declaration in storage. |
||
52 | * |
||
53 | * @param \Illuminate\Http\Request $request |
||
2 ignored issues
–
show
|
|||
54 | * @return \Illuminate\Http\Response |
||
55 | */ |
||
56 | public function create(Request $request) |
||
57 | { |
||
58 | $this->authorize('create', SkillDeclaration::class); |
||
59 | |||
60 | $user = $request->user(); |
||
61 | $applicant = $user->applicant; |
||
62 | |||
63 | //Get the default claim status id |
||
64 | $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
||
65 | |||
66 | // Create a new Skill Declaration |
||
67 | // But don't save, as it hasn't been validated yet |
||
68 | $skillDeclaration = new SkillDeclaration(); |
||
69 | $skillDeclaration->applicant_id = $applicant->id; |
||
70 | $skillDeclaration->skill_id = $request->input('skill_id'); |
||
71 | $skillDeclaration->skill_status_id = $claimedStatusId; |
||
72 | |||
73 | //Update variable fields in skill declaration |
||
74 | return $this->updateSkillDeclaration($request, $skillDeclaration); |
||
1 ignored issue
–
show
|
|||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Update the particular skill declaration in storage. |
||
79 | * |
||
80 | * @param \Illuminate\Http\Request $request |
||
2 ignored issues
–
show
|
|||
81 | * @param \App\Models\SkillDeclaration $skillDeclaration |
||
2 ignored issues
–
show
|
|||
82 | * @return \Illuminate\Http\Response |
||
83 | */ |
||
84 | public function update(Request $request, SkillDeclaration $skillDeclaration) |
||
89 | } |
||
90 | |||
91 | protected function updateSkillDeclaration(Request $request, SkillDeclaration $skillDeclaration) |
||
1 ignored issue
–
show
|
|||
92 | { |
||
93 | //Fill variable values |
||
94 | $skillDeclaration->fill([ |
||
95 | 'description' => $request->input('description'), |
||
96 | 'skill_level_id' => $request->input('skill_level_id'), |
||
97 | ]); |
||
98 | |||
99 | //Validate before saving |
||
100 | $validator = new SkillDeclarationValidator($request->user()->applicant); |
||
101 | $validator->validate($skillDeclaration); |
||
102 | |||
103 | //Save this skill declaration |
||
104 | $skillDeclaration->save(); |
||
105 | |||
106 | //Attach relatives |
||
107 | $referenceIds = $this->getRelativeIds($request->input(), 'references'); |
||
108 | $skillDeclaration->references()->sync($referenceIds); |
||
109 | |||
110 | $sampleIds = $this->getRelativeIds($request->input(), 'samples'); |
||
111 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
112 | |||
113 | // $skillDeclaration->save(); |
||
114 | |||
115 | // If an ajax request, return the new object |
||
116 | if ($request->ajax()) { |
||
117 | $skillDeclaration->load('references'); |
||
118 | $skillDeclaration->load('work_samples'); |
||
119 | $skillDeclaration->load('skill'); |
||
120 | $skillDeclaration->load('skill_status'); |
||
121 | return $skillDeclaration->toJson(); |
||
122 | } |
||
123 | |||
124 | return redirect()->back(); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Delete the particular skill declaration in storage. |
||
129 | * |
||
130 | * @param \Illuminate\Http\Request $request |
||
2 ignored issues
–
show
|
|||
131 | * @param \App\Models\SkillDeclaration $skillDeclaration |
||
2 ignored issues
–
show
|
|||
132 | * @return \Illuminate\Http\Response |
||
133 | */ |
||
134 | public function destroy(Request $request, SkillDeclaration $skillDeclaration) |
||
144 | } |
||
145 | |||
146 | } |
||
147 |