|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Menu; |
|
5
|
|
|
|
|
6
|
|
|
use Chamilo\PageBundle\Entity\Page; |
|
7
|
|
|
use Chamilo\PageBundle\Entity\Site; |
|
8
|
|
|
use Knp\Menu\FactoryInterface; |
|
9
|
|
|
use Knp\Menu\ItemInterface; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class NavBuilder. |
|
15
|
|
|
* |
|
16
|
|
|
* @package Chamilo\CoreBundle\Menu |
|
17
|
|
|
*/ |
|
18
|
|
|
class NavBuilder implements ContainerAwareInterface |
|
19
|
|
|
{ |
|
20
|
|
|
use ContainerAwareTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param array $itemOptions The options given to the created menuItem |
|
24
|
|
|
* @param string $currentUri The current URI |
|
25
|
|
|
* |
|
26
|
|
|
* @return ItemInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
public function createCategoryMenu(array $itemOptions = [], $currentUri = null) |
|
29
|
|
|
{ |
|
30
|
|
|
$factory = $this->container->get('knp_menu.factory'); |
|
31
|
|
|
$menu = $factory->createItem('categories', $itemOptions); |
|
32
|
|
|
|
|
33
|
|
|
$this->buildCategoryMenu($menu, $itemOptions, $currentUri); |
|
34
|
|
|
|
|
35
|
|
|
return $menu; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param ItemInterface $menu The item to fill with $routes |
|
40
|
|
|
* @param array $options The item options |
|
41
|
|
|
* @param string $currentUri The current URI |
|
42
|
|
|
*/ |
|
43
|
|
|
public function buildCategoryMenu(ItemInterface $menu, array $options = [], $currentUri = null) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
//$categories = $this->categoryManager->getCategoryTree(); |
|
46
|
|
|
|
|
47
|
|
|
//$this->fillMenu($menu, $categories, $options, $currentUri); |
|
48
|
|
|
$menu->addChild('home', ['route' => 'home']); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Top menu left. |
|
53
|
|
|
* |
|
54
|
|
|
* @param FactoryInterface $factory |
|
55
|
|
|
* @param array $options |
|
56
|
|
|
* |
|
57
|
|
|
* @return ItemInterface |
|
58
|
|
|
*/ |
|
59
|
|
|
public function leftMenu(FactoryInterface $factory, array $options) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$checker = $this->container->get('security.authorization_checker'); |
|
62
|
|
|
$translator = $this->container->get('translator'); |
|
63
|
|
|
|
|
64
|
|
|
$menu = $factory->createItem('root'); |
|
65
|
|
|
$menu->setChildrenAttribute('class', 'nav navbar-nav'); |
|
66
|
|
|
$menu->addChild( |
|
67
|
|
|
$translator->trans('Home'), |
|
68
|
|
|
[ |
|
69
|
|
|
'route' => 'legacy_index', |
|
70
|
|
|
] |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
if ($checker && $checker->isGranted('IS_AUTHENTICATED_FULLY')) { |
|
74
|
|
|
$menu->addChild( |
|
75
|
|
|
$translator->trans('MyCourses'), |
|
76
|
|
|
[ |
|
77
|
|
|
'route' => 'main', |
|
78
|
|
|
'routeParameters' => [ |
|
79
|
|
|
'name' => '../user_portal.php', |
|
80
|
|
|
], |
|
81
|
|
|
] |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$menu->addChild( |
|
85
|
|
|
$translator->trans('Calendar'), |
|
86
|
|
|
[ |
|
87
|
|
|
'route' => 'main', |
|
88
|
|
|
'routeParameters' => [ |
|
89
|
|
|
'name' => 'calendar/agenda_js.php', |
|
90
|
|
|
], |
|
91
|
|
|
] |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
$menu->addChild( |
|
95
|
|
|
$translator->trans('Reporting'), |
|
96
|
|
|
[ |
|
97
|
|
|
'route' => 'main', |
|
98
|
|
|
'routeParameters' => [ |
|
99
|
|
|
'name' => 'mySpace/index.php', |
|
100
|
|
|
], |
|
101
|
|
|
] |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$menu->addChild( |
|
105
|
|
|
$translator->trans('Social'), |
|
106
|
|
|
[ |
|
107
|
|
|
'route' => 'main', |
|
108
|
|
|
'routeParameters' => [ |
|
109
|
|
|
'name' => 'social/home.php', |
|
110
|
|
|
], |
|
111
|
|
|
] |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
if ($checker->isGranted('ROLE_ADMIN')) { |
|
115
|
|
|
$menu->addChild( |
|
116
|
|
|
$translator->trans('Dashboard'), |
|
117
|
|
|
[ |
|
118
|
|
|
'route' => 'main', |
|
119
|
|
|
'routeParameters' => [ |
|
120
|
|
|
'name' => 'dashboard/index.php', |
|
121
|
|
|
], |
|
122
|
|
|
] |
|
123
|
|
|
); |
|
124
|
|
|
$menu->addChild( |
|
125
|
|
|
$translator->trans('Administration'), |
|
126
|
|
|
[ |
|
127
|
|
|
'route' => 'main', |
|
128
|
|
|
'routeParameters' => [ |
|
129
|
|
|
'name' => 'admin/index.php', |
|
130
|
|
|
], |
|
131
|
|
|
] |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$categories = $this->container->get('Chamilo\FaqBundle\Repository\CategoryRepository')->retrieveActive(); |
|
137
|
|
|
if ($categories) { |
|
138
|
|
|
$faq = $menu->addChild( |
|
139
|
|
|
'FAQ', |
|
140
|
|
|
[ |
|
141
|
|
|
'route' => 'faq_index', |
|
142
|
|
|
] |
|
143
|
|
|
); |
|
144
|
|
|
/** @var Category $category */ |
|
145
|
|
|
foreach ($categories as $category) { |
|
146
|
|
|
$faq->addChild( |
|
147
|
|
|
$category->getHeadline(), |
|
148
|
|
|
[ |
|
149
|
|
|
'route' => 'faq', |
|
150
|
|
|
'routeParameters' => [ |
|
151
|
|
|
'categorySlug' => $category->getSlug(), |
|
152
|
|
|
'questionSlug' => '', |
|
153
|
|
|
], |
|
154
|
|
|
] |
|
155
|
|
|
)->setAttribute('divider_append', true); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
// Getting site information |
|
160
|
|
|
$site = $this->container->get('sonata.page.site.selector'); |
|
161
|
|
|
$host = $site->getRequestContext()->getHost(); |
|
162
|
|
|
$siteManager = $this->container->get('sonata.page.manager.site'); |
|
163
|
|
|
/** @var Site $site */ |
|
164
|
|
|
$site = $siteManager->findOneBy([ |
|
165
|
|
|
'host' => [$host, 'localhost'], |
|
166
|
|
|
'enabled' => true, |
|
167
|
|
|
]); |
|
168
|
|
|
|
|
169
|
|
|
if ($site) { |
|
|
|
|
|
|
170
|
|
|
$pageManager = $this->container->get('sonata.page.manager.page'); |
|
171
|
|
|
|
|
172
|
|
|
// Parents only of homepage |
|
173
|
|
|
$criteria = ['site' => $site, 'enabled' => true, 'parent' => 1]; |
|
174
|
|
|
$pages = $pageManager->findBy($criteria); |
|
175
|
|
|
|
|
176
|
|
|
//$pages = $pageManager->loadPages($site); |
|
177
|
|
|
/** @var Page $page */ |
|
178
|
|
|
foreach ($pages as $page) { |
|
179
|
|
|
/*if ($page->getRouteName() !== 'page_slug') { |
|
180
|
|
|
continue; |
|
181
|
|
|
}*/ |
|
182
|
|
|
|
|
183
|
|
|
// Avoid home |
|
184
|
|
|
if ($page->getUrl() === '/') { |
|
185
|
|
|
continue; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
if (!$page->isCms()) { |
|
189
|
|
|
continue; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
$subMenu = $menu->addChild( |
|
193
|
|
|
$page->getName(), |
|
194
|
|
|
[ |
|
195
|
|
|
'route' => $page->getRouteName(), |
|
196
|
|
|
'routeParameters' => [ |
|
197
|
|
|
'path' => $page->getUrl(), |
|
198
|
|
|
], |
|
199
|
|
|
] |
|
200
|
|
|
); |
|
201
|
|
|
|
|
202
|
|
|
/** @var Page $child */ |
|
203
|
|
|
foreach ($page->getChildren() as $child) { |
|
204
|
|
|
$subMenu->addChild( |
|
205
|
|
|
$child->getName(), |
|
206
|
|
|
[ |
|
207
|
|
|
'route' => $page->getRouteName(), |
|
208
|
|
|
'routeParameters' => [ |
|
209
|
|
|
'path' => $child->getUrl(), |
|
210
|
|
|
], |
|
211
|
|
|
] |
|
212
|
|
|
)->setAttribute('divider_append', true); |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
return $menu; |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.