StatisticBuilderController::postAddComponent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 24
rs 9.7
1
<?php namespace crocodicstudio\crudbooster\controllers;
2
3
use CRUDBooster;
0 ignored issues
show
Bug introduced by
The type CRUDBooster was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
use Illuminate\Support\Facades\DB;
5
use Illuminate\Support\Facades\Excel;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Excel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\PDF;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\PDF was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Support\Facades\Request;
8
9
class StatisticBuilderController extends CBController
10
{
11
    public function cbInit()
12
    {
13
        $this->table = "cms_statistics";
14
        $this->primary_key = "id";
15
        $this->title_field = "name";
16
        $this->limit = 20;
17
        $this->orderby = ["id" => "desc"];
18
        $this->global_privilege = false;
19
20
        $this->button_table_action = true;
21
        $this->button_action_style = "button_icon_text";
22
        $this->button_add = true;
23
        $this->button_delete = true;
24
        $this->button_edit = true;
25
        $this->button_detail = false;
26
        $this->button_show = true;
27
        $this->button_filter = false;
28
        $this->button_export = false;
29
        $this->button_import = false;
30
31
        $this->col = [];
32
        $this->col[] = ["label" => "Name", "name" => "name"];
33
34
        $this->form = [];
35
        $this->form[] = [
36
            "label" => "Name",
37
            "name" => "name",
38
            "type" => "text",
39
            "required" => true,
40
            "validation" => "required|min:3|max:255",
41
            "placeholder" => "You can only enter the letter only",
42
        ];
43
44
        $this->addaction = [];
45
        $this->addaction[] = ['label' => 'Builder', 'url' => CRUDBooster::mainpath('builder').'/[id]', 'icon' => 'fa fa-wrench'];
46
    }
47
48
    public function getShowDashboard()
49
    {
50
        $this->cbLoader();
51
        $m = CRUDBooster::sidebarDashboard();
52
        $m->path = str_replace("statistic_builder/show/", "", $m->path);
53
        if ($m->type != 'Statistic') {
54
            redirect('/');
55
        }
56
        $row = CRUDBooster::first($this->table, ['slug' => $m->path]);
57
58
        $id_cms_statistics = $row->id;
59
        $page_title = $row->name;
60
61
        return view('crudbooster::statistic_builder.show', compact('page_title', 'id_cms_statistics'));
62
    }
63
64
    public function getDashboard()
65
    {
66
        $this->cbLoader();
67
68
        $menus= DB::table('cms_menus')->whereRaw("cms_menus.id IN (select id_cms_menus from cms_menus_privileges where id_cms_privileges = '".CRUDBooster::myPrivilegeId()."')")->where('is_dashboard', 1)->where('is_active', 1)->first();
69
70
        $slug = str_replace("statistic_builder/show/", "", $menus->path);
71
72
        $row = CRUDBooster::first($this->table, ['slug' => $slug]);
73
        $id_cms_statistics = $row->id;
74
        $page_title = $row->name;
75
76
        return view('crudbooster::statistic_builder.show', compact('page_title', 'id_cms_statistics'));
77
    }
78
79
    public function getShow($slug)
80
    {
81
        $this->cbLoader();
82
        $row = CRUDBooster::first($this->table, ['slug' => $slug]);
83
        $id_cms_statistics = $row->id;
84
        $page_title = $row->name;
85
86
        return view('crudbooster::statistic_builder.show', compact('page_title', 'id_cms_statistics'));
87
    }
88
89
    public function getBuilder($id_cms_statistics)
90
    {
91
        $this->cbLoader();
92
93
        if (! CRUDBooster::isSuperadmin()) {
94
            CRUDBooster::insertLog(trans("crudbooster.log_try_view", ['name' => 'Builder', 'module' => 'Statistic']));
95
            CRUDBooster::redirect(CRUDBooster::adminPath(), trans('crudbooster.denied_access'));
96
        }
97
98
        $page_title = 'Statistic Builder';
99
100
        return view('crudbooster::statistic_builder.builder', compact('page_title', 'id_cms_statistics'));
101
    }
102
103
    public function getListComponent($id_cms_statistics, $area_name)
104
    {
105
        $rows = DB::table('cms_statistic_components')->where('id_cms_statistics', $id_cms_statistics)->where('area_name', $area_name)->orderby('sorting', 'asc')->get();
106
107
        return response()->json(['components' => $rows]);
108
    }
109
110
    public function getViewComponent($componentID)
111
    {
112
113
        $component = DB::table('cms_statistic_components')->where('componentID', $componentID)->first();
114
        $command = 'layout';
115
        $layout = view('crudbooster::statistic_builder.components.'.$component->component_name, compact('command', 'componentID'))->render();
116
117
        $component_name = $component->component_name;
118
        $area_name = $component->area_name;
0 ignored issues
show
Unused Code introduced by
The assignment to $area_name is dead and can be removed.
Loading history...
119
        $config = json_decode($component->config);
120
        if ($config) {
121
            foreach ($config as $key => $value) {
122
                if ($value) {
123
                    $command = 'showFunction';
124
                    $value = view('crudbooster::statistic_builder.components.'.$component_name, compact('command', 'value', 'key', 'config', 'componentID'))->render();
125
                    $layout = str_replace('['.$key.']', $value, $layout);
126
                }
127
            }
128
        }
129
130
        return response()->json(compact('componentID', 'layout'));
131
    }
132
133
    public function postAddComponent()
134
    {
135
        $this->cbLoader();
136
        $component_name = Request::get('component_name');
137
        $id_cms_statistics = Request::get('id_cms_statistics');
138
        $sorting = Request::get('sorting');
139
        $area = Request::get('area');
140
141
        $componentID = md5(time());
142
143
        $command = 'layout';
144
        $layout = view('crudbooster::statistic_builder.components.'.$component_name, compact('command', 'componentID'))->render();
145
146
        $data = [
147
            'id_cms_statistics' => $id_cms_statistics,
148
            'componentID' => $componentID,
149
            'component_name' => $component_name,
150
            'area_name' => $area,
151
            'sorting' => $sorting,
152
            'name' => 'Untitled',
153
        ];
154
        CRUDBooster::insert('cms_statistic_components', $data);
155
156
        return response()->json(compact('layout', 'componentID'));
157
    }
158
159
    public function postUpdateAreaComponent()
160
    {
161
        DB::table('cms_statistic_components')->where('componentID', Request::get('componentid'))->update([
162
            'sorting' => Request::get('sorting'),
163
            'area_name' => Request::get('areaname'),
164
        ]);
165
166
        return response()->json(['status' => true]);
167
    }
168
169
    public function getEditComponent($componentID)
170
    {
171
        $this->cbLoader();
172
173
        if (! CRUDBooster::isSuperadmin()) {
174
            CRUDBooster::insertLog(trans("crudbooster.log_try_view", ['name' => 'Edit Component', 'module' => 'Statistic']));
175
            CRUDBooster::redirect(CRUDBooster::adminPath(), trans('crudbooster.denied_access'));
176
        }
177
178
        $component_row = CRUDBooster::first('cms_statistic_components', ['componentID' => $componentID]);
179
180
        $config = json_decode($component_row->config);
181
182
        $command = 'configuration';
183
184
        return view('crudbooster::statistic_builder.components.'.$component_row->component_name, compact('command', 'componentID', 'config'));
185
    }
186
187
    public function postSaveComponent()
188
    {
189
        DB::table('cms_statistic_components')->where('componentID', Request::get('componentid'))->update([
190
            'name' => Request::get('name'),
191
            'config' => json_encode(Request::get('config')),
192
        ]);
193
194
        return response()->json(['status' => true]);
195
    }
196
197
    public function getDeleteComponent($id)
198
    {
199
        if (! CRUDBooster::isSuperadmin()) {
200
            CRUDBooster::insertLog(trans("crudbooster.log_try_view", ['name' => 'Delete Component', 'module' => 'Statistic']));
201
            CRUDBooster::redirect(CRUDBooster::adminPath(), trans('crudbooster.denied_access'));
202
        }
203
204
        DB::table('cms_statistic_components')->where('componentID', $id)->delete();
205
206
        return response()->json(['status' => true]);
207
    }
208
209
    public function hook_before_add(&$arr)
210
    {
211
        //Your code here
212
        $arr['slug'] = str_slug($arr['name']);
0 ignored issues
show
Deprecated Code introduced by
The function str_slug() has been deprecated: Str::slug() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

212
        $arr['slug'] = /** @scrutinizer ignore-deprecated */ str_slug($arr['name']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
213
    }
214
}
215