1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Lang; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Barryvdh\Debugbar\Facade as Debugbar; |
8
|
|
|
use App\Models\Skill; |
9
|
|
|
use App\Models\Lookup\SkillStatus; |
10
|
|
|
use App\Models\SkillDeclaration; |
11
|
|
|
use App\Models\Applicant; |
12
|
|
|
use App\Http\Controllers\Controller; |
13
|
|
|
|
14
|
|
|
class SkillsController extends Controller |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Display the Skills page associated with the applicant. |
19
|
|
|
* |
20
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
21
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
22
|
|
|
*/ |
23
|
|
|
public function show(Applicant $applicant) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
// |
26
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Show the form for editing the applicant's skills |
31
|
|
|
* |
32
|
|
|
* @param Request $request |
|
|
|
|
33
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
34
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function edit(Request $request, Applicant $applicant) |
37
|
|
|
{ |
38
|
|
|
$skills = Skill::all(); |
39
|
|
|
return view('applicant/profile_03_skills', [ |
|
|
|
|
40
|
|
|
'applicant' => $applicant, |
41
|
|
|
'profile' => Lang::get('applicant/profile_skills'), |
42
|
|
|
'form_submit_action' => route('profile.skills.update', $applicant), |
|
|
|
|
43
|
|
|
'skills' => $skills |
44
|
|
|
]); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Update the applicant's profile in storage. |
49
|
|
|
* |
50
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
51
|
|
|
* @param \App\Models\Applicant $applicant |
|
|
|
|
52
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
53
|
|
|
*/ |
54
|
|
|
public function update(Request $request, Applicant $applicant) |
55
|
|
|
{ |
56
|
|
|
|
57
|
|
|
$input = $request->input(); |
58
|
|
|
|
59
|
|
|
Debugbar::info($input); |
60
|
|
|
|
61
|
|
|
$skillDeclarations = $input['skill_declarations']; |
62
|
|
|
$claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
63
|
|
|
|
64
|
|
|
//Delete old skill declarations that weren't resubmitted |
65
|
|
|
//Note: this must be done before adding new ones, so we don't delete |
66
|
|
|
// them right after adding them |
67
|
|
|
foreach($applicant->skill_declarations as $oldDeclaration) { |
|
|
|
|
68
|
|
|
//Check if none were resubmitted, or if this specific one wasn't |
69
|
|
|
$type = $oldDeclaration->skill->skill_type->name; |
70
|
|
|
if (!isset($skillDeclarations['old']) || |
71
|
|
|
!isset($skillDeclarations['old'][$type]) || |
|
|
|
|
72
|
|
|
!isset($skillDeclarations['old'][$type][$oldDeclaration->id])) { |
|
|
|
|
73
|
|
|
$oldDeclaration->delete(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
//Save new skill declarartions |
78
|
|
|
if (isset($skillDeclarations['new'])) { |
79
|
|
|
foreach($skillDeclarations['new'] as $skillType => $typeInput) { |
|
|
|
|
80
|
|
|
foreach($typeInput as $skillDeclarationInput) { |
|
|
|
|
81
|
|
|
$skillDeclaration = new SkillDeclaration(); |
82
|
|
|
$skillDeclaration->applicant_id = $applicant->id; |
83
|
|
|
$skillDeclaration->skill_id = $skillDeclarationInput['skill_id']; |
84
|
|
|
$skillDeclaration->skill_status_id = $claimedStatusId; |
85
|
|
|
$skillDeclaration->fill([ |
|
|
|
|
86
|
|
|
'description' => $skillDeclarationInput['description'], |
87
|
|
|
'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
88
|
|
|
]); |
|
|
|
|
89
|
|
|
$skillDeclaration->save(); |
90
|
|
|
|
91
|
|
|
$referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
92
|
|
|
$skillDeclaration->references()->sync($referenceIds); |
93
|
|
|
|
94
|
|
|
$sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
95
|
|
|
$skillDeclaration->work_samples()->sync($sampleIds); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
//Update old declarations |
101
|
|
|
if (isset($skillDeclarations['old'])) { |
102
|
|
|
foreach($skillDeclarations['old'] as $skillType => $typeInput) { |
|
|
|
|
103
|
|
|
foreach($typeInput as $id=>$skillDeclarationInput) { |
|
|
|
|
104
|
|
|
//Ensure this declaration belongs to this applicant |
105
|
|
|
$skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
106
|
|
|
if ($skillDeclaration != null) { |
107
|
|
|
//skill_id and skill_status cannot be changed |
108
|
|
|
$skillDeclaration->fill([ |
|
|
|
|
109
|
|
|
'description' => $skillDeclarationInput['description'], |
110
|
|
|
'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
111
|
|
|
]); |
|
|
|
|
112
|
|
|
$skillDeclaration->save(); |
113
|
|
|
|
114
|
|
|
$referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
115
|
|
|
$skillDeclaration->references()->sync($referenceIds); |
116
|
|
|
|
117
|
|
|
$sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
118
|
|
|
$skillDeclaration->work_samples()->sync($sampleIds); |
119
|
|
|
} else { |
120
|
|
|
Debugbar::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
return redirect( route('profile.skills.edit', $applicant) ); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Delete the particular skill declaration in storage. |
132
|
|
|
* |
133
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
134
|
|
|
* @param \App\Models\SkillDeclaration $skillDeclaration |
|
|
|
|
135
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
136
|
|
|
*/ |
137
|
|
|
public function destroy(Request $request, SkillDeclaration $skillDeclaration) |
138
|
|
|
{ |
139
|
|
|
$skillDeclaration->delete(); |
140
|
|
|
debugbar()->info('deleted skill declaration '.$skillDeclaration->id); |
141
|
|
|
|
142
|
|
|
if($request->ajax()) { |
|
|
|
|
143
|
|
|
return 'Skill deleted'; |
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return redirect()->back(); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
} |
150
|
|
|
|