Passed
Push — master ( 1dd91c...220996 )
by Anthony
03:16
created

GestionDroitAcces::getNbUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
	namespace core\admin\droitsacces;
3
4
	use core\App;
5
6
	class GestionDroitAcces extends DroitAcces {
7
		//pour les droit_acces standard
8
		private $id_liste_droit_acces;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
9
		private $nom_liste;
10
		private $droit_acces;
11
		private $nb_droit_acces;
12
13
		//pour les droits d'acces sur les page
14
		private $id_page;
15
		private $titre_page;
16
		private $nb_droit_acces_page;
17
18
		//pour la table identite
19
		private $id_identite;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
20
		private $pseudo;
21
		private $nom;
22
		private $prenom;
23
		private $nb_user;
24
25
26
27
		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
28
		public function __construct($id_liste_droit_acces = null) {
29
			if ($id_liste_droit_acces == null) {
30
				$this->getListeDroitAcces();
31
			}
32
			else {
33
				$this->id_liste_droit_acces = $id_liste_droit_acces;
34
			}
35
		}
36
		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
37
38
39
40
		//-------------------------- GETTER ----------------------------------------------------------------------------//
41
		//pour les droit_acces standard
42
		public function getIdListeDroitAcces() {
43
			return $this->id_liste_droit_acces;
44
		}
45
		public function getNomListe() {
46
			return $this->nom_liste;
47
		}
48
		public function getDroitAcces() {
49
			return $this->droit_acces;
50
		}
51
		public function getNbDroitAcces() {
52
			return $this->nb_droit_acces;
53
		}
54
55
		//pour les droits d'acces sur les page
56
		public function getIdPage() {
57
			return $this->id_page;
58
		}
59
		public function getTitrePage() {
60
			return $this->titre_page;
61
		}
62
		public function getNbDroitAccesPage() {
63
			return $this->nb_droit_acces_page;
64
		}
65
66
		//pour la table identite
67
		public function getIdidentite() {
68
			return $this->id_identite;
69
		}
70
		public function getNom() {
71
			return $this->nom;
72
		}
73
		public function getPrenom() {
74
			return $this->prenom;
75
		}
76
		public function getPseudo() {
77
			return $this->pseudo;
78
		}
79
		public function getNbUser() {
80
			return $this->nb_user;
81
		}
82
83
		/**
84
		 * appellee dans le constructeur pour afficher les listes de droit d'acces
85
		 */
86
		private function getListeDroitAcces() {
0 ignored issues
show
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
87
			$dbc = App::getDb();
88
89
			//pour affichage de la liste des listes de droit d'acces
90
			//récupération des droits d'acces génériques
91
			$query = $dbc->query("SELECT * FROM liste_droit_acces");
92
93
			if ((is_array($query)) && (count($query) > 0)) {
94
				$id_liste_droit_acces = [];
95
				$nom_liste = [];
96
				$nb_droit_acces = [];
97
				$nb_droit_acces_page = [];
98
				$nb_user = [];
99
100
				foreach ($query as $obj) {
101
					$id_liste_droit_acces[] = $obj->ID_liste_droit_acces;
102
					$nom_liste[] = $obj->nom_liste;
103
104
					//récupération du nombre de droits d'acces pour cette liste
105
					$nb_droit_acces = $this->getNombreDroitAccesListe($obj->ID_liste_droit_acces);
106
107
					//récupération du nombre d'utilisateurs qui sont dans cette liste
108
					$nb_user = $this->getNombreUtilisateurListe($obj->ID_liste_droit_acces);
109
110
					//récupération du nombres de pages dans cette liste
111
					$nb_droit_acces_page = $this-> getNombrePageListe($obj->ID_liste_droit_acces);
112
				}
113
114
				$this->setListeDroitAcces($id_liste_droit_acces, $nom_liste, $nb_droit_acces, $nb_droit_acces_page, $nb_user);
115
			}
116
		}
117
118
		/**
119
		 * @param $id_liste_droit_acces
120
		 * @return integer
121
		 */
122
		private function getNombreUtilisateurListe($id_liste_droit_acces) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
123
			$dbc = App::getDb();
124
125
			$nb_user = 0;
126
127
			$query2 = $dbc->query("SELECT count(ID_identite) as ID_identite FROM identite WHERE liste_droit=".$id_liste_droit_acces);
128
			if ((is_array($query2)) && (count($query2) > 0)) {
129
				foreach ($query2 as $obj2) {
130
					$nb_user[] = $obj2->ID_identite;
131
				}
132
			}
133
134
			return $nb_user;
135
		}
136
137
		/**
138
		 * @param $id_liste_droit_acces
139
		 * @return integer
140
		 */
141
		private function getNombreDroitAccesListe($id_liste_droit_acces) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
142
			$dbc = App::getDb();
143
144
			$nb_droit_acces = 0;
145
146
			$query1 = $dbc->query("SELECT count(ID_droit_acces) as ID_droit_acces FROM liaison_liste_droit WHERE ID_liste_droit_acces =".$id_liste_droit_acces);
147
			if ((is_array($query1)) && (count($query1) > 0)) {
148
				foreach ($query1 as $obj1) {
149
					$nb_droit_acces[] = $obj1->ID_droit_acces;
150
				}
151
			}
