Completed
Push — fixes ( 73343d...8cfd48 )
by Tony
03:02
created

DashboardWidgetController::get_content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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
    public function __construct() {
18
19
    }
20
21
    /**
22
     * Display a listing of all authorized devices
23
     *
24
     * @return \Illuminate\Http\Response
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
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
73
     */
74
    public function show(Request $request, $id)
75
    {
76
        $widget  = Widgets::find($id);
77
        return array('widget' => $widget);
78
    }
79
80
    /**
81
     * Show the form for editing the specified resource.
82
     *
83
     * @param  int  $id
84
     * @return \Illuminate\Http\Response
85
     */
86
    public function edit($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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 View Code Duplication
        if ($users_widgets->save())
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
            return $this->response->array(array('statusText' => 'OK'));
133
        }
134
        else {
135
            return $this->response->errorInternal();
136
        }
137
    }
138
}
139