Passed
Push — master ( 01ef95...06f42e )
by Anthony
03:39
created

Navigation::setAjoutLien()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
	namespace core;
3
	class Navigation {
4
		private $navigation;
5
		private $last_ordre;
6
		
7
		
8
		
9
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
10
		public function __construct($no_module = null) {
11
			$dbc = App::getDb();
12
			$navigation = [];
13
			$last_ordre = "";
14
15
			if($no_module === null) {
16
				$query = $dbc->select()->from("navigation")->orderBy("ordre")->get();
17
			}
18
			else {
19
				$query = $dbc->select()->from("navigation")->where("ID_page", " IS NOT ", "NULL")->orderBy("ordre")->get();
20
			}
21
22
			if (is_array($query) && (count($query) > 0)) {
23
				foreach ($query as $obj) {
24
					if ($obj->ID_page === null) {
25
						$navigation[] = $this->getLienNavigationModule($obj->ID_module);
26
					}
27
					else {
28
						$navigation[] = $this->getLienNavigationPage($obj->ID_page);
29
					}
30
					$last_ordre = $obj->ordre;
31
				}
32
33
				$this->last_ordre = $last_ordre;
34
				$this->setNavigation($navigation);
35
			}
36
		}
37
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
38
		
39
		
40
		
41
		//-------------------------- GETTER ----------------------------------------------------------------------------//
42
		public function getNavigation() {
43
			return $this->navigation;
44
		}
45
46
		private function getLienNavigationPage($id_page) {
47
			$dbc = App::getDb();
48
49
			$query = $dbc->select()
50
				->from("navigation")
51
				->from("page")
52
				->where("navigation.ID_page", "=", "page.ID_page", "AND")
53
				->where("page.ID_page", "=", $id_page, "AND")
54
				->where("page.affiche", "=", 1, "AND")
55
				->where("page.parent", "=", 0)
56
				->get();
57
58 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...
59
				foreach ($query as $obj) {
60
					return [$obj->ID_page, $obj->titre, $obj->url, $obj->balise_title, $this->getSousMenu($id_page)];
61
				}
62
			}
63
		}
64
65
		private function getSousMenu($id_page) {
66
			$dbc = App::getDb();
67
			$sous_menu = [];
68
69
			$query = $dbc->select()
70
				->from("page")
71
				->where("parent", "=", $id_page, "AND")
72
				->where("affiche", "=", 1)
73
				->get();
74
75 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...
76
				foreach ($query as $obj) {
77
					$sous_menu[] = [$obj->ID_page, $obj->titre, $obj->url, $obj->balise_title,];
78
				}
79
			}
80
81
			return $sous_menu;
82
		}
83
84
		private function getLienNavigationModule($id_module) {
85
			$dbc = App::getDb();
86
87
			$query = $dbc->select()
88
				->from("navigation")
89
				->from("module")
90
				->where("navigation.ID_module", "=", "module.ID_module", "AND")
91
				->where("module.ID_module", "=", $id_module, "AND")
92
				->where("module.installer", "=", 1, "AND")
93
				->where("module.activer", "=", 1)
94
				->get();
95
96
			if (is_array($query) && (count($query) > 0)) {
97
				foreach ($query as $obj) {
98
					return [$obj->ID_module, $obj->nom_module, $obj->url];
99
				}
100
			}
101
		}
102
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
103
		
104
		
105
		
106
		//-------------------------- SETTER ----------------------------------------------------------------------------//
107
		private function setNavigation($navigation) {
108
			$this->navigation = $navigation;
109
		}
110
111
		public function setAjoutLien($id, $value_id) {
112
			$dbc = App::getDb();
113
114
			$dbc->insert($id, $value_id)->insert("ordre", $this->last_ordre+1)->into("navigation")->set();
115
		}
116
117
		public function setSupprimerLien($id, $value_id) {
118
			$dbc = App::getDb();
119
120
			$dbc->delete()->from("navigation")->where($id, "=", $value_id)->del();
121
		}
122
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
123
	}