1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Container\Container; |
6
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
7
|
|
|
use Illuminate\Support\Facades\View; |
8
|
|
|
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu; |
9
|
|
|
use JeroenNoten\LaravelAdminLte\Menu\Builder; |
10
|
|
|
|
11
|
|
|
class AdminLte |
12
|
|
|
{ |
13
|
|
|
protected $menu; |
14
|
|
|
|
15
|
|
|
protected $filters; |
16
|
|
|
|
17
|
|
|
protected $events; |
18
|
|
|
|
19
|
|
|
protected $container; |
20
|
|
|
|
21
|
1 |
|
public function __construct( |
22
|
|
|
array $filters, |
23
|
|
|
Dispatcher $events, |
24
|
|
|
Container $container |
25
|
|
|
) { |
26
|
1 |
|
$this->filters = $filters; |
27
|
1 |
|
$this->events = $events; |
28
|
1 |
|
$this->container = $container; |
29
|
1 |
|
} |
30
|
|
|
|
31
|
1 |
|
public function menu() |
32
|
|
|
{ |
33
|
1 |
|
if (! $this->menu) { |
34
|
1 |
|
$this->menu = $this->buildMenu(); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
return $this->menu; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Gets the body classes, in relation to the config options. |
42
|
|
|
*/ |
43
|
|
|
public function getBodyClasses() |
44
|
|
|
{ |
45
|
|
|
$body_classes = []; |
46
|
|
|
$screen_sizes = ['xs', 'sm', 'md', 'lg', 'xl']; |
47
|
|
|
|
48
|
|
|
// Add classes related to the "sidebar_mini" configuration. |
49
|
|
|
|
50
|
|
|
if (config('adminlte.sidebar_mini', true) === true) { |
51
|
|
|
$body_classes[] = 'sidebar-mini'; |
52
|
|
|
} elseif (config('adminlte.sidebar_mini', true) == 'md') { |
53
|
|
|
$body_classes[] = 'sidebar-mini sidebar-mini-md'; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Add classes related to the "layout_topnav" configuration. |
57
|
|
|
|
58
|
|
|
if (config('adminlte.layout_topnav') || View::getSection('layout_topnav')) { |
59
|
|
|
$body_classes[] = 'layout-top-nav'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// Add classes related to the "layout_boxed" configuration. |
63
|
|
|
|
64
|
|
|
if (config('adminlte.layout_boxed') || View::getSection('layout_boxed')) { |
65
|
|
|
$body_classes[] = 'layout-boxed'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// Add classes related to the "sidebar_collapse" configuration. |
69
|
|
|
|
70
|
|
|
if (config('adminlte.sidebar_collapse') || View::getSection('sidebar_collapse')) { |
71
|
|
|
$body_classes[] = 'sidebar-collapse'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// Add classes related to the "right_sidebar" configuration. |
75
|
|
|
|
76
|
|
|
if (config('adminlte.right_sidebar') && config('adminlte.right_sidebar_push')) { |
77
|
|
|
$body_classes[] = 'control-sidebar-push'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// Add classes related to fixed sidebar, these are not compatible with |
81
|
|
|
// "layout_topnav". |
82
|
|
|
|
83
|
|
|
if (! config('adminlte.layout_topnav') && ! View::getSection('layout_topnav')) { |
84
|
|
|
|
85
|
|
|
// Check for fixed sidebar configuration. |
86
|
|
|
|
87
|
|
|
if (config('adminlte.layout_fixed_sidebar')) { |
88
|
|
|
$body_classes[] = 'layout-fixed'; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
// Add classes related to fixed footer and navbar, these are not |
93
|
|
|
// compatible with "layout_boxed". |
94
|
|
|
|
95
|
|
|
if (! config('adminlte.layout_boxed') && ! View::getSection('layout_boxed')) { |
96
|
|
|
|
97
|
|
|
// Check for fixed navbar configuration. |
98
|
|
|
|
99
|
|
|
$fixed_navbar_cfg = config('adminlte.layout_fixed_navbar'); |
100
|
|
|
|
101
|
|
View Code Duplication |
if ($fixed_navbar_cfg === true) { |
|
|
|
|
102
|
|
|
$body_classes[] = 'layout-navbar-fixed'; |
103
|
|
|
} elseif (is_array($fixed_navbar_cfg)) { |
104
|
|
|
foreach ($fixed_navbar_cfg as $size => $enabled) { |
105
|
|
|
if (in_array($size, $screen_sizes)) { |
106
|
|
|
$size = $size == 'xs' ? '' : '-'.$size; |
107
|
|
|
$body_classes[] = $enabled == true ? |
108
|
|
|
'layout'.$size.'-navbar-fixed' : |
109
|
|
|
'layout'.$size.'-navbar-not-fixed'; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// Check for fixed footer configuration. |
115
|
|
|
|
116
|
|
|
$fixed_footer_cfg = config('adminlte.layout_fixed_footer'); |
117
|
|
|
|
118
|
|
View Code Duplication |
if ($fixed_footer_cfg === true) { |
|
|
|
|
119
|
|
|
$body_classes[] = 'layout-footer-fixed'; |
120
|
|
|
} elseif (is_array($fixed_footer_cfg)) { |
121
|
|
|
foreach ($fixed_footer_cfg as $size => $enabled) { |
122
|
|
|
if (in_array($size, $screen_sizes)) { |
123
|
|
|
$size = $size == 'xs' ? '' : '-'.$size; |
124
|
|
|
$body_classes[] = $enabled == true ? |
125
|
|
|
'layout'.$size.'-footer-fixed' : |
126
|
|
|
'layout'.$size.'-footer-not-fixed'; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
// Add custom classes, related to the "classes_body" configuration. |
133
|
|
|
|
134
|
|
|
$body_classes[] = config('adminlte.classes_body', ''); |
135
|
|
|
|
136
|
|
|
// Return the set of configured classes for the body tag. |
137
|
|
|
|
138
|
|
|
return trim(implode(' ', $body_classes)); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Gets the body data attributes, in relation to the config options. |
143
|
|
|
*/ |
144
|
|
|
public function getBodyData() |
145
|
|
|
{ |
146
|
|
|
$body_data = []; |
147
|
|
|
|
148
|
|
|
// Add data related to the "sidebar_scrollbar_theme" configuration. |
149
|
|
|
|
150
|
|
|
$sb_theme_cfg = config('adminlte.sidebar_scrollbar_theme', 'os-theme-light'); |
151
|
|
|
|
152
|
|
|
if ($sb_theme_cfg != 'os-theme-light') { |
153
|
|
|
$body_data[] = 'data-scrollbar-theme='.$sb_theme_cfg; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
// Add data related to the "sidebar_scrollbar_auto_hide" configuration. |
157
|
|
|
|
158
|
|
|
$sb_auto_hide = config('adminlte.sidebar_scrollbar_auto_hide', 'l'); |
159
|
|
|
|
160
|
|
|
if ($sb_auto_hide != 'l') { |
161
|
|
|
$body_data[] = 'data-scrollbar-auto-hide='.$sb_auto_hide; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return trim(implode(' ', $body_data)); |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
protected function buildMenu() |
168
|
|
|
{ |
169
|
1 |
|
$builder = new Builder($this->buildFilters()); |
170
|
|
|
|
171
|
1 |
|
$this->events->dispatch(new BuildingMenu($builder)); |
172
|
|
|
|
173
|
1 |
|
return $builder->menu; |
174
|
|
|
} |
175
|
|
|
|
176
|
1 |
|
protected function buildFilters() |
177
|
|
|
{ |
178
|
1 |
|
return array_map([$this->container, 'make'], $this->filters); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
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.