Passed
Push — task/all-applications-to-pdf ( cb7375...852a46 )
by Tristan
59:34 queued 50:51
created

AssessmentPlanNotificationController::index()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
ccs 0
cts 9
cp 0
rs 9.6111
c 0
b 0
f 0
cc 5
nc 2
nop 1
crap 30
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\JobPoster;
6
use App\Models\Lookup\AssessmentType;
7
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Response;
10
use App\Models\AssessmentPlanNotification;
11
12
class AssessmentPlanNotificationController extends Controller
13
{
14
    /**
15
     * Display a list of the specified resource. Must specify a job_poster_id,
16
     * either as form data or as url query string.
17
     *
18
     * @param  \Illuminate\Http\Request $request Incoming request.
19
     * @return mixed
20
     */
21
    public function index(Request $request)
22
    {
23
        $notificationsArray = [];
24
        if ($request->has('job_poster_id') && $request->user() != null) {
25
            $jobPosterId = $request->input('job_poster_id');
26
            $notifications = AssessmentPlanNotification::where('job_poster_id', $jobPosterId)->get();
27
            foreach ($notifications as $notification) {
28
                if ($request->user()->can('view', $notification)) {
29
                    $notificationsArray[] = $notification->toArray();
30
                }
31
            }
32
        }
33
        return $notificationsArray;
34
    }
35
36
    /**
37
     * Display the specified resource.
38
     *
39
     * @param  \App\Models\AssessmentPlanNotification $assessmentPlanNotification Incoming object.
40
     * @return mixed
41
     */
42
    public function show(AssessmentPlanNotification $assessmentPlanNotification)
43
    {
44
        $this->authorize('view', $assessmentPlanNotification);
45
        return $assessmentPlanNotification->toArray();
46
    }
47
48
    /**
49
     * Update the specified resource in storage.
50
     *
51
     * @param  \Illuminate\Http\Request        $request             Incoming request.
2 ignored issues
show
Coding Style introduced by
Expected 15 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 20 spaces after parameter name; 13 found
Loading history...
52
     * @param  \App\Models\AssessmentPlanNotification $assessmentPlanNotification Incoming object.
53
     * @throws \InvalidArgumentException For missing $question.
54
     * @return mixed
55
     */
56
    public function update(Request $request, AssessmentPlanNotification $assessmentPlanNotification)
57
    {
58
        $this->authorize('update', $assessmentPlanNotification);
59
        $assessmentPlanNotification->fill([
60
            'acknowledged' => $request->input('acknowledged')
61
        ]);
62
        $assessmentPlanNotification->save();
63
64
        return [
65
            'success' => "Successfully updated assessment plan notification $assessmentPlanNotification->id",
66
            'assessment_plan_notification' => $assessmentPlanNotification->toArray(),
67
        ];
68
    }
69
70
    /**
71
     * Remove the specified resource from storage.
72
     *
73
     * @param  \App\Models\AssessmentPlanNotification $assessmentPlanNotification Incoming object.
74
     * @return mixed
75
     */
76
    public function destroy(AssessmentPlanNotification $assessmentPlanNotification)
77
    {
78
        $this->authorize('delete', $assessmentPlanNotification);
79
        $assessmentPlanNotification->delete();
80
81
        return [
82
            'success' => "Successfully deleted assessment plan notification $assessmentPlanNotification->id"
83
        ];
84
    }
85
}
86