Passed
Push — master ( a65307...4c85c7 )
by Anthony
03:31
created

GestionContenus::getVerifChamp()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
	namespace core\admin\contenus;
3
4
	use core\App;
5
	use core\contenus\Contenus;
6
	use core\functions\ChaineCaractere;
7
	use core\HTML\flashmessage\FlashMessage;
8
9
	class GestionContenus extends Contenus {
10
		use GestionErreurContenus;
11
		private $erreur;
12
13
14
		//-------------------------- GETTER ----------------------------------------------------------------------------//
15
		public function getErreur() {
16
			return $this->erreur;
17
		}
18
19
		private function getParentId($parent) {
20
			$dbc = \core\App::getDb();
21
22
			if ($parent == "") {
23
				return 0;
24
			}
25
26
			$query = $dbc->select("ID_page")->from("page")->where("titre", " LIKE ", '"%'.$parent.'%"', "", true)->get();
27
28
			if (count($query) == 1) {
29
				foreach ($query as $obj) {
30
					return $obj->ID_page;
31
				}
32
			}
33
34
			return 0;
35
		}
36
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
37
38
39
40
		//-------------------------- SETTER ----------------------------------------------------------------------------//
41
		/**
42
		 * @param string $new_page
43
		 * @return bool
44
		 */
45
		private function setCreerFichier($new_page) {
46
			$page_type = ROOT."config/page_type/page_type.html";
47
			
48
			if ((!file_exists($new_page)) && (copy($page_type, $new_page))) {
49
				return true;
50
			}
51
			
52
			FlashMessage::setFlash("Impossible de créer cette page, veuillez réeseyer dans un moment. Si le problème persiste contactez votre administrateur.");
53
			$this->erreur = true;
54
			return false;
55
		}
56
57
		/**
58
		 * fonction qui permet de créer un page
59
		 * @param $balise_title
60
		 * @param $url
61
		 * @param $meta_description
62
		 * @param $titre_page
63
		 * @param $parent
64
		 */
65
		public function setCreerPage($balise_title, $url, $meta_description, $titre_page, $parent, $affiche = 1) {
66
			$dbc = \core\App::getDb();
67
			$url = ChaineCaractere::setUrl($url);
68
			$nom_page = explode("/", $url);
69
			$nom_page = end($nom_page);
70
			$new_page = ROOT."app/views/".$nom_page.".html";
71
			$err_balise_title = $this->getTestBaliseTitle($balise_title);
72
			$err_url = $this->getTestUrl($url);
73
			$err_meta_description = $this->getTestMetaDescription($meta_description);
74
			$err_titre_page = $this->getTestTitrePage($titre_page);
75
			
76
			if ($this->erreur === true) {
77
				$this->setErreurContenus($balise_title, $url, $meta_description, $titre_page, $parent, $err_balise_title, $err_url, $err_meta_description, $err_titre_page);
78
				return false;
79
			}
80
			
81
			if ($this->setCreerFichier($new_page) === false) {
82
				return false;
83
			}
84
			
85
			$parent = intval($this->getParentId($parent));
86
			$dbc->insert("titre", $titre_page)->insert("url", $url)->insert("meta_description", $meta_description)
87
				->insert("balise_title", $balise_title)->insert("parent", $parent)
88
				->insert("affiche", $affiche)->into("page")->set();
89
			
90
			$this->id_page = $dbc->lastInsertId();
91
			$this->url = $url;
92
			if ($parent == "") {
93
				$this->setAjoutLienNavigation("ID_page", $this->id_page, 1);
94
			}
95
		}
96
97
		/**
98
		 * function that will create a redirection on an other site
99
		 * @param $balise_title
100
		 * @param $url
101
		 * @param $titre_page
102
		 * @param $parent
103
		 */
104
		public function setCreerPageRedirect($balise_title, $url, $titre_page, $parent, $affiche = 1) {
105
			$dbc = \core\App::getDb();
106
			$err_balise_title = $this->getTestBaliseTitle($balise_title);
107
			$err_url = $this->getTestUrl($url);
108
			$err_titre_page = $this->getTestTitrePage($titre_page);
109
			
110
			if ($this->erreur !== true) {
111
				$parent = intval($this->getParentId($parent));
112
				$dbc->insert("titre", $titre_page)->insert("url", $url)->insert("balise_title", $balise_title)->insert("parent", $parent)->insert("affiche", $affiche)->insert("target", "_blanck")->into("page")->set();
113
				$this->id_page = $dbc->lastInsertId();
114
				if ($parent == "") {
115
					$this->setAjoutLienNavigation("ID_page", $this->id_page, 1);
116
				}
117
			}
118
			else {
119
				$this->setErreurContenus($balise_title, $url, "", $titre_page, $parent, $err_balise_title, $err_url, "", $err_titre_page);
120
				$this->erreur = true;
121
			}
122
		}
123
124
		/**
125
		 * fonction qui permet de modifier une page en fonction de son id
126
		 * @param $id_page
127
		 * @param $balise_title
128
		 * @param $url
129
		 * @param $meta_description
130
		 * @param $titre_page
131
		 * @param $parent
132
		 * @param $contenu
133
		 */
134
		public function setModifierPage($id_page, $balise_title, $url, $meta_description, $titre_page, $parent, $affiche = 1) {
135
			$dbc = \core\App::getDb();
136
			$old_url = explode("/", $this->url);
137
			$filename = ROOT."app/views/".end($old_url).".html";
138
			
139
			if (file_exists($filename) || ($id_page == 1)) {
140
				FlashMessage::setFlash("Impossible de modifier cette page, veuillez contacter votre administrateur pour corriger ce problème");
141
				$this->erreur = true;
142
				return false;
143
			}
144
			
145
			$this->id_page = $id_page;
146
			$url = ChaineCaractere::setUrl($url);
147
			$err_balise_title = $this->getTestBaliseTitle($balise_title, $id_page);
148
			$err_url = $this->getTestUrl($url, $id_page);
149
			$err_meta_description = $this->getTestMetaDescription($meta_description, $id_page);
150
			$err_titre_page = $this->getTestTitrePage($titre_page, $id_page);
151
			
152
			if ($this->erreur !== true) {
153
				$new_url = explode("/", $url);
154
				$new_filename = ROOT."app/views/".end($new_url).".html";
155
				
156
				rename($filename, $new_filename);
157
				
158
				$parent = intval($this->getParentId($parent));
159
				$dbc->update("titre", $titre_page)
160
					->update("url", $url)
161
					->update("meta_description", $meta_description)
162
					->update("balise_title", $balise_title)
163
					->update("parent", $parent)
164
					->update("affiche", $affiche)
165
					->from("page")->where("ID_page", "=", $id_page, "", true)
166
					->set();
167
				
168
				$this->setModifierLienNavigation("ID_page", $id_page, $this->getParentId($parent), $affiche);
169
				$this->url = $url;
170
			}
171
			else {
172
				$this->setErreurContenus($balise_title, $url, $meta_description, $titre_page, $parent, $err_balise_title, $err_url, $err_meta_description, $err_titre_page);
173
			}
174
		}
175
176
		/**
177
		 * @param $id_page
178
		 * @param $contenu
179
		 */
180
		public function setModifierContenu($id_page, $contenu) {
181
			$dbc = \core\App::getDb();
182
183
			$dbc->update("contenu", $contenu)->from("page")->where("ID_page", "=", $id_page)->set();
184
		}
185
186
		/**
187
		 * fonction qui permet de supprimer une page, test si fichier exist, si oui on delete
188
		 * @param $id_page
189
		 */
190
		public function setSupprimerPage() {
191
			$url = explode("/", $this->url);
192
			$filename = ROOT."app/views/".end($url).".html";
193
			
194
			if (file_exists($filename) && $this->id_page != 1) {
195
				unlink($filename);
196
				$this->setSupprimerLienNavigation();
197
				
198
				return true;
199
			}
200
			else if (ChaineCaractere::FindInString($this->url, "http://") === true) {
201
				$this->setSupprimerLienNavigation();
202
			}
203
			else {
204
				FlashMessage::setFlash("Impossible de supprimer cette page, veuillez contacter votre administrateur pour corriger ce problème");
205
				$this->erreur = true;
206
				return false;
207
			}
208
		}
209
210
		/**
211
		 * @param string $id
212
		 * @param string $value_id
213
		 * @param integer $affiche
214
		 */
215
		private function setAjoutLienNavigation($id, $value_id, $affiche) {
216
			if ($affiche !== null) {
217
				App::getNav()->setAjoutLien($id, $value_id);
218
			}
219
		}
220
221
		/**
222
		 * @param string $id
223
		 * @param integer $affiche
224
		 */
225
		private function setModifierLienNavigation($id, $id_page, $parent, $affiche) {
226
			if ($parent != "") {
227
				App::getNav()->setSupprimerLien($id, $id_page);
228
			}
229
			else if (($affiche == 0) && ($parent == "")) {
230
				App::getNav()->setSupprimerLien($id, $id_page);
231
			}
232
		}
233
		
234
		/**
235
		 * delete link in nav and delete page in table
236
		 */
237
		private function setSupprimerLienNavigation() {
238
			$dbc = App::getDb();
239
			
240
			$dbc->delete()->from("page")->where("ID_page", "=", $this->id_page)->del();
241
			
242
			App::getNav()->setSupprimerLien("ID_page", $this->id_page);
243
		}
244
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
245
	}