SiteMenuHelper.php
3.18 KB
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
<?php
final class SiteMenuHelper
{
private static $_mainMenuItems;
public static function getItems()
{
if (isset(self::$_mainMenuItems)) return self::$_mainMenuItems;
$fixed = array(
array(
'url' => array('action/index'),
'label' => Yii::t('site', 'Акции'),
'active' => "\$controller->id == 'action'",
),
array(
'url' => array('service/index'),
'label' => Yii::t('site', 'Сервис'),
'active' => "\$controller->id == 'service'",
),
array(
'url' => array('site/contact'),
'label' => Yii::t('site', 'Контакты'),
'active' => "\$controller->id == 'site' && \$controller->action->id == 'contact'",
),
array(
'url' => array('stoFilter/index'),
'label' => Yii::t('site', 'Расчет стоимости ТО'),
'active' => "\$controller->id == 'stoFilter'",
),
);
$items = $fixed;
/** @var $rootNodes Node[] */
$rootNodes = Node::model()->with('i18n')->findAll('node_id is null');
$maping = array(
'aboutRoot' => 'about/index',
'jobsSection' => '',
'partnersSection' => '',
'newsRoot' => 'news/index',
'questionRoot' => 'question/index',
'reviewsRoot' => 'reviews/index',
'saleRoot' => 'sale/index',
'sportRoot' => 'sport/index',
'albumsSection' => '',
'calendarSection' => '',
'textRoot' => 'textRoot/index',
'textSection' => '',
'textPage' => '',
'tuningRoot' => 'tuning/index',
'warrantyRoot' => 'warranty/index',
'workRoot' => 'work/index',
);
foreach ($rootNodes as $node) {
$route = $maping[$node->data_type];
if (!empty($route) && !$node->hidden) {
$items[] = array(
'url' => array($route, 'node_id' => $node->id),
'label' => $node->i18n->label,
'active' => 'isset($_GET["node_id"]) && $_GET["node_id"]==' . $node->id,
);
}
}
$res = array();
foreach ($items as $item) {
$res[crc32(serialize($item['url']))] = $item;
}
self::$_mainMenuItems = $res;
return $res;
}
public static function getList()
{
$res = array();
foreach (self::getItems() as $k => $item) {
$res[$k] = $item['label'];
}
return $res;
}
/**
* @static
* @param $selected
* @return array
*/
public static function getListWithSelected($selected)
{
$items = self::getList();
if (empty($selected)) return $items;
$res = array();
foreach ($selected as $i)
if (!empty($items[$i])) {
$res[$i] = $items[$i];
unset($items[$i]);
} else {
unset($items[$i]);
}
$res += $items;
return $res;
}
}