Completed
Push — develop ( 0d51b0...7344b5 )
by Neil
8s
created

DashboardWidgetController::get_content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Api\Controllers;
4
5
use App\Models\Dashboard;
6
use App\Models\UsersWidgets;
7
use App\Models\Widgets;
8
use Dingo\Api\Http;
9
use Dingo\Api\Routing\Helpers;
10
use Illuminate\Http\Request;
11
12
class DashboardWidgetController extends Controller
13
{
14
15
    use Helpers;
16
17 1
    public function __construct() {
18
19 1
    }
20
21
    /**
22
     * Display a listing of all authorized devices
23
     *
24
     * @param Request $request
25
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
26
     */
27
    public function index(Request $request)
28
    {
29
        //
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
36
     */
37
    public function create()
38
    {
39
        //
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param  \Illuminate\Http\Request  $request
46
     * @return \Illuminate\Http\Response
47
     */
48
    public function store(Request $request)
49
    {
50
        $row                         = Dashboard::find($request->dashboard_id)->widgets()->max('row') + 1;
51
        $user_widget                 = new UsersWidgets;
52
        $user_widget->user_id        = $request->user()->user_id;
53
        $user_widget->widget_id      = $request->widget_id;
54
        $user_widget->col            = $request->col;
55
        $user_widget->row            = $row;
56
        $user_widget->size_x         = $request->size_x;
57
        $user_widget->size_y         = $request->size_y;
58
        $user_widget->title          = $request->title;
59
        $user_widget->dashboard_id   = $request->dashboard_id;
60
        if ($user_widget->save())
61
        {
62
            return $this->response->array(array('statusText' => 'OK', 'user_widget_id' => $user_widget->user_widget_id));
63
        }
64
        else {
65
            return $this->response->errorInternal();
66
        }
67
    }
68
69
    /**
70
     * Display the specified resource.
71
     *
72
     * @param Request $request
73
     * @param  int $id
74 1
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
75
     */
76 1
    public function show(Request $request, $id)
77 1
    {
78 1
        $widget  = Widgets::find($id);
79
        return array('widget' => $widget);
80
    }
81
82
    /**
83
     * Show the form for editing the specified resource.
84
     *
85
     * @param  int  $id
86
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
87
     */
88
    public function edit($id)
89
    {
90
        //
91
    }
92
93
    /**
94
     * Update the specified resource in storage.
95
     *
96
     * @param  \Illuminate\Http\Request  $request
97
     * @param  int  $id
98
     * @return \Illuminate\Http\Response
99
     */
100
    public function update(Request $request, $id)
101
    {
102
        if ($request->input('settings'))
103
        {
104
            $users_widgets           = UsersWidgets::find($id);
105
            $users_widgets->settings = json_encode($request->input('settings'));
106
        }
107
        else {
108
            $users_widgets         = UsersWidgets::find($id);
109
            $users_widgets->col    = $request->input('x');
110
            $users_widgets->row    = $request->input('y');
111
            $users_widgets->size_x = $request->input('width');
112
            $users_widgets->size_y = $request->input('height');
113
        }
114
115
        if ($users_widgets->save())
116
        {
117
            return $this->response->array(array('statusText' => 'OK'));
118
        }
119
        else {
120
            return $this->response->errorInternal();
121
        }
122
    }
123
124
    /**
125
     * Remove the specified resource from storage.
126
     *
127
     * @param  int  $id
128
     * @return \Illuminate\Http\Response
129
     */
130
    public function destroy($id)
131
    {
132 1
        if (UsersWidgets::destroy($id))
133
        {
134 1
            return $this->response->array(array('statusText' => 'OK'));
135 1
        }
136
        else {
137
            return $this->response->errorInternal();
138
        }
139
    }
140
}
141