-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuTree.php
53 lines (43 loc) · 1.15 KB
/
MenuTree.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
<?php
namespace alex290\treemenu;
use yii\base\Widget;
use yii\helpers\Url;
/**
* Description of NavHover
*
* @author art
*/
class MenuTree extends Widget {
public $arrMenu;
public function run() {
$arrMenuTree = $this->getTree();
$templ = '<ul class="nav navbar-nav">';
$templ .= $this->getMenuHtml($arrMenuTree);
$templ .= '</ul>';
return $templ;
}
protected function getMenuHtml($treesMenu){
$tree = '';
foreach ($treesMenu as $treeMenu) {
$tree .= $this->catToTemplate($treeMenu);
}
return $tree;
}
protected function catToTemplate($category){
ob_start();
include __DIR__ . '/menu_tpl/menu.php';
return ob_get_clean();
}
protected function getTree() {
$tree = [];
$catstree = $this->arrMenu;
foreach ($catstree as $id => &$node) {
if (!$node['parent_id'])
$tree[$id] = &$node;
else
$catstree[$node['parent_id']]['childs'][$node['id']] = &$node;
}
$treeOne = $tree;
return $treeOne;
}
}