|
1
|
|
|
<?php |
|
2
|
|
|
namespace core; |
|
3
|
|
|
class Navigation { |
|
4
|
|
|
private $navigation; |
|
5
|
|
|
private $last_ordre; |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
|
10
|
|
|
public function __construct() { |
|
11
|
|
|
$dbc = App::getDb(); |
|
12
|
|
|
$navigation = []; |
|
13
|
|
|
|
|
14
|
|
|
$query = $dbc->select()->from("navigation")->orderBy("ordre")->get(); |
|
15
|
|
|
|
|
16
|
|
|
if (is_array($query) && (count($query) > 0)) { |
|
17
|
|
|
foreach ($query as $obj) { |
|
18
|
|
|
if ($obj->ID_page === null) { |
|
19
|
|
|
$navigation[] = $this->getLienNavigationModule($obj->ID_module); |
|
20
|
|
|
} |
|
21
|
|
|
else { |
|
22
|
|
|
$navigation[] = $this->getLienNavigationPage($obj->ID_page); |
|
23
|
|
|
} |
|
24
|
|
|
$last_ordre = $obj->ordre; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$this->last_ordre = $last_ordre; |
|
|
|
|
|
|
28
|
|
|
$this->setNavigation($navigation); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
|
36
|
|
|
public function getNavigation() { |
|
37
|
|
|
return $this->navigation; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function getLienNavigationPage($id_page) { |
|
41
|
|
|
$dbc = App::getDb(); |
|
42
|
|
|
|
|
43
|
|
|
$query = $dbc->select() |
|
44
|
|
|
->from("navigation") |
|
45
|
|
|
->from("page") |
|
46
|
|
|
->where("navigation.ID_page", "=", "page.ID_page", "AND") |
|
47
|
|
|
->where("page.ID_page", "=", $id_page, "AND") |
|
48
|
|
|
->where("page.affiche", "=", 1, "AND") |
|
49
|
|
|
->where("page.parent", "=", 0) |
|
50
|
|
|
->get(); |
|
51
|
|
|
|
|
52
|
|
View Code Duplication |
if (is_array($query) && (count($query) > 0)) { |
|
|
|
|
|
|
53
|
|
|
foreach ($query as $obj) { |
|
54
|
|
|
return [$obj->titre, $obj->url, $obj->balise_title, $this->getSousMenu($id_page)]; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function getSousMenu($id_page) { |
|
60
|
|
|
$dbc = App::getDb(); |
|
61
|
|
|
$sous_menu = []; |
|
62
|
|
|
|
|
63
|
|
|
$query = $dbc->select()->from("page")->where("parent", "=", $id_page)->get(); |
|
64
|
|
|
|
|
65
|
|
View Code Duplication |
if (is_array($query) && (count($query) > 0)) { |
|
|
|
|
|
|
66
|
|
|
foreach ($query as $obj) { |
|
67
|
|
|
$sous_menu[] = [$obj->titre, $obj->url, $obj->balise_title,]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $sous_menu; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function getLienNavigationModule($id_module) { |
|
75
|
|
|
$dbc = App::getDb(); |
|
76
|
|
|
|
|
77
|
|
|
$query = $dbc->select() |
|
78
|
|
|
->from("navigation") |
|
79
|
|
|
->from("module") |
|
80
|
|
|
->where("navigation.ID_module", "=", "module.ID_module", "AND") |
|
81
|
|
|
->where("module.ID_module", "=", $id_module, "AND") |
|
82
|
|
|
->where("module.installer", "=", 1, "AND") |
|
83
|
|
|
->where("module.activer", "=", 1) |
|
84
|
|
|
->get(); |
|
85
|
|
|
|
|
86
|
|
View Code Duplication |
if (is_array($query) && (count($query) > 0)) { |
|
|
|
|
|
|
87
|
|
|
foreach ($query as $obj) { |
|
88
|
|
|
return [$obj->nom_module,$obj->url]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
|
97
|
|
|
private function setNavigation($navigation) { |
|
98
|
|
|
$this->navigation = $navigation; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function setTestAjoutLien($id, $value_id, $afficher) { |
|
102
|
|
|
$dbc = App::getDb(); |
|
103
|
|
|
|
|
104
|
|
|
if ($afficher != null) { |
|
105
|
|
|
$dbc->insert($id, $value_id)->insert("ordre", $this->last_ordre+1)->into("navigation")->set(); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function setSupprimerLien($id, $value_id) {echo("$id, $value_id"); |
|
110
|
|
|
$dbc = App::getDb(); |
|
111
|
|
|
|
|
112
|
|
|
$dbc->delete()->from("navigation")->where($id, "=", $value_id)->del(); |
|
113
|
|
|
} |
|
114
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
|
115
|
|
|
} |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: