|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PiouPiou\RibsAdminBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use PiouPiou\RibsAdminBundle\Entity\Module; |
|
6
|
|
|
use PiouPiou\RibsAdminBundle\Service\AccessRights; |
|
7
|
|
|
use PiouPiou\RibsAdminBundle\Service\Globals; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
|
|
11
|
|
|
class NavigationBuilderController extends AbstractController |
|
12
|
|
|
{ |
|
13
|
|
|
private $nav = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* function that display the left navigation mapped by user rights |
|
17
|
|
|
* @param Globals $globals |
|
18
|
|
|
* @param AccessRights $access_rights |
|
19
|
|
|
* @return Response |
|
20
|
|
|
*/ |
|
21
|
|
|
public function getLeftNavigation(Globals $globals, AccessRights $access_rights): Response |
|
22
|
|
|
{ |
|
23
|
|
|
$navigation = json_decode(file_get_contents($globals->getBaseBundlePath() . "/Resources/json/navigation.json"), true); |
|
24
|
|
|
|
|
25
|
|
|
foreach ($navigation["items"] as $item) { |
|
26
|
|
|
if ($access_rights->testRight($item["right"]) && (!isset($item["position"]) || $item["position"] === "left")) { |
|
27
|
|
|
$this->nav[] = $item; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$this->getModuleNavigation($access_rights); |
|
32
|
|
|
|
|
33
|
|
|
return $this->render("@RibsAdmin/navigation.html.twig", ["navigation" => $this->nav]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* to get all modules navigation and test right navigation |
|
38
|
|
|
* @param AccessRights $access_rights |
|
39
|
|
|
*/ |
|
40
|
|
|
private function getModuleNavigation(AccessRights $access_rights) |
|
41
|
|
|
{ |
|
42
|
|
|
$modules = $this->getDoctrine()->getRepository(Module::class)->findBy([ |
|
43
|
|
|
"active" => true, |
|
44
|
|
|
"displayed" => true |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($modules as $module) { |
|
48
|
|
|
$navigation = json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath |
|
49
|
|
|
($module->getPackageName(), $module->getDevMode()) . "/Resources/json/navigation.json"), true); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($navigation["items"] as $item) { |
|
52
|
|
|
if ($access_rights->testRight($item["right"]) && (!isset($item["position"]) || $item["position"] === "left")) { |
|
53
|
|
|
$this->nav[] = $item; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|