1
|
|
|
<?php |
2
|
|
|
namespace core; |
3
|
|
|
use core\functions\ChaineCaractere; |
4
|
|
|
|
5
|
|
|
class Navigation { |
6
|
|
|
private $last_ordre; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
11
|
|
|
/** |
12
|
|
|
* Navigation constructor. |
13
|
|
|
* @param null $no_module |
14
|
|
|
* to init get navigation link (if no module != null) whe only get page it's for admin content gestion pages |
15
|
|
|
*/ |
16
|
|
|
public function __construct($no_module = null) { |
17
|
|
|
$dbc = App::getDb(); |
18
|
|
|
|
19
|
|
|
if ($no_module === null) { |
20
|
|
|
$query = $dbc->select()->from("navigation")->orderBy("ordre")->get(); |
21
|
|
|
} |
22
|
|
|
else { |
23
|
|
|
$query = $dbc->select()->from("navigation")->where("ID_page", " IS NOT ", "NULL", "", true)->orderBy("ordre")->get(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if (count($query) > 0) { |
27
|
|
|
$this->setNavigation($query); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
|
34
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
35
|
|
|
/** |
36
|
|
|
* @param $id_page |
37
|
|
|
* @return array |
38
|
|
|
* to get the navigation link of pages of the website |
39
|
|
|
*/ |
40
|
|
|
private function getLienNavigationPage($id_page) { |
41
|
|
|
$dbc = App::getDb(); |
42
|
|
|
$query = $dbc->select()->from("navigation")->from("page")->where("page.ID_page", "=", $id_page, "AND")->where("page.affiche", "=", 1, "AND")->where("page.parent", "=", 0, "AND")->where("navigation.ID_page", "=", "page.ID_page", "", true)->get(); |
43
|
|
|
if (is_array($query) && (count($query) > 0)) { |
44
|
|
|
$nav = []; |
45
|
|
|
foreach ($query as $obj) { |
46
|
|
|
$nav = [ |
47
|
|
|
"id" => $obj->ID_page, |
48
|
|
|
"titre" => $obj->titre, |
49
|
|
|
"lien_page" => $this->getLienPage($obj->url), |
50
|
|
|
"url" => $obj->url, |
51
|
|
|
"balise_title" => $obj->balise_title, |
52
|
|
|
"sous_menu" => $this->getSousMenu($id_page), |
53
|
|
|
"type" => "page", |
54
|
|
|
"target" => $obj->target, |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
return $nav; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param $id_page |
63
|
|
|
* @return array |
64
|
|
|
* to get the sub navigation of a page which have it |
65
|
|
|
*/ |
66
|
|
|
private function getSousMenu($id_page) { |
67
|
|
|
$dbc = App::getDb(); |
68
|
|
|
$sous_menu = []; |
69
|
|
|
|
70
|
|
|
$query = $dbc->select()->from("page")->where("parent", "=", $id_page, "AND")->where("affiche", "=", 1)->get(); |
71
|
|
|
|
72
|
|
View Code Duplication |
if (is_array($query) && (count($query) > 0)) { |
|
|
|
|
73
|
|
|
foreach ($query as $obj) { |
74
|
|
|
$sous_menu[] = [ |
75
|
|
|
"id" => $obj->ID_page, |
76
|
|
|
"titre" => $obj->titre, |
77
|
|
|
"lien_page" => $this->getLienPage($obj->url), |
78
|
|
|
"url" => $obj->url, |
79
|
|
|
"balise_title" => $obj->balise_title, |
80
|
|
|
"type" => "page", |
81
|
|
|
"target" => $obj->target, |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
return $sous_menu; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param $id_module |
90
|
|
|
* @return array |
91
|
|
|
* to get the navigation link of modules of the website |
92
|
|
|
*/ |
93
|
|
|
private function getLienNavigationModule($id_module) { |
94
|
|
|
$dbc = App::getDb(); |
95
|
|
|
|
96
|
|
|
$query = $dbc->select()->from("navigation")->from("module")->where("module.ID_module", "=", $id_module, "AND")->where("module.installer", "=", 1, "AND")->where("module.activer", "=", 1, "AND")->where("navigation.ID_module", "=", "module.ID_module", "", true)->get(); |
97
|
|
|
|
98
|
|
View Code Duplication |
if (is_array($query) && (count($query) > 0)) { |
|
|
|
|
99
|
|
|
foreach ($query as $obj) { |
100
|
|
|
$nav = [ |
101
|
|
|
"id" => $obj->ID_module, |
102
|
|
|
"titre" => $obj->nom_module, |
103
|
|
|
"lien_page" => $this->getLienPage($obj->url), |
104
|
|
|
"balise_title" => $obj->nom_module, |
105
|
|
|
"type" => "module", |
106
|
|
|
"target" => $obj->target, |
107
|
|
|
]; |
108
|
|
|
return $nav; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/*to verify if page exist*/ |
114
|
|
|
private function getLienPageExist($id_page) { |
115
|
|
|
$dbc = App::getDb(); |
116
|
|
|
|
117
|
|
|
$query = $dbc->select("ID_page")->from("navigation")->where("ID_page", "=", $id_page)->get(); |
118
|
|
|
|
119
|
|
|
if (count($query) < 1) { |
120
|
|
|
return false; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return true; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
private function getLienPage($url) { |
127
|
|
|
if (ChaineCaractere::FindInString($url, "http://")) { |
128
|
|
|
return $url; |
129
|
|
|
} |
130
|
|
|
else { |
131
|
|
|
return WEBROOT.$url; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
|
138
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
139
|
|
|
/** |
140
|
|
|
* @param $query |
141
|
|
|
* function that create navigation called in construct |
142
|
|
|
*/ |
143
|
|
|
private function setNavigation($query) { |
144
|
|
|
$navigation = []; |
145
|
|
|
$last_ordre = ""; |
146
|
|
|
|
147
|
|
|
foreach ($query as $obj) { |
148
|
|
|
if ($obj->ID_page === null) { |
149
|
|
|
$navigation[] = $this->getLienNavigationModule($obj->ID_module); |
150
|
|
|
} |
151
|
|
|
else { |
152
|
|
|
$navigation[] = $this->getLienNavigationPage($obj->ID_page); |
153
|
|
|
} |
154
|
|
|
$last_ordre = $obj->ordre; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->last_ordre = $last_ordre; |
158
|
|
|
|
159
|
|
|
App::setValues(["navigation" => $navigation]); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param $id |
165
|
|
|
* @param $value_id |
166
|
|
|
* to add a link in navigation table |
167
|
|
|
*/ |
168
|
|
|
public function setAjoutLien($id, $value_id) { |
169
|
|
|
$dbc = App::getDb(); |
170
|
|
|
|
171
|
|
|
if ($this->getLienPageExist($id) === false) { |
172
|
|
|
$dbc->insert($id, $value_id)->insert("ordre", $this->last_ordre+1)->into("navigation")->set(); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param $id |
178
|
|
|
* @param $value_id |
179
|
|
|
* to delete a link in navigation table |
180
|
|
|
*/ |
181
|
|
|
public function setSupprimerLien($id, $value_id) { |
182
|
|
|
$dbc = App::getDb(); |
183
|
|
|
|
184
|
|
|
$dbc->delete()->from("navigation")->where($id, "=", $value_id)->del(); |
185
|
|
|
} |
186
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
187
|
|
|
} |
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.