Passed
Push — master ( 99fb41...22b2db )
by Anthony
03:06
created

Navigation::setNavigation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
	namespace core;
3
	class Navigation {
4
		private $navigation;
5
		
6
		
7
		
8
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
9
		public function __construct() {
10
			$dbc = App::getDb();
11
			$navigation = [];
12
13
			$query = $dbc->select()->from("navigation")->orderBy("ordre")->get();
14
15
			if (is_array($query) && (count($query) > 0)) {
16
				foreach ($query as $obj) {
17
					if ($obj->ID_page === null) {
18
						$navigation = $this->getLienNavigationModule($obj->ID_module);
19
					}
20
					else {
21
						$navigation = $this->getLienNavigationPage($obj->ID_page);
22
					}
23
				}
24
25
				$this->setNavigation($navigation);
26
			}
27
		}
28
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
29
		
30
		
31
		
32
		//-------------------------- GETTER ----------------------------------------------------------------------------//
33
		public function getNavigation() {
34
			return $this->navigation;
35
		}
36
37
		private function getLienNavigationPage($id_page) {
38
			$dbc = App::getDb();
39
40
			$query = $dbc->select()
41
				->from("navigation")
42
				->from("page")
43
				->where("navigation.ID_page", "=", "page.ID_page", "AND")
44
				->where("page.ID_page", "=", $id_page)
45
				->where("page.affiche", "=", 1)
46
				->get();
47
48 View Code Duplication
			if (is_array($query) && (count($query) > 0)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
				foreach ($query as $obj) {
50
					return [$obj->titre,$obj->url];
51
				}
52
			}
53
		}
54
55
		private function getLienNavigationModule($id_module) {
56
			$dbc = App::getDb();
57
58
			$query = $dbc->select()
59
				->from("navigation")
60
				->from("module")
61
				->where("navigation.ID_module", "=", "module.ID_module", "AND")
62
				->where("module.ID_module", "=", $id_module)
63
				->where("module.installer", "=", 1)
64
				->where("module.activer", "=", 1)
65
				->get();
66
67 View Code Duplication
			if (is_array($query) && (count($query) > 0)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
				foreach ($query as $obj) {
69
					return [$obj->nom_module,$obj->url];
70
				}
71
			}
72
		}
73
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
74
		
75
		
76
		
77
		//-------------------------- SETTER ----------------------------------------------------------------------------//
78
		private function setNavigation($navigation) {
79
			$this->navigation = $navigation;
80
		}
81
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
82
	}