Passed
Push — master ( ca8acb...66a67e )
by Anthony
03:29
created

NavigationBuilderController::getModuleNavigation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Controller;
4
5
use PiouPiou\RibsAdminBundle\Entity\Module;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class NavigationBuilderController extends Controller
10
{
11
	private  $nav = [];
12
	
13
	/**
14
	 * @return Response function that display the left navigation mapped by user rights
15
	 */
16
	public function getLeftNavigationAction(): Response
17
	{
18
		$navigation = json_decode(file_get_contents($this->get("ribs_admin.globals")->getBaseBundlePath() . "/Resources/json/navigation.json"), true);
19
		
20
		foreach ($navigation["items"] as $item) {
21
			if ($this->get("ribs_admin.acess_rights")->testRight($item["right"])) {
22
				$this->nav[] = $item;
23
			}
24
		}
25
		
26
		$this->getModuleNavigation();
27
		
28
		return $this->render("@RibsAdmin/navigation.html.twig", ["navigation" => $this->nav]);
29
	}
30
	
31
	/**
32
	 * to get all modules navigation and test right navigation
33
	 */
34
	private function getModuleNavigation()
35
	{
36
		$modules = $this->getDoctrine()->getRepository(Module::class)->findBy([
37
			"active" => true,
38
			"displayed" => true
39
		]);
40
		
41
		foreach ($modules as $module) {
42
			$this->nav[] = [
43
				"right" => "ribsadmin@blog",
44
				"url" => "ribsadmin_index",
45
				"icon" => "",
46
				"text" => $module->getTitle()
47
			];
48
		}
49
	}
50
}