Completed
Push — device-groups ( 54870b...cccab4 )
by Tony
03:45
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
     * @param Request $request
25
     * @return \Illuminate\Http\Response
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
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 View Code Duplication
        if ($user_widget->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...
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
     * @return \Illuminate\Http\Response
75
     */
76
    public function show(Request $request, $id)
77
    {
78
        $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
87
     */
88
    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...
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 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...
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
        if (UsersWidgets::destroy($id))
133
        {
134
            return $this->response->array(array('statusText' => 'OK'));
135
        }
136
        else {
137
            return $this->response->errorInternal();
138
        }
139
    }
140
}
141