Completed
Pull Request — master (#610)
by Diego
03:35
created

LayoutHelper::makeRightSidebarClasses()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 5
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 0
crap 3
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Helpers;
4
5
use Illuminate\Support\Facades\View;
6
7
class LayoutHelper
8
{
9
    /**
10
     * Set of tokens related to screen sizes.
11
     *
12
     * @var array
13
     */
14
    protected static $screenSizes = ['xs', 'sm', 'md', 'lg', 'xl'];
15
16
    /**
17
     * Check if layout topnav is enabled.
18
     *
19
     * @return boolean
20
     */
21 1
    public static function isLayoutTopnavEnabled()
22
    {
23 1
        return config('adminlte.layout_topnav') || View::getSection('layout_topnav');
24
    }
25
26
    /**
27
     * Check if layout boxed is enabled.
28
     *
29
     * @return boolean
30
     */
31 1
    public static function isLayoutBoxedEnabled()
32
    {
33 1
        return config('adminlte.layout_boxed') || View::getSection('layout_boxed');
34
    }
35
36
    /**
37
     * Make and return the set of classes related to the body tag.
38
     *
39
     * @return string
40
     */
41 1
    public static function makeBodyClasses()
42
    {
43 1
        $classes = [];
44
45 1
        $classes = array_merge($classes, self::makeLayoutClasses());
46 1
        $classes = array_merge($classes, self::makeSidebarClasses());
47 1
        $classes = array_merge($classes, self::makeRightSidebarClasses());
48 1
        $classes = array_merge($classes, self::makeCustomBodyClasses());
49
50 1
        return trim(implode(' ', $classes));
51
    }
52
53
    /**
54
     * Make and return the set of data attributes related to the body tag.
55
     *
56
     * @return string
57
     */
58 1
    public static function makeBodyData()
59
    {
60 1
        $data = [];
61
62
        // Add data related to the "sidebar_scrollbar_theme" configuration.
63
64 1
        $sb_theme_cfg = config('adminlte.sidebar_scrollbar_theme', 'os-theme-light');
65
66 1
        if ($sb_theme_cfg != 'os-theme-light') {
67 1
            $data[] = 'data-scrollbar-theme='.$sb_theme_cfg;
68
        }
69
70
        // Add data related to the "sidebar_scrollbar_auto_hide" configuration.
71
72 1
        $sb_auto_hide = config('adminlte.sidebar_scrollbar_auto_hide', 'l');
73
74 1
        if ($sb_auto_hide != 'l') {
75 1
            $data[] = 'data-scrollbar-auto-hide='.$sb_auto_hide;
76
        }
77
78 1
        return trim(implode(' ', $data));
79
    }
80
81
    /**
82
     * Make and return the set of classes related to the layout configuration.
83
     *
84
     * @return array
85
     */
86 1
    private static function makeLayoutClasses()
87
    {
88 1
        $classes = [];
89
90
        // Add classes related to the "layout_topnav" configuration.
91
92 1
        if (self::isLayoutTopnavEnabled()) {
93 1
            $classes[] = 'layout-top-nav';
94
        }
95
96
        // Add classes related to the "layout_boxed" configuration.
97
98 1
        if (self::isLayoutBoxedEnabled()) {
99 1
            $classes[] = 'layout-boxed';
100
        }
101
102
        // Add classes related to fixed sidebar layout configuration. The fixed
103
        // sidebar is not compatible with layout topnav.
104
105 1
        if (! self::isLayoutTopnavEnabled() && config('adminlte.layout_fixed_sidebar')) {
106 1
            $classes[] = 'layout-fixed';
107
        }
108
109
        // Add classes related to fixed navbar/footer configuration. The fixed
110
        // navbar/footer is not compatible with layout boxed.
111
112 1
        if (! self::isLayoutBoxedEnabled()) {
113 1
            $classes = array_merge($classes, self::makeFixedResponsiveClasses('navbar'));
114 1
            $classes = array_merge($classes, self::makeFixedResponsiveClasses('footer'));
115
        }
116
117 1
        return $classes;
118
    }
119
120
    /**
121
     * Make the set of classes related to a fixed responsive configuration.
122
     *
123
     * @param string $section
124
     * @return array
125
     */
126 1
    private static function makeFixedResponsiveClasses($section)
127
    {
128 1
        $classes = [];
129 1
        $cfg = config('adminlte.layout_fixed_'.$section);
130
131 1
        if ($cfg === true) {
132 1
            $classes[] = 'layout-'.$section.'-fixed';
133 1
        } elseif (is_array($cfg)) {
134 1
            foreach ($cfg as $size => $enabled) {
135 1
                if (in_array($size, self::$screenSizes)) {
136 1
                    $size = $size == 'xs' ? '' : '-'.$size;
137 1
                    $classes[] = $enabled == true ?
138 1
                        'layout'.$size.'-'.$section.'-fixed' :
139 1
                        'layout'.$size.'-'.$section.'-not-fixed';
140
                }
141
            }
142
        }
143
144 1
        return $classes;
145
    }
146
147
    /**
148
     * Make the set of classes related to the left sidebar configuration.
149
     *
150
     * @return array
151
     */
152 1
    private static function makeSidebarClasses()
153
    {
154 1
        $classes = [];
155
156
        // Add classes related to the "sidebar_mini" configuration.
157
158 1
        if (config('adminlte.sidebar_mini', true) === true) {
159 1
            $classes[] = 'sidebar-mini';
160 1
        } elseif (config('adminlte.sidebar_mini', true) == 'md') {
161 1
            $classes[] = 'sidebar-mini sidebar-mini-md';
162
        }
163
164
        // Add classes related to the "sidebar_collapse" configuration.
165
166 1
        if (config('adminlte.sidebar_collapse') || View::getSection('sidebar_collapse')) {
167 1
            $classes[] = 'sidebar-collapse';
168
        }
169
170 1
        return $classes;
171
    }
172
173
    /**
174
     * Make the set of classes related to the right sidebar configuration.
175
     *
176
     * @return array
177
     */
178 1
    private static function makeRightSidebarClasses()
179
    {
180 1
        $classes = [];
181
182
        // Add classes related to the "right_sidebar" configuration.
183
184 1
        if (config('adminlte.right_sidebar') && config('adminlte.right_sidebar_push')) {
185 1
            $classes[] = 'control-sidebar-push';
186
        }
187
188 1
        return $classes;
189
    }
190
191
    /**
192
     * Make the set of classes related to custom body classes configuration.
193
     *
194
     * @return array
195
     */
196 1
    private static function makeCustomBodyClasses()
197
    {
198 1
        $classes = [];
199 1
        $cfg = config('adminlte.classes_body', '');
200
201 1
        if (is_string($cfg) && $cfg) {
202 1
            $classes[] = $cfg;
203
        }
204
205 1
        return $classes;
206
    }
207
}
208