|
1
|
|
|
<?php |
|
2
|
|
|
namespace core\contenus; |
|
3
|
|
|
|
|
4
|
|
|
use core\RedirectError; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class Contenus { |
|
8
|
|
|
//pour la table page |
|
9
|
|
|
protected $id_page; |
|
10
|
|
|
protected $titre; |
|
11
|
|
|
protected $contenu; |
|
12
|
|
|
protected $url; |
|
13
|
|
|
protected $meta_description; |
|
14
|
|
|
protected $balise_title; |
|
15
|
|
|
protected $parent; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------// |
|
20
|
|
View Code Duplication |
public function __construct($init_all = 0) { |
|
|
|
|
|
|
21
|
|
|
$dbc = \core\App::getDb(); |
|
22
|
|
|
|
|
23
|
|
|
if ($init_all == 1) { |
|
24
|
|
|
//on construit le menu |
|
25
|
|
|
$query = $dbc->query("SELECT ID_page, titre, balise_title, parent, url FROM page WHERE affiche=1 ORDER BY ordre"); |
|
26
|
|
|
|
|
27
|
|
|
if ((is_array($query)) && (count($query) > 0)) { |
|
28
|
|
|
$id_page = []; |
|
29
|
|
|
$titre = []; |
|
30
|
|
|
$balise_title = []; |
|
31
|
|
|
$url = []; |
|
32
|
|
|
$parent = []; |
|
33
|
|
|
|
|
34
|
|
|
foreach ($query as $obj) { |
|
35
|
|
|
$id_page[] = $obj->ID_page; |
|
36
|
|
|
$titre[] = $obj->titre; |
|
37
|
|
|
$balise_title[] = $obj->balise_title; |
|
38
|
|
|
$url[] = $obj->url; |
|
39
|
|
|
$parent[] = $obj->parent; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->setMenu($id_page, $titre, $balise_title, $url, $parent); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------// |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
|
51
|
|
|
//pour la table page |
|
52
|
|
|
public function getIdPage() { |
|
53
|
|
|
return $this->id_page; |
|
54
|
|
|
} |
|
55
|
|
|
public function getTitre() { |
|
56
|
|
|
return $this->titre; |
|
57
|
|
|
} |
|
58
|
|
|
public function getContenu() { |
|
59
|
|
|
return $this->contenu; |
|
60
|
|
|
} |
|
61
|
|
|
public function getUrl() { |
|
62
|
|
|
return $this->url; |
|
63
|
|
|
} |
|
64
|
|
|
public function getMetaDescription() { |
|
65
|
|
|
return $this->meta_description; |
|
66
|
|
|
} |
|
67
|
|
|
public function getBaliseTitle() { |
|
68
|
|
|
return $this->balise_title; |
|
69
|
|
|
} |
|
70
|
|
|
public function getParent() { |
|
71
|
|
|
return $this->parent; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* pour récupérer l'en tete d'une page (balise title ++ meta description) |
|
77
|
|
|
* @param $id_page |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getHeadPage($id_page, $url = null) { |
|
80
|
|
|
$dbc = \core\App::getDb(); |
|
81
|
|
|
|
|
82
|
|
|
if ($id_page != 0) { |
|
83
|
|
|
$query = $dbc->query("SELECT balise_title, meta_description, ID_page FROM page WHERE ID_page=".$id_page); |
|
84
|
|
|
} |
|
85
|
|
|
else { |
|
86
|
|
|
$query = $dbc->query("SELECT balise_title, meta_description, ID_page FROM page WHERE url LIKE '$url'"); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if (RedirectError::testRedirect404($query, $url) === true) { |
|
90
|
|
|
if ((is_array($query)) && (count($query) > 0)) { |
|
91
|
|
|
foreach ($query as $obj) { |
|
92
|
|
|
$this->id_page = $obj->ID_page; |
|
93
|
|
|
$this->meta_description = $obj->meta_description; |
|
94
|
|
|
$this->balise_title = $obj->balise_title; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* pour récupérer une page en particulier |
|
102
|
|
|
* @param $id_page |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getContenuPage($id_page = null) { |
|
105
|
|
|
$dbc = \core\App::getDb(); |
|
106
|
|
|
|
|
107
|
|
|
if ($id_page == null) { |
|
108
|
|
|
$id_page = $this->id_page; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if ($id_page != null) { |
|
112
|
|
|
$query = $dbc->query("SELECT * FROM page WHERE ID_page=".$id_page); |
|
113
|
|
|
|
|
114
|
|
|
if ((is_array($query)) && (count($query) > 0)) { |
|
115
|
|
|
foreach ($query as $obj) { |
|
116
|
|
|
$this->id_page = $obj->ID_page; |
|
117
|
|
|
$this->titre = $obj->titre; |
|
118
|
|
|
$this->contenu = $obj->contenu; |
|
119
|
|
|
$this->url = $obj->url; |
|
120
|
|
|
$this->parent = $obj->parent; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
//-------------------------- FIN GETTER ----------------------------------------------------------------------------// |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
|
130
|
|
|
protected function setMenu($id_page, $titre, $balise_title, $url, $parent) { |
|
131
|
|
|
$this->id_page = $id_page; |
|
132
|
|
|
$this->titre = $titre; |
|
133
|
|
|
$this->balise_title = $balise_title; |
|
134
|
|
|
$this->url = $url; |
|
135
|
|
|
$this->parent = $parent; |
|
136
|
|
|
} |
|
137
|
|
|
//-------------------------- FIN SETTER ----------------------------------------------------------------------------// |
|
138
|
|
|
} |
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.