Completed
Pull Request — develop (#139)
by Tony
04:14
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
     * @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...
25
     */
26
    public function index(Request $request)
27
    {
28
        //
29
    }
30
31
    /**
32
     * Show the form for creating a new resource.
33
     *
34
     * @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...
35
     */
36
    public function create()
37
    {
38
        //
39
    }
40
41
    /**
42
     * Store a newly created resource in storage.
43
     *
44
     * @param  \Illuminate\Http\Request  $request
45
     * @return \Illuminate\Http\Response
46
     */
47
    public function store(Request $request)
48
    {
49
        $row                         = Dashboard::find($request->dashboard_id)->widgets()->max('row') + 1;
50
        $user_widget                 = new UsersWidgets;
51
        $user_widget->user_id        = $request->user()->user_id;
52
        $user_widget->widget_id      = $request->widget_id;
53
        $user_widget->col            = $request->col;
54
        $user_widget->row            = $row;
55
        $user_widget->size_x         = $request->size_x;
56
        $user_widget->size_y         = $request->size_y;
57
        $user_widget->title          = $request->title;
58
        $user_widget->dashboard_id   = $request->dashboard_id;
59
        if ($user_widget->save())
60
        {
61
            return $this->response->array(array('statusText' => 'OK', 'user_widget_id' => $user_widget->user_widget_id));
62
        }
63
        else {
64
            return $this->response->errorInternal();
65
        }
66
    }
67
68
    /**
69
     * Display the specified resource.
70
     *
71
     * @param  int  $id
72
     * @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...
73
     */
74 1
    public function show(Request $request, $id)
75
    {
76 1
        $widget  = Widgets::find($id);
77 1
        return array('widget' => $widget);
78 1
    }
79
80
    /**
81
     * Show the form for editing the specified resource.
82
     *
83
     * @param  int  $id
84
     * @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...
85
     */
86
    public function edit($id)
87
    {
88
        //
89
    }
90
91
    /**
92
     * Update the specified resource in storage.
93
     *
94
     * @param  \Illuminate\Http\Request  $request
95
     * @param  int  $id
96
     * @return \Illuminate\Http\Response
97
     */
98
    public function update(Request $request, $id)
99
    {
100
        if ($request->input('settings'))
101
        {
102
            $users_widgets           = UsersWidgets::find($id);
103
            $users_widgets->settings = json_encode($request->input('settings'));
104
        }
105
        else {
106
            $users_widgets         = UsersWidgets::find($id);
107
            $users_widgets->col    = $request->input('x');
108
            $users_widgets->row    = $request->input('y');
109
            $users_widgets->size_x = $request->input('width');
110
            $users_widgets->size_y = $request->input('height');
111
        }
112
113
        if ($users_widgets->save())
114
        {
115
            return $this->response->array(array('statusText' => 'OK'));
116
        }
117
        else {
118
            return $this->response->errorInternal();
119
        }
120
    }
121
122
    /**
123
     * Remove the specified resource from storage.
124
     *
125
     * @param  int  $id
126
     * @return \Illuminate\Http\Response
127
     */
128
    public function destroy($id)
129
    {
130
        if (UsersWidgets::destroy($id))
131
        {
132 1
            return $this->response->array(array('statusText' => 'OK'));
133
        }
134 1
        else {
135 1
            return $this->response->errorInternal();
136
        }
137
    }
138
}
139