152
153
			return $nb_droit_acces;
154
		}
155
156
		/**
157
		 * @param $id_liste_droit_acces
158
		 * @return integer
159
		 */
160
		private function getNombrePageListe($id_liste_droit_acces) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
161
			$dbc = App::getDb();
162
163
			$nb_droit_acces_page = 0;
164
165
			$query3 = $dbc->query("SELECT count(ID_page) as ID_page FROM droit_acces_page WHERE ID_liste_droit_acces =".$id_liste_droit_acces);
166
			if ((is_array($query3)) && (count($query3) > 0)) {
167
				foreach ($query3 as $obj3) {
168
					$nb_droit_acces_page[] = $obj3->ID_page;
169
				}
170
			}
171
172
			return $nb_droit_acces_page;
173
		}
174
175
		/**
176
		 * fonction qui récupère la liste des droits d'acces en texte en fonction de l'id de la liste
177
		 * @param $id_liste_droit_acces
178
		 */
179 View Code Duplication
		public function getListeDroitAccesDetailDroit() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
180
			$dbc = \core\App::getDb();
181
182
			$query = $dbc->query("SELECT * FROM droit_acces, liaison_liste_droit WHERE
183
										droit_acces.ID_droit_acces = liaison_liste_droit.ID_droit_acces AND
184
										liaison_liste_droit.ID_liste_droit_acces =".$this->id_liste_droit_acces);
185
			if ((is_array($query)) && (count($query) > 0)) {
186
				$droit_acces = [];
187
188
				foreach ($query as $obj) {
189
					$droit_acces[] = $obj->droit_acces;
190
				}
191
192
				$this->setListeDroitAccesDetailDroit($droit_acces);
193
			}
194
		}
195
196
		/**
197
		 * fonction qui récupère la liste des utilisateur dans une liste de droits d'acces en texte en fonction de l'id de la liste
198
		 * @param $id_liste_droit_acces
199
		 */
200
		public function getListeDroitAccesDetailUser() {
201
			$dbc = \core\App::getDb();
202
203
			//récupératin des utilisateurs qui sont dans cette liste
204
			$query = $dbc->query("SELECT * FROM identite WHERE liste_droit=".$this->id_liste_droit_acces);
205
			if ((is_array($query)) && (count($query) > 0)) {
206
				$id_identite = [];
207
				$pseudo = [];
208
				$nom = [];
209
				$prenom = [];
210
211
				foreach ($query as $obj) {
212
					$id_identite[] = $obj->ID_identite;
213
					$pseudo[] = $obj->pseudo;
214
					$nom[] = $obj->nom;
215
					$prenom[] = $obj->prenom;
216
				}
217
218
				$this->setListeDroitAccesDetailUser($id_identite, $pseudo, $nom, $prenom);
219
			}
220
		}
221
222
		/**
223
		 * fonction qui récupère la liste des droits d'acces sur les pages en texte en fonction de l'id de la liste
224
		 * @param $id_liste_droit_acces
225
		 */
226
		public function getListeDroitAccesDetailPage() {
227
			$dbc = \core\App::getDb();
228
229
			//récupération des droits d'acces pour les pages
230
			$query = $dbc->query("SELECT * FROM liste_droit_acces, droit_acces_page, page WHERE
231
									liste_droit_acces.ID_liste_droit_acces = droit_acces_page.ID_liste_droit_acces AND
232
									droit_acces_page.ID_page = page.ID_page AND
233
									liste_droit_acces.ID_liste_droit_acces = $this->id_liste_droit_acces
234
			");
235
			if ((is_array($query)) && (count($query) > 0)) {
236
				$id_page = [];
237
				$titre_page = [];
238
239
				foreach ($query as $obj) {
240
					$id_page[] = $obj->ID_page;
241
					$titre_page[] = $obj->titre;
242
				}
243
244
				$this->setListeDroitAccesDetailPage($id_page, $titre_page);
245
			}
246
		}
247
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
248
249
250
251
		//-------------------------- SETTER ----------------------------------------------------------------------------//
252
		private function setListeDroitAcces($id_liste_droit_acces, $nom_liste, $nb_droit_acces, $nb_droit_acces_page, $nb_user) {
253
			$this->id_liste_droit_acces = $id_liste_droit_acces;
254
			$this->nom_liste = $nom_liste;
255
			$this->nb_droit_acces = $nb_droit_acces;
256
			$this->nb_droit_acces_page = $nb_droit_acces_page;
257
			$this->nb_user = $nb_user;
258
		}
259
		private function setListeDroitAccesDetailDroit($droit_acces) {
260
			$this->droit_acces = $droit_acces;
261
		}
262
		private function setListeDroitAccesDetailPage($id_page, $titre_page) {
263
			$this->id_page = $id_page;
264
			$this->titre_page = $titre_page;
265
		}
266
		private function setListeDroitAccesDetailUser($id_identite, $pseudo, $nom, $prenom) {
267
			$this->id_identite = $id_identite;
268
			$this->pseudo = $pseudo;
269
			$this->nom = $nom;
270
			$this->prenom = $prenom;
271
		}
272
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
273
	}