forked from pceuropa/yii2-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.php
executable file
·60 lines (43 loc) · 1.4 KB
/
Menu.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
<?php
namespace pceuropa\menu;
#Copyright (c) 2017 Rafal Marguzewicz pceuropa.net
use Yii;
use yii\helpers\Html;
use yii\helpers\Json;
use pceuropa\menu\models\Model;
class Menu extends \yii\base\Module {
public $controllerNamespace = 'pceuropa\menu\controllers';
public $defaultRoute = 'creator';
public function init(){
parent::init(); // custom initialization code goes here
}
public static function NavbarLeft($id){
return self::processNavbar($id, 'left');
}
public static function NavbarRight($id){
return self::processNavbar($id, 'right');
}
protected static function processNavbar($id, $pos)
{
$m = Model::findModel($id);
$m = Json::decode($m->menu);
//$data = self::checkIcon($m[$pos]);
return $m[$pos];
}
protected static function checkIcon($array){
$result = [];
foreach ($array as $item){
if (array_key_exists('icon', $item)){
$glyph = Html::tag('i', '',
['class' => sprintf("glyphicon glyphicon-%s", $item['icon'])]
);
$item['label'] = sprintf('%s %s', $glyph, $item['label']);
}
if (array_key_exists('items', $item)){
$item['items'] = self::checkIcon($item['items']);
}
$result[] = $item;
}
return $result;
}
}