Passed
Push — feature/job-builder/step-03-ui ( dabf2e...dabf2e )
by Xander
20:05 queued 13s
created

AssessmentPlanNotificationController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 22
c 1
b 0
f 0
dl 0
loc 71
ccs 0
cts 23
cp 0
rs 10

4 Methods

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