Commit 5780caea9e25eb984c7cac665fbb54c1d637dc50
1 parent
11e2c9ec
+ модель MenuTree
Showing
1 changed file
with
56 additions
and
0 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +use common\models\Menu; | |
6 | + | |
7 | +class MenuTree extends Menu | |
8 | +{ | |
9 | + var $mass = array (); | |
10 | + | |
11 | + public function build ($location_name) | |
12 | + { | |
13 | + if ($this->mass = parent::getMenuList ($location_name)) | |
14 | + { | |
15 | + return $this->getMenuRecrusive (0); | |
16 | + } | |
17 | + } | |
18 | + | |
19 | + public function findChild ($id) | |
20 | + { | |
21 | + $mass = array (); | |
22 | + | |
23 | + foreach ($this->mass as $row) | |
24 | + { | |
25 | + if ($row['menu_pid'] == $id) | |
26 | + { | |
27 | + $mass[] = $row; | |
28 | + } | |
29 | + } | |
30 | + | |
31 | + return $mass; | |
32 | + } | |
33 | + | |
34 | + public function getMenuRecrusive ($menu_id) | |
35 | + { | |
36 | + $items = $this->findChild($menu_id); | |
37 | + | |
38 | + if (! empty ($items)) | |
39 | + { | |
40 | + $result = []; | |
41 | + | |
42 | + foreach ($items as $row) | |
43 | + { | |
44 | + $result[] = [ | |
45 | + 'label' => $row['page_title'], | |
46 | + 'url' => ['/'.$row['page_alias']], | |
47 | + 'items' => $this->getMenuRecrusive($row['menu_id']), | |
48 | + '<li class="divider"></li>', | |
49 | + ]; | |
50 | + } | |
51 | + | |
52 | + return $result; | |
53 | + } | |
54 | + | |
55 | + } | |
56 | +} | ... | ... |