-
Notifications
You must be signed in to change notification settings - Fork 50
/
Metronic.php
297 lines (252 loc) · 7.16 KB
/
Metronic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
/**
* @link http://www.digitaldeals.cz/
* @copyright Copyright (c) 2014 Digital Deals s.r.o.
* @license http://www.digitaldeals.cz/license/
*/
namespace dlds\metronic;
use dlds\metronic\bundles\IonRangeSliderAsset;
use dlds\metronic\traits\HtmlTrait;
use Yii;
use yii\helpers\Html;
use yii\web\AssetBundle;
use yii\base\InvalidConfigException;
use dlds\metronic\bundles\ThemeAsset;
/**
* This is the class of Metronic Component
*/
class Metronic extends \yii\base\Component
{
/**
* @var AssetBundle
*/
public static $assetsBundle;
/**
* Assets link
*/
const ASSETS_LINK = __DIR__ . '/assets';
/**
* Theme
*/
const VERSION_1 = 'layout';
const VERSION_2 = 'layout2';
const VERSION_3 = 'layout3';
const VERSION_4 = 'layout4';
const VERSION_5 = 'layout5';
const VERSION_6 = 'layout6';
const VERSION_7 = 'layout7';
/**
* Theme
*/
const THEME_DARK = 'default';
const THEME_LIGHT = 'light';
/**
* Style
*/
const STYLE_SQUARE = 'default';
const STYLE_ROUNDED = 'rounded';
const STYLE_MATERIAL = 'material';
/**
* Layout
*/
const LAYOUT_FLUID = 'default';
const LAYOUT_BOXED = 'boxed';
/**
* Header
*/
const HEADER_DEFAULT = 'default';
const HEADER_FIXED = 'fixed';
/**
* Header Dropdowns
*/
const HEADER_DROPDOWN_DARK = 'dark';
const HEADER_DROPDOWN_LIGHT = 'light';
/**
* Sidebar
*/
const SIDEBAR_DEFAULT = 'default';
const SIDEBAR_FIXED = 'fixed';
/**
* Sidebar menu
*/
const SIDEBAR_MENU_ACCORDION = 'accordion';
const SIDEBAR_MENU_HOVER = 'hover';
/**
* Sidebar position
*/
const SIDEBAR_POSITION_LEFT = 'left';
const SIDEBAR_POSITION_RIGHT = 'right';
/**
* Footer
*/
const FOOTER_DEFAULT = 'default';
const FOOTER_FIXED = 'fixed';
/**
* Search string
*/
const PARAM_VERSION = '{version}';
const PARAM_THEME = '{theme}';
/**
* UI Colors blue
*/
const UI_COLOR_BLUE = 'blue';
const UI_COLOR_BLUE_HOKI = 'blue-hoki';
const UI_COLOR_BLUE_STEEL = 'blue-steel';
const UI_COLOR_BLUE_MADISON = 'blue-madison';
const UI_COLOR_BLUE_CHAMBRAY = 'blue-chambray';
const UI_COLOR_BLUE_EBONYCLAY = 'blue-ebonyclay';
/**
* UI Colors green
*/
const UI_COLOR_GREEN = 'green';
const UI_COLOR_GREEN_MEADOW = 'green-meadow';
const UI_COLOR_GREEN_SEAGREEN = 'green-seagreen';
const UI_COLOR_GREEN_TORQUOISE = 'green-torquoise';
const UI_COLOR_GREEN_JUNGLE = 'green-jungle';
const UI_COLOR_GREEN_HAZE = 'green-haze';
/**
* UI Colors red
*/
const UI_COLOR_RED = 'red';
const UI_COLOR_RED_PINK = 'red-pink';
const UI_COLOR_RED_SUNGLO = 'red-sunglo';
const UI_COLOR_RED_INTENSE = 'red-intense';
const UI_COLOR_RED_THUNDERBIRD = 'red-thunderbird';
const UI_COLOR_RED_FLAMINGO = 'red-flamingo';
const UI_COLOR_RED_HAZE = 'red-haze';
/**
* UI Colors yellow
*/
const UI_COLOR_YELLOW = 'yellow';
const UI_COLOR_YELLOW_GOLD = 'yellow-gold';
const UI_COLOR_YELLOW_CASABLANCA = 'yellow-casablanca';
const UI_COLOR_YELLOW_CRUSTA = 'yellow-crusta';
const UI_COLOR_YELLOW_LEMON = 'yellow-lemon';
const UI_COLOR_YELLOW_SAFFRON = 'yellow-saffron';
/**
* UI Colors purple
*/
const UI_COLOR_PURPLE = 'purple';
const UI_COLOR_PURPLE_PLUM = 'purple-plum';
const UI_COLOR_PURPLE_MEDIUM = 'purple-medium';
const UI_COLOR_PURPLE_STUDIO = 'purple-studio';
const UI_COLOR_PURPLE_WISTERIA = 'purple-wisteria';
const UI_COLOR_PURPLE_SEANCE = 'purple-seance';
/**
* UI Colors grey
*/
const UI_COLOR_GREY = 'grey';
const UI_COLOR_GREY_CASCADE = 'grey-cascade';
const UI_COLOR_GREY_SILVER = 'grey-silver';
const UI_COLOR_GREY_STEEL = 'grey-steel';
const UI_COLOR_GREY_CARARRA = 'grey-cararra';
const UI_COLOR_GREY_GALLERY = 'grey-gallery';
/**
* Classes paths
*/
const CLASS_HTML = '@vendor/dlds/yii2-metronic/helpers/Html.php';
/**
* @var string version
*/
public $version = self::VERSION_4;
/**
* @var string Theme
*/
public $theme = self::THEME_LIGHT;
/**
* @var string Theme style
*/
public $style = self::STYLE_ROUNDED;
/**
* @var string Layout mode
*/
public $layoutOption = self::LAYOUT_FLUID;
/**
* @var string Header display
*/
public $headerOption = self::HEADER_FIXED;
/**
* @var string Header dropdowns
*/
public $headerDropdown = self::HEADER_DROPDOWN_DARK;
/**
* @var string Sidebar display
*/
public $sidebarOption = self::SIDEBAR_DEFAULT;
/**
* @var string Sidebar display
*/
public $sidebarMenu = self::SIDEBAR_MENU_ACCORDION;
/**
* @var string Sidebar position
*/
public $sidebarPosition = self::SIDEBAR_POSITION_LEFT;
/**
* @var string Footer display
*/
public $footerOption = self::FOOTER_DEFAULT;
/** @var string IonRangeSlider skin */
public $ionSliderSkin = IonRangeSliderAsset::SKIN_SIMPLE;
/**
* @var array resources paths
*/
public $resources;
/**
* @var string Component name used in the application
*/
public static $componentName = 'metronic';
/**
* Inits module
*/
public function init()
{
if (self::SIDEBAR_FIXED === $this->sidebarOption && self::SIDEBAR_MENU_HOVER === $this->sidebarMenu) {
throw new InvalidConfigException('Hover Sidebar Menu is not compatible with Fixed Sidebar Mode. Select Default Sidebar Mode Instead.');
}
if (!$this->resources) {
throw new InvalidConfigException('You have to specify resources locations to be able to create symbolic links. Specify "admin" and "global" theme folder locations.');
}
if (!is_link(self::ASSETS_LINK) && !is_dir(self::ASSETS_LINK)) {
symlink($this->resources, self::ASSETS_LINK);
}
}
public function parseAssetsParams(&$string)
{
if (preg_match('/\{[a-z]+\}/', $string)) {
$string = str_replace(static::PARAM_VERSION, $this->version, $string);
$string = str_replace(static::PARAM_THEME, $this->theme, $string);
}
}
/**
* @return Metronic Get Metronic component
*/
public static function getComponent()
{
try {
return \Yii::$app->get(static::$componentName);
} catch (InvalidConfigException $ex) {
return null;
}
}
/**
* Get base url to metronic assets
* @param $view View
* @return string
*/
public static function getAssetsUrl($view)
{
if (static::$assetsBundle === null) {
static::$assetsBundle = static::registerThemeAsset($view);
}
return (static::$assetsBundle instanceof AssetBundle) ? static::$assetsBundle->baseUrl : '';
}
/**
* Register Theme Asset
* @param $view View
* @return AssetBundle
*/
public static function registerThemeAsset($view)
{
return static::$assetsBundle = ThemeAsset::register($view);
}
}