Passed
Push — main ( 275957...473697 )
by PRATIK
04:03
created

Adminetic::getClientAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pratiksh\Adminetic\Services;
4
5
use Exception;
6
use App\Models\User;
0 ignored issues
show
Bug introduced by
The type App\Models\User 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\Str;
8
use Pratiksh\Adminetic\Models\Admin\Role;
9
use Pratiksh\Adminetic\Models\Admin\Setting;
10
use Pratiksh\Adminetic\Models\Admin\Permission;
11
use Pratiksh\Adminetic\Models\Admin\Preference;
12
13
class Adminetic
14
{
15
    public function user()
16
    {
17
        $user = config('auth.providers.users.model');
18
        return new $user;
19
    }
20
21
    public function assets(): array
22
    {
23
        $client_assets = $this->getClientAssets();
24
        $default_assets = $this->getDefaultAssets();
25
        $allAssets = array_merge($default_assets, $client_assets);
26
27
        $assets = array_unique($allAssets, SORT_REGULAR);
28
        return $assets;
29
    }
30
31
    public function menus(): array
32
    {
33
        $client_menus = $this->clientMenus();
34
        $adminetic_menus = $this->admineticMenus();
35
        $plugin_menus = $this->pluginMenus();
36
        $allmenus = array_merge($adminetic_menus, $client_menus, $plugin_menus);
37
        return $allmenus;
38
    }
39
40
    public function getClientAssets(): array
41
    {
42
        return config('adminetic.assets', array());
43
    }
44
45
    public function getDefaultAssets(): array
46
    {
47
        return [
48
            [
49
                'name' => 'Datatables',
50
                'active' => true,
51
                'files' => [
52
                    [
53
                        'type' => 'css',
54
                        'active' => true,
55
                        'location' => 'adminetic/assets/css/vendors/datatables.css',
56
                    ],
57
                    [
58
                        'type' => 'js',
59
                        'active' => true,
60
                        'location' => 'adminetic/assets/js/datatable/datatables/jquery.dataTables.min.js',
61
                    ],
62
                    [
63
                        'type' => 'js',
64
                        'active' => true,
65
                        'location' => 'adminetic/assets/js/datatable/datatable-extension/dataTables.buttons.min.js',
66
                    ],
67
                    [
68
                        'type' => 'js',
69
                        'active' => true,
70
                        'location' => 'adminetic/assets/js/datatable/datatable-extension/buttons.flash.min.js',
71
                    ],
72
                    [
73
                        'type' => 'js',
74
                        'active' => true,
75
                        'location' => 'adminetic/assets/js/datatable/datatable-extension/jszip.min.js',
76
                    ],
77
                    [
78
                        'type' => 'js',
79
                        'active' => true,
80
                        'location' => 'adminetic/assets/js/datatable/datatable-extension/pdfmake.min.js',
81
                    ],
82
                    [
83
                        'type' => 'js',
84
                        'active' => true,
85
                        'location' => 'adminetic/assets/js/datatable/datatable-extension/vfs_fonts.js',
86
                    ],
87
                    [
88
                        'type' => 'js',
89
                        'active' => true,
90
                        'location' => 'adminetic/assets/js/datatable/datatable-extension/buttons.html5.min.js',
91
                    ],
92
                    [
93
                        'type' => 'js',
94
                        'active' => true,
95
                        'location' => 'adminetic/assets/js/datatable/datatable-extension/buttons.print.min.js',
96
                    ],
97
                ],
98
            ],
99
            [
100
                'name' => 'Icons',
101
                'active' => true,
102
                'files' => [
103
                    [
104
                        'type' => 'css',
105
                        'active' => true,
106
                        'location' => 'adminetic/assets/css/font-awesome.css',
107
                    ],
108
                    [
109
                        'type' => 'css',
110
                        'active' => true,
111
                        'location' => 'adminetic/assets/css/vendors/icofont.css',
112
                    ],
113
                    [
114
                        'type' => 'css',
115
                        'active' => true,
116
                        'location' => 'adminetic/assets/css/vendors/themify.css',
117
                    ],
118
                    [
119
                        'type' => 'css',
120
                        'active' => true,
121
                        'location' => 'adminetic/assets/css/vendors/flag-icon.css',
122
                    ],
123
                    [
124
                        'type' => 'css',
125
                        'active' => true,
126
                        'location' => 'adminetic/assets/css/vendors/feather-icon.css',
127
                    ],
128
                ],
129
            ],
130
            [
131
                'name' => 'Scrollbar',
132
                'active' => true,
133
                'files' => [
134
                    [
135
                        'type' => 'css',
136
                        'active' => true,
137
                        'location' => 'adminetic/assets/css/vendors/scrollbar.css',
138
                    ],
139
                    [
140
                        'type' => 'js',
141
                        'active' => true,
142
                        'location' => 'adminetic/assets/js/scrollbar/simplebar.js',
143
                    ],
144
                    [
145
                        'type' => 'js',
146
                        'active' => true,
147
                        'location' => 'adminetic/assets/js/scrollbar/custom.js',
148
                    ],
149
                ],
150
            ],
151
            [
152
                'name' => 'Touchspin',
153
                'active' => true,
154
                'files' => [
155
                    [
156
                        'type' => 'js',
157
                        'active' => true,
158
                        'location' => 'adminetic/assets/js/touchspin/touchspin.js',
159
                    ],
160
                    [
161
                        'type' => 'js',
162
                        'active' => true,
163
                        'location' => 'adminetic/assets/js/touchspin/input-groups.min.js',
164
                    ],
165
                ],
166
            ],
167
            [
168
                'name' => 'Datepicker',
169
                'active' => true,
170
                'files' => [
171
                    [
172
                        'type' => 'css',
173
                        'active' => true,
174
                        'location' => 'adminetic/assets/css/vendors/date-picker.css',
175
                    ],
176
                    [
177
                        'type' => 'js',
178
                        'active' => true,
179
                        'location' => 'adminetic/assets/js/datepicker/date-picker/datepicker.js',
180
                    ],
181
                    [
182
                        'type' => 'js',
183
                        'active' => true,
184
                        'location' => 'adminetic/assets/js/datepicker/date-picker/datepicker.en.js',
185
                    ],
186
                ],
187
            ],
188
            [
189
                'name' => 'CKEditor',
190
                'active' => true,
191
                'files' => [
192
                    [
193
                        'type' => 'js',
194
                        'active' => true,
195
                        'location' => 'adminetic/assets/js/editor/ckeditor/ckeditor.js',
196
                    ],
197
                    [
198
                        'type' => 'js',
199
                        'active' => true,
200
                        'location' => 'adminetic/assets/js/editor/ckeditor/styles.js',
201
                    ],
202
                ],
203
            ],
204
            [
205
                'name' => 'Summernote',
206
                'active' => true,
207
                'files' => [
208
                    [
209
                        'type' => 'css',
210
                        'active' => true,
211
                        'location' => 'adminetic/assets/css/vendors/summernote.css',
212
                    ],
213
                    [
214
                        'type' => 'js',
215
                        'active' => true,
216
                        'location' => 'adminetic/assets/js/editor/summernote/summernote.js',
217
                    ],
218
                ],
219
            ],
220
            [
221
                'name' => 'Select2',
222
                'active' => true,
223
                'files' => [
224
                    [
225
                        'type' => 'css',
226
                        'active' => true,
227
                        'location' => 'adminetic/assets/css/vendors/select2.css',
228
                    ],
229
                    [
230
                        'type' => 'js',
231
                        'active' => true,
232
                        'location' => 'adminetic/assets/js/select2/select2.full.min.js',
233
                    ],
234
                ],
235
            ],
236
            [
237
                'name' => 'ACE Editor',
238
                'active' => false,
239
                'files' => [
240
                    [
241
                        'type' => 'js',
242
                        'active' => true,
243
                        'location' => 'adminetic/assets/js/editor/ace-editor/ace.js',
244
                    ],
245
                    [
246
                        'type' => 'js',
247
                        'active' => true,
248
                        'location' => 'adminetic/assets/js/editor/ace-editor/mode-html.js',
249
                    ],
250
                ],
251
            ],
252
            [
253
                'name' => 'Notify',
254
                'active' => true,
255
                'files' => [
256
                    [
257
                        'type' => 'js',
258
                        'active' => true,
259
                        'location' => 'adminetic/assets/js/notify/bootstrap-notify.min.js',
260
                    ],
261
                ],
262
            ],
263
            [
264
                'name' => 'Card',
265
                'active' => true,
266
                'files' => [
267
                    [
268
                        'type' => 'js',
269
                        'active' => true,
270
                        'location' => 'adminetic/assets/js/custom-card/custom-card.js',
271
                    ],
272
                ],
273
            ],
274
        ];
275
    }
276
277
    public function getPluginAssets(): array
278
    {
279
        $pluginAssets = array();
280
        if (count($this->getAdapters()) > 0) {
281
            foreach ($this->getAdapters() as $adapter) {
282
                $pluginAssets = array_merge($pluginAssets, $adapter->assets());
283
            }
284
        }
285
        return $pluginAssets;
286
    }
287
288
    public function admineticMenus(): array
289
    {
290
        return [
291
            [
292
                'type' => 'breaker',
293
                'name' => 'General',
294
                'description' => 'Administration Control',
295
            ],
296
            [
297
                'type' => 'link',
298
                'name' => 'Dashboard',
299
                'icon' => 'fa fa-home',
300
                'link' => route('home'),
301
                'is_active' => request()->routeIs('home') ? 'active' : '',
302
                'conditions' => [
303
                    [
304
                        'type' => 'and',
305
                        'condition' => auth()->user()->hasRole('admin'),
306
                    ],
307
                ],
308
            ],
309
            [
310
                'type' => 'menu',
311
                'name' => 'User Management',
312
                'icon' => 'fa fa-users',
313
                'is_active' => request()->routeIs('user*') ? 'active' : '',
314
                'pill' => [
315
                    'class' => 'badge badge-info badge-air-info',
316
                    'value' => \App\Models\User::count(),
317
                ],
318
                'conditions' => [
319
                    [
320
                        'type' => 'or',
321
                        'condition' => auth()->user()->can('view-any', \App\Models\User::class),
322
                    ],
323
                    [
324
                        'type' => 'or',
325
                        'condition' => auth()->user()->can('create', \App\Models\User::class),
326
                    ],
327
                ],
328
                'children' => $this->indexCreateChildren('user', \App\Models\User::class),
329
            ],
330
            [
331
                'type' => 'menu',
332
                'name' => 'Role',
333
                'icon' => 'fa fa-black-tie',
334
                'is_active' => request()->routeIs('role*') ? 'active' : '',
335
                'conditions' => [
336
                    [
337
                        'type' => 'or',
338
                        'condition' => auth()->user()->can('view-any', \Pratiksh\Adminetic\Models\Admin\Role::class),
339
                    ],
340
                    [
341
                        'type' => 'or',
342
                        'condition' => auth()->user()->can('create', \Pratiksh\Adminetic\Models\Admin\Role::class),
343
                    ],
344
                ],
345
                'children' => $this->indexCreateChildren('role', \Pratiksh\Adminetic\Models\Admin\Role::class),
346
            ],
347
            [
348
                'type' => 'menu',
349
                'name' => 'Permission',
350
                'icon' => 'fa fa-check',
351
                'is_active' => request()->routeIs('permission*') ? 'active' : '',
352
                'conditions' => [
353
                    [
354
                        'type' => 'or',
355
                        'condition' => auth()->user()->can('view-any', \Pratiksh\Adminetic\Models\Admin\Permission::class),
356
                    ],
357
                    [
358
                        'type' => 'or',
359
                        'condition' => auth()->user()->can('create', \Pratiksh\Adminetic\Models\Admin\Permission::class),
360
                    ],
361
                ],
362
                'children' => $this->indexCreateChildren('permission', \Pratiksh\Adminetic\Models\Admin\Permission::class),
363
            ],
364
            [
365
                'type' => 'menu',
366
                'name' => 'Setting',
367
                'icon' => 'fa fa-cog',
368
                'is_active' => request()->routeIs('setting*') ? 'active' : '',
369
                'conditions' => [
370
                    [
371
                        'type' => 'or',
372
                        'condition' => auth()->user()->can('view-any', \Pratiksh\Adminetic\Models\Admin\Setting::class),
373
                    ],
374
                    [
375
                        'type' => 'or',
376
                        'condition' => auth()->user()->can('create', \Pratiksh\Adminetic\Models\Admin\Setting::class),
377
                    ],
378
                ],
379
                'children' => $this->indexCreateChildren('setting', \Pratiksh\Adminetic\Models\Admin\Setting::class),
380
            ],
381
            [
382
                'type' => 'menu',
383
                'name' => 'Preference',
384
                'icon' => 'fa fa-wrench',
385
                'is_active' => request()->routeIs('preference*') ? 'active' : '',
386
                'conditions' => [
387
                    [
388
                        'type' => 'or',
389
                        'condition' => auth()->user()->can('view-any', \Pratiksh\Adminetic\Models\Admin\Preference::class),
390
                    ],
391
                    [
392
                        'type' => 'or',
393
                        'condition' => auth()->user()->can('create', \Pratiksh\Adminetic\Models\Admin\Preference::class),
394
                    ],
395
                ],
396
                'children' => $this->indexCreateChildren('preference', \Pratiksh\Adminetic\Models\Admin\Preference::class),
397
            ],
398
            [
399
                'type' => 'link',
400
                'name' => 'Activities',
401
                'icon' => 'fa fa-book',
402
                'is_active' => request()->routeIs('activity*') ? 'active' : '',
403
                'link' => adminRedirectRoute('activity'),
404
                'conditions' => [
405
                    [
406
                        'type' => 'and',
407
                        'condition' => auth()->user()->hasRole('admin'),
408
                    ],
409
                ],
410
            ],
411
        ];
412
    }
413
414
    public function clientMenus(): array
415
    {
416
        $myMenu = config('adminetic.myMenu', \App\Services\MyMenu::class);
0 ignored issues
show
Bug introduced by
The type App\Services\MyMenu 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...
417
        if (class_exists($myMenu)) {
418
            if (method_exists($myMenu, 'myMenu')) {
419
                $menu = new $myMenu;
420
                if (is_array($menu->myMenu())) {
421
                    return $menu->myMenu();
422
                } else {
423
                    throw new Exception('myMenu method return type must be an array.');
424
                }
425
            } else {
426
                throw new Exception('myMenu method is not found', 1);
427
            }
428
        } else {
429
            throw new Exception('Given class namespace is not found');
430
        }
431
    }
432
433
    public function pluginMenus(): array
434
    {
435
        $pluginMenu = array();
436
        if (count($this->getAdapters()) > 0) {
437
            foreach ($this->getAdapters() as $adapter) {
438
                $pluginMenu = array_merge($pluginMenu, $adapter->myMenu());
439
            }
440
        }
441
        return $pluginMenu;
442
    }
443
444
    public function getAdapters(): array
445
    {
446
        $adapters = array();
447
        foreach (config('adminetic.adapters', array()) as $adapter) {
448
            if (class_exists($adapter)) {
449
                $init_adapter = new $adapter;
450
                $adapters[] = $init_adapter;
451
            }
452
        }
453
        return $adapters;
454
    }
455
456
    private function indexCreateChildren($route, $class)
457
    {
458
        $name = Str::ucfirst($route);
459
        $plural = Str::plural($name);
460
461
        $children = [
462
            [
463
                'type' => 'submenu',
464
                'name' => 'All ' . $plural,
465
                'is_active' => request()->routeIs($route . '.index') ? 'active' : '',
466
                'link' => adminRedirectRoute($route),
467
                'conditions' => [
468
                    [
469
                        'type' => 'or',
470
                        'condition' => auth()->user()->can('view-any', $class),
471
                    ],
472
                ],
473
            ],
474
            [
475
                'type' => 'submenu',
476
                'name' => 'Create ' . $route,
477
                'is_active' => request()->routeIs($route . '.create') ? 'active' : '',
478
                'link' => adminCreateRoute($route),
479
                'conditions' => [
480
                    [
481
                        'type' => 'or',
482
                        'condition' => auth()->user()->can('create', $class),
483
                    ],
484
                ],
485
            ],
486
        ];
487
488
        return $children;
489
    }
490
}
491