Total Complexity | 13 |
Total Lines | 151 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | class CriteriaController extends Controller |
||
14 | { |
||
15 | /** |
||
16 | * Returns all criteria by JobPoster ID. |
||
17 | * |
||
18 | * @param \App\Models\JobPoster $jobPoster Incoming Job Poster object. |
||
19 | * @return \Illuminate\Http\Response |
||
20 | */ |
||
21 | public function indexByJob(JobPoster $jobPoster) |
||
22 | { |
||
23 | $criteriaByJob = Criteria::where('job_poster_id', $jobPoster->id)->get(); |
||
24 | return CriteriaResource::collection($criteriaByJob); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Update the set of criteria associated with a Job. |
||
29 | * |
||
30 | * @param Request $request |
||
2 ignored issues
–
show
|
|||
31 | * @param JobPoster $jobPoster |
||
1 ignored issue
–
show
|
|||
32 | * @return \Illuminate\Http\Response |
||
33 | */ |
||
34 | public function batchUpdate(Request $request, JobPoster $jobPoster) |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Save a new criteria and create a notification. |
||
72 | * |
||
73 | * @param Criteria $criteria |
||
1 ignored issue
–
show
|
|||
74 | * @return void |
||
1 ignored issue
–
show
|
|||
75 | */ |
||
76 | protected function createCriteria(Criteria $criteria) |
||
77 | { |
||
78 | $criteria->save(); |
||
79 | $notification = $this->makeAssessmentPlanNotification( |
||
80 | 'CREATE', |
||
81 | $criteria |
||
82 | ); |
||
83 | $notification->save(); |
||
84 | |||
85 | return $criteria; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Update an existing Job Criteria and create a notification if necessary. |
||
90 | * |
||
91 | * @param \App\Models\Criteria $oldCriteria Existing Criteria. |
||
92 | * @param mixed[] $newData Updated version of the Criteria. |
||
2 ignored issues
–
show
|
|||
93 | * @return void |
||
94 | */ |
||
95 | protected function updateCriteria(Criteria $oldCriteria, $newData): void |
||
1 ignored issue
–
show
|
|||
96 | { |
||
97 | // We only need to create a notification when the non-descriptive fields change. |
||
98 | if ($oldCriteria->skill_level_id != $newData['skill_level_id'] |
||
99 | || $oldCriteria->skill_id != $newData['skill_id'] |
||
100 | ) { |
||
101 | $notification = $this->makeAssessmentPlanNotification( |
||
102 | 'UPDATE', |
||
103 | $oldCriteria, |
||
104 | $newData['skill_id'], |
||
105 | $newData['skill_level_id'], |
||
106 | $newData['criteria_type_id'] |
||
107 | ); |
||
108 | $notification->save(); |
||
109 | } |
||
110 | // Get just the data that can be changed. |
||
111 | $fillableData = collect($newData)->except(['id', 'job_poster_id'])->toArray(); |
||
112 | $oldCriteria->fill($fillableData); |
||
113 | $oldCriteria->save(); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Delete existing Job Criteria and create a notification. |
||
118 | * |
||
119 | * @param \App\Models\Criteria $criteria Incoming Criteria. |
||
120 | * @return void |
||
121 | */ |
||
122 | protected function deleteCriteria(Criteria $criteria): void |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Create a new AssessmentPlanNotification for a modification to a Criteria |
||
137 | * |
||
138 | * @param string $type Can be CREATE, UPDATE or DELETE. |
||
1 ignored issue
–
show
|
|||
139 | * @param \App\Models\Criteria $criteria The Criteria (the OLD criteria if updating or deleting) |
||
2 ignored issues
–
show
|
|||
140 | * @param integer|null $newSkillId Only used for UPDATE type notifications. |
||
1 ignored issue
–
show
|
|||
141 | * @param integer|null $newSkillLevelId Only used for UPDATE type notifications. |
||
1 ignored issue
–
show
|
|||
142 | * @param integer|null $newCriteriaTypeId Only used for UPDATE type notifications. |
||
143 | * @return \App\Models\AssessmentPlanNotification |
||
144 | */ |
||
145 | protected function makeAssessmentPlanNotification( |
||
166 |