1 | <?php namespace crocodicstudio\crudbooster\controllers; |
||||
2 | |||||
3 | use CRUDBooster; |
||||
0 ignored issues
–
show
|
|||||
4 | use Illuminate\Support\Facades\Cache; |
||||
5 | use Illuminate\Support\Facades\DB; |
||||
6 | use Illuminate\Support\Facades\Excel; |
||||
0 ignored issues
–
show
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
7 | use Illuminate\Support\Facades\PDF; |
||||
0 ignored issues
–
show
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
8 | use Illuminate\Support\Facades\Request; |
||||
9 | use Illuminate\Support\Facades\Session; |
||||
10 | use crocodicstudio\crudbooster\fonts\Fontawesome; |
||||
11 | |||||
12 | class MenusController extends CBController |
||||
13 | { |
||||
14 | public function cbInit() |
||||
15 | { |
||||
16 | $this->table = "cms_menus"; |
||||
17 | $this->primary_key = "id"; |
||||
18 | $this->title_field = "name"; |
||||
19 | $this->limit = 20; |
||||
20 | $this->orderby = ["id" => "desc"]; |
||||
21 | |||||
22 | $this->button_table_action = true; |
||||
23 | $this->button_action_style = "FALSE"; |
||||
24 | $this->button_add = false; |
||||
25 | $this->button_delete = true; |
||||
26 | $this->button_edit = true; |
||||
27 | $this->button_detail = true; |
||||
28 | $this->button_show = false; |
||||
29 | $this->button_filter = true; |
||||
30 | $this->button_export = false; |
||||
31 | $this->button_import = false; |
||||
32 | |||||
33 | $id = CRUDBooster::getCurrentId(); |
||||
34 | if (Request::segment(3) == 'edit') { |
||||
35 | $id = Request::segment(4); |
||||
36 | Session::put('current_row_id', $id); |
||||
37 | } |
||||
38 | $row = CRUDBooster::first($this->table, $id); |
||||
39 | $row = (Request::segment(3) == 'edit') ? $row : null; |
||||
40 | |||||
41 | $id_module = $id_statistic = 0; |
||||
42 | |||||
43 | if ($row->type == 'Module') { |
||||
44 | $m = CRUDBooster::first('cms_moduls', ['path' => $row->path]); |
||||
45 | $id_module = $m->id; |
||||
46 | } elseif ($row->type == 'Statistic') { |
||||
47 | $row->path = str_replace('statistic_builder/show/', '', $row->path); |
||||
48 | $m = CRUDBooster::first('cms_statistics', ['slug' => $row->path]); |
||||
49 | $id_statistic = $m->id; |
||||
50 | } |
||||
51 | |||||
52 | $this->script_js = " |
||||
53 | $(function() { |
||||
54 | var current_id = '$id'; |
||||
55 | var current_type = '$row->type'; |
||||
56 | var type_menu = $('input[name=type]').val(); |
||||
57 | type_menu = (current_type)?current_type:type_menu; |
||||
58 | if(type_menu == 'Module') { |
||||
59 | $('#form-group-module_slug').show(); |
||||
60 | $('#form-group-statistic_slug,#form-group-path').hide(); |
||||
61 | $('#module_slug').prop('required',true); |
||||
62 | $('#form-group-module_slug label').append('<span class=\"text-danger\" title=\"".trans('crudbooster.this_field_is_required')."\">*</span>'); |
||||
0 ignored issues
–
show
Are you sure
trans('crudbooster.this_field_is_required') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
63 | }else if(type_menu == 'Statistic') { |
||||
64 | $('#form-group-statistic_slug').show(); |
||||
65 | $('#module_slug').prop('required',false); |
||||
66 | $('#form-group-module_slug,#form-group-path').hide(); |
||||
67 | $('#statistic_slug').prop('required',true); |
||||
68 | $('#form-group-statistic_slug label').append('<span class=\"text-danger\" title=\"".trans('crudbooster.this_field_is_required')."\">*</span>'); |
||||
69 | }else{ |
||||
70 | $('#module_slug').prop('required',false); |
||||
71 | $('#form-group-module_slug,#form-group-statistic_slug').hide(); |
||||
72 | $('#form-group-path').show(); |
||||
73 | } |
||||
74 | |||||
75 | |||||
76 | function format(icon) { |
||||
77 | var originalOption = icon.element; |
||||
78 | var label = $(originalOption).text(); |
||||
79 | var val = $(originalOption).val(); |
||||
80 | if(!val) return label; |
||||
81 | var \$resp = $('<span><i style=\"margin-top:5px\" class=\"pull-right ' + $(originalOption).val() + '\"></i> ' + $(originalOption).data('label') + '</span>'); |
||||
82 | return \$resp; |
||||
83 | } |
||||
84 | $('#list-icon').select2({ |
||||
85 | width: \"100%\", |
||||
86 | templateResult: format, |
||||
87 | templateSelection: format |
||||
88 | }); |
||||
89 | |||||
90 | $('input[name=type]').click(function() { |
||||
91 | var default_placeholder_path = 'NameController@methodName'; |
||||
92 | var n = $(this).val(); |
||||
93 | var isCheck = $(this).prop('checked'); |
||||
94 | console.log('Click the module type '+n); |
||||
95 | $('#module_slug').prop('required',false); |
||||
96 | $('input[name=path]').attr('placeholder',default_placeholder_path); |
||||
97 | if(n == 'Module') { |
||||
98 | $('#form-group-path').hide(); |
||||
99 | $('#form-group-statistic_slug').hide(); |
||||
100 | $('#statistic_slug,#path').prop('required',false); |
||||
101 | |||||
102 | $('#form-group-module_slug').show(); |
||||
103 | $('#module_slug').prop('required',true); |
||||
104 | $('#form-group-module_slug label .text-danger').remove(); |
||||
105 | }else if (n == 'Statistic') { |
||||
106 | $('#form-group-path').hide(); |
||||
107 | $('#form-group-module_slug').hide(); |
||||
108 | $('#module_slug,#path').prop('required',false); |
||||
109 | |||||
110 | $('#form-group-statistic_slug').show(); |
||||
111 | $('#statistic_slug').prop('required',true); |
||||
112 | $('#form-group-statistic_slug label .text-danger').remove(); |
||||
113 | $('#form-group-statistic_slug label').append('<span class=\"text-danger\" title=\"".trans('crudbooster.this_field_is_required')."\">*</span>'); |
||||
114 | }else if (n == 'URL') { |
||||
115 | $('input[name=path]').attr('placeholder','Please enter your URL'); |
||||
116 | |||||
117 | $('#path').prop('required',true); |
||||
118 | $('#form-group-path label .text-danger').remove(); |
||||
119 | $('#form-group-path label').append('<span class=\"text-danger\" title=\"".trans('crudbooster.this_field_is_required')."\">*</span>'); |
||||
120 | |||||
121 | $('#form-group-path').show(); |
||||
122 | $('#form-group-module_slug,#form-group-statistic_slug').hide(); |
||||
123 | }else if (n == 'Route') { |
||||
124 | $('input[name=path]').attr('placeholder','Please enter the Route'); |
||||
125 | |||||
126 | $('#path').prop('required',true); |
||||
127 | $('#form-group-path label .text-danger').remove(); |
||||
128 | $('#form-group-path label').append('<span class=\"text-danger\" title=\"".trans('crudbooster.this_field_is_required')."\">*</span>'); |
||||
129 | |||||
130 | $('#form-group-path').show(); |
||||
131 | $('#form-group-module_slug,#form-group-statistic_slug').hide(); |
||||
132 | }else { |
||||
133 | $('#module_slug,#statistic_slug').prop('required',false); |
||||
134 | |||||
135 | $('#path').prop('required',true); |
||||
136 | $('#form-group-path label .text-danger').remove(); |
||||
137 | $('#form-group-path label').append('<span class=\"text-danger\" title=\"".trans('crudbooster.this_field_is_required')."\">*</span>'); |
||||
138 | |||||
139 | $('#form-group-path').show(); |
||||
140 | $('#form-group-module_slug,#form-group-statistic_slug').hide(); |
||||
141 | } |
||||
142 | }) |
||||
143 | }) |
||||
144 | "; |
||||
145 | |||||
146 | $this->col = []; |
||||
147 | $this->col[] = ["label" => "Name", "name" => "name"]; |
||||
148 | $this->col[] = ["label" => "Is Active", "name" => "is_active"]; |
||||
149 | $this->col[] = ["label" => "Privileges", "name" => "id_cms_privileges", "join" => "cms_privileges,name"]; |
||||
150 | |||||
151 | $this->form = []; |
||||
152 | $this->form[] = [ |
||||
153 | "label" => "Privileges", |
||||
154 | "name" => "cms_menus_privileges", |
||||
155 | "type" => "select2", |
||||
156 | "select2_multiple" => true, |
||||
157 | "datatable" => "cms_privileges,name", |
||||
158 | "relationship_table" => "cms_menus_privileges", |
||||
159 | "required" => true, |
||||
160 | ]; |
||||
161 | $this->form[] = [ |
||||
162 | "label" => "Name", |
||||
163 | "name" => "name", |
||||
164 | "type" => "text", |
||||
165 | "required" => true, |
||||
166 | "validation" => "required|min:3|max:255" |
||||
167 | ]; |
||||
168 | $this->form[] = [ |
||||
169 | "label" => "Type", |
||||
170 | "name" => "type", |
||||
171 | "type" => "radio", |
||||
172 | "required" => true, |
||||
173 | 'dataenum' => ['Module', 'Statistic', 'URL', 'Controller & Method', 'Route'], |
||||
174 | 'value' => 'Module', |
||||
175 | ]; |
||||
176 | |||||
177 | $this->form[] = [ |
||||
178 | "label" => "Module", |
||||
179 | "name" => "module_slug", |
||||
180 | "type" => "select", |
||||
181 | "datatable" => "cms_moduls,name", |
||||
182 | "datatable_where" => "is_protected = 0", |
||||
183 | "value" => $id_module, |
||||
184 | ]; |
||||
185 | $this->form[] = [ |
||||
186 | "label" => "Statistic", |
||||
187 | "name" => "statistic_slug", |
||||
188 | "type" => "select", |
||||
189 | "datatable" => "cms_statistics,name", |
||||
190 | "style" => "display:none", |
||||
191 | "value" => $id_statistic, |
||||
192 | ]; |
||||
193 | |||||
194 | $this->form[] = [ |
||||
195 | "label" => "Value", |
||||
196 | "name" => "path", |
||||
197 | "type" => "text", |
||||
198 | 'help' => 'If you select type controller, you can fill this field with controller name, you may include the method also', |
||||
199 | 'placeholder' => 'NameController or NameController@methodName', |
||||
200 | "style" => "display:none", |
||||
201 | ]; |
||||
202 | |||||
203 | $fontawesome = Fontawesome::getIcons(); |
||||
204 | |||||
205 | $custom = view('crudbooster::components.list_icon', compact('fontawesome', 'row'))->render(); |
||||
206 | $this->form[] = ['label' => 'Icon', 'name' => 'icon', 'type' => 'custom', 'html' => $custom, 'required' => true]; |
||||
207 | $this->form[] = [ |
||||
208 | 'label' => 'Color', |
||||
209 | 'name' => 'color', |
||||
210 | 'type' => 'select2', |
||||
211 | 'dataenum' => ['normal', 'red', 'green', 'aqua', 'light-blue', 'red', 'yellow', 'muted'], |
||||
212 | 'required' => true, |
||||
213 | 'value' => 'normal', |
||||
214 | ]; |
||||
215 | $this->form[] = [ |
||||
216 | "label" => "Active", |
||||
217 | "name" => "is_active", |
||||
218 | "type" => "radio", |
||||
219 | "required" => true, |
||||
220 | "validation" => "required|integer", |
||||
221 | "dataenum" => ['1|Active', '0|InActive'], |
||||
222 | 'value' => '1', |
||||
223 | ]; |
||||
224 | $this->form[] = [ |
||||
225 | "label" => "Dashboard", |
||||
226 | "name" => "is_dashboard", |
||||
227 | "type" => "radio", |
||||
228 | "required" => true, |
||||
229 | "validation" => "required|integer", |
||||
230 | "dataenum" => ['1|Yes', '0|No'], |
||||
231 | 'value' => '0', |
||||
232 | ]; |
||||
233 | |||||
234 | $id_cms_privileges = Request::get('id_cms_privileges'); |
||||
235 | $this->form[] = ["label" => "id_cms_privileges", "name" => "id_cms_privileges", "type" => "hidden", "value" => $id_cms_privileges]; |
||||
236 | } |
||||
237 | |||||
238 | public function getIndex() |
||||
239 | { |
||||
240 | $this->cbLoader(); |
||||
241 | |||||
242 | $module = CRUDBooster::getCurrentModule(); |
||||
243 | if (! CRUDBooster::isView() && $this->global_privilege == false) { |
||||
0 ignored issues
–
show
|
|||||
244 | CRUDBooster::insertLog(trans('crudbooster.log_try_view', ['module' => $module->name])); |
||||
245 | CRUDBooster::redirect(CRUDBooster::adminPath(), trans('crudbooster.denied_access')); |
||||
246 | } |
||||
247 | |||||
248 | $privileges = DB::table('cms_privileges')->get(); |
||||
249 | |||||
250 | $id_cms_privileges = Request::get('id_cms_privileges'); |
||||
251 | $id_cms_privileges = ($id_cms_privileges) ?: CRUDBooster::myPrivilegeId(); |
||||
252 | |||||
253 | $menu_active = DB::table('cms_menus')->where('parent_id', 0)->where('is_active', 1)->orderby('sorting', 'asc')->get(); |
||||
254 | |||||
255 | foreach ($menu_active as &$menu) { |
||||
256 | $child = DB::table('cms_menus')->where('is_active', 1)->where('parent_id', $menu->id)->orderby('sorting', 'asc')->get(); |
||||
257 | if (count($child)) { |
||||
258 | $menu->children = $child; |
||||
259 | } |
||||
260 | } |
||||
261 | |||||
262 | $menu_inactive = DB::table('cms_menus')->where('parent_id', 0)->where('is_active', 0)->orderby('sorting', 'asc')->get(); |
||||
263 | |||||
264 | foreach ($menu_inactive as &$menu) { |
||||
265 | $child = DB::table('cms_menus')->where('is_active', 1)->where('parent_id', $menu->id)->orderby('sorting', 'asc')->get(); |
||||
266 | if (count($child)) { |
||||
267 | $menu->children = $child; |
||||
268 | } |
||||
269 | } |
||||
270 | |||||
271 | $return_url = Request::fullUrl(); |
||||
272 | |||||
273 | $page_title = 'Menu Management'; |
||||
274 | |||||
275 | return view('crudbooster::menus_management', compact('menu_active', 'menu_inactive', 'privileges', 'id_cms_privileges', 'return_url', 'page_title')); |
||||
276 | } |
||||
277 | |||||
278 | public function hook_before_add(&$postdata) |
||||
279 | { |
||||
280 | if (! $postdata['id_cms_privileges']) { |
||||
281 | $postdata['id_cms_privileges'] = CRUDBooster::myPrivilegeId(); |
||||
282 | } |
||||
283 | $postdata['parent_id'] = 0; |
||||
284 | |||||
285 | if ($postdata['type'] == 'Statistic') { |
||||
286 | $stat = CRUDBooster::first('cms_statistics', ['id' => $postdata['statistic_slug']]); |
||||
287 | $postdata['path'] = 'statistic_builder/show/'.$stat->slug; |
||||
288 | } elseif ($postdata['type'] == 'Module') { |
||||
289 | $stat = CRUDBooster::first('cms_moduls', ['id' => $postdata['module_slug']]); |
||||
290 | $postdata['path'] = $stat->path; |
||||
291 | } |
||||
292 | |||||
293 | unset($postdata['module_slug']); |
||||
294 | unset($postdata['statistic_slug']); |
||||
295 | |||||
296 | if ($postdata['is_dashboard'] == 1) { |
||||
297 | //If set dashboard, so unset for first all dashboard |
||||
298 | //DB::table('cms_menus')->where('id_cms_privileges', $postdata['id_cms_privileges'])->where('is_dashboard', 1)->update(['is_dashboard' => 0]); |
||||
299 | Cache::forget('sidebarDashboard'.CRUDBooster::myPrivilegeId()); |
||||
300 | } |
||||
301 | } |
||||
302 | |||||
303 | public function hook_before_edit(&$postdata, $id) |
||||
304 | { |
||||
305 | |||||
306 | if ($postdata['is_dashboard'] == 1) { |
||||
307 | //If set dashboard, so unset for first all dashboard |
||||
308 | //DB::table('cms_menus')->where('id_cms_privileges', $postdata['id_cms_privileges'])->where('is_dashboard', 1)->update(['is_dashboard' => 0]); |
||||
309 | Cache::forget('sidebarDashboard'.CRUDBooster::myPrivilegeId()); |
||||
310 | } |
||||
311 | |||||
312 | if ($postdata['type'] == 'Statistic') { |
||||
313 | $stat = CRUDBooster::first('cms_statistics', ['id' => $postdata['statistic_slug']]); |
||||
314 | $postdata['path'] = 'statistic_builder/show/'.$stat->slug; |
||||
315 | } elseif ($postdata['type'] == 'Module') { |
||||
316 | $stat = CRUDBooster::first('cms_moduls', ['id' => $postdata['module_slug']]); |
||||
317 | $postdata['path'] = $stat->path; |
||||
318 | } |
||||
319 | |||||
320 | unset($postdata['module_slug']); |
||||
321 | unset($postdata['statistic_slug']); |
||||
322 | } |
||||
323 | |||||
324 | public function hook_after_delete($id) |
||||
325 | { |
||||
326 | DB::table('cms_menus')->where('parent_id', $id)->delete(); |
||||
327 | } |
||||
328 | |||||
329 | public function postSaveMenu() |
||||
330 | { |
||||
331 | $post = Request::input('menus'); |
||||
332 | $isActive = Request::input('isActive'); |
||||
333 | $post = json_decode($post, true); |
||||
334 | |||||
335 | $i = 1; |
||||
336 | foreach ($post[0] as $ro) { |
||||
337 | $pid = $ro['id']; |
||||
338 | if ($ro['children'][0]) { |
||||
339 | $ci = 1; |
||||
340 | foreach ($ro['children'][0] as $c) { |
||||
341 | $id = $c['id']; |
||||
342 | DB::table('cms_menus')->where('id', $id)->update(['sorting' => $ci, 'parent_id' => $pid, 'is_active' => $isActive]); |
||||
343 | $ci++; |
||||
344 | } |
||||
345 | } |
||||
346 | DB::table('cms_menus')->where('id', $pid)->update(['sorting' => $i, 'parent_id' => 0, 'is_active' => $isActive]); |
||||
347 | $i++; |
||||
348 | } |
||||
349 | |||||
350 | return response()->json(['success' => true]); |
||||
351 | } |
||||
352 | } |
||||
353 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths