Passed
Push — master ( 130235...72544b )
by Anthony
02:52
created

DroitAcces   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 201
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 12
Bugs 1 Features 0
Metric Value
wmc 39
c 12
b 1
f 0
lcom 1
cbo 2
dl 0
loc 201
rs 8.2857

13 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 21 5
A getLogged() 0 3 1
A getSuperAdmin() 0 3 1
A getIdListeDroitAcces() 0 3 1
A getModifSeo() 0 3 1
A getModifContenu() 0 3 1
A getModifNavigation() 0 3 1
A getSupprimerPage() 0 3 1
A getListeDroitAcces() 0 17 4
A getListeDroitPage() 0 11 4
B getDroitAccesPage() 0 11 6
D getDroitAccesContenu() 0 46 10
A getDroitAccesAction() 0 10 3
1
<?php
2
	namespace core\admin\droitsacces;
3
4
	use core\App;
5
6
	class DroitAcces {
7
		private $logged;
8
9
		//pour la table identite
10
		private $id_identite;
11
		private $super_admin;
12
13
		//pour la table liste_droit_acces
14
		private $id_liste_droit_acces;
15
16
		//pour des droits pour la gestion des contenus
17
		private $modif_seo;
18
		private $modif_contenu;
19
		private $modif_navigation;
20
		private $supprimer_page;
21
22
23
		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
24
		public function __construct() {
25
			$dbc = \core\App::getDb();
26
27
			if (isset($_SESSION["idlogin".CLEF_SITE])) {
28
				$this->logged = true;
29
				$this->id_identite = $_SESSION["idlogin".CLEF_SITE];
30
31
				//on test voir si super admin
32
				$query = $dbc->query("SELECT super_admin,liste_droit FROM identite WHERE ID_identite=".$this->id_identite);
33
34
				if ((is_array($query)) && (count($query) > 0)) {
35
					foreach ($query as $obj) {
36
						$this->super_admin = $obj->super_admin;
37
						$this->id_liste_droit_acces = $obj->liste_droit;
38
					}
39
				}
40
			}
41
			else {
42
				$this->logged = false;
43
			}
44
		}
45
		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
46
    
47
    
48
    
49
		//-------------------------- GETTER ----------------------------------------------------------------------------//
50
		public function getLogged(){
51
			return $this->logged;
52
		}
53
		public function getSuperAdmin(){
54
			return $this->super_admin;
55
		}
56
		public function getIdListeDroitAcces(){
57
			return $this->id_liste_droit_acces;
58
		}
59
		public function getModifSeo(){
60
			return $this->modif_seo;
61
		}
62
		public function getModifContenu(){
63
			return $this->modif_contenu;
64
		}
65
		public function getModifNavigation(){
66
			return $this->modif_navigation;
67
		}
68
		public function getSupprimerPage(){
69
			return $this->supprimer_page;
70
		}
71
72
		/**
73
		 * @return array
74
		 */
75
		private function getListeDroitAcces() {
76
			$dbc = App::getDb();
77
78
			$liste_droit_acces = [];
79
80
			$query = $dbc->query("SELECT * FROM droit_acces, liste_droit_acces, liaison_liste_droit WHERE
81
								droit_acces.ID_droit_acces = liaison_liste_droit.ID_droit_acces AND
82
								liste_droit_acces.ID_liste_droit_acces = liaison_liste_droit.ID_liste_droit_acces AND
83
								liste_droit_acces.ID_liste_droit_acces = $this->id_liste_droit_acces
84
				");
85
86
			if ((is_array($query)) && (count($query) > 0)) {
87
				foreach ($query as $obj) $liste_droit_acces[] = $obj->droit_acces;
88
			}
89
90
			return $liste_droit_acces;
91
		}
92
93
		/**
94
		 * @return array/
0 ignored issues
show
Documentation introduced by
The doc-type array/ could not be parsed: Unknown type name "array/" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
95
		 */
96
		private function getListeDroitPage() {
97
			$dbc = App::getDb();
98
			$droit_acces = [];
99
100
			$query = $dbc->query("SELECT droit_acces FROM droit_acces WHERE page LIKE '%$page%'");
0 ignored issues
show
Bug introduced by
The variable $page does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
101
			if ((is_array($query)) && (count($query) > 0)) {
102
				foreach ($query as $obj) $droit_acces = $obj->droit_acces;
103
			}
104
105
			return $droit_acces;
106
		}
107
108
		//autres getter
109
		/**
110
		 * pour savoir si en fonction des droits d'accès de l'utilisateur il peu ou non accéder à cete page
111
		 * on passe outre les test si on est super admin
112
		 * @param string $page
113
		 * @return bool
114
		 */
115
		public function getDroitAccesPage($page) {
116
			//page sans droit dans admin
117
			$all_access = array("gestion-comptes/mon-compte", "index");
118
119
			if (($this->super_admin == 1) || (in_array($this->getListeDroitPage(), $this->getListeDroitAcces())) || (($page == "") || ($page == null)) || (in_array($page, $all_access))) {
120
				return true;
121
			}
122
			else {
123
				return false;
124
			}
125
		}
126
127
		/**
128
		 * fonction qui permet de gérer les droits d'accès sur les contenus :
129
		 * - creer une page
130
		 * - modifier du contenu (SEO, navigation, contenu)
131
		 * - supprimer une page
132
		 * si on est super admin on passe outre tous les tests
133
		 * @param $droit
134
		 * @param $id_page
135
		 * @return bool|null
136
		 */
137
		public function getDroitAccesContenu($droit, $id_page) {
138
			$dbc = \core\App::getDb();
139
140
			//récupération de la liste des droits de l'utilisateur si aps super admin
141
			if ($this->super_admin != 1) {
142
				$liste_droit_acces = $this->getListeDroitAcces();
143
144
				if (in_array($droit, $liste_droit_acces)) {
145
					//on check si il a le droit de modifier ou supprimer cette page
146
					$query = $dbc->query("SELECT * FROM droit_acces_page, liste_droit_acces WHERE
147
									droit_acces_page.ID_liste_droit_acces = liste_droit_acces.ID_liste_droit_acces AND
148
									droit_acces_page.ID_page = $id_page AND
149
									liste_droit_acces.ID_liste_droit_acces = $this->id_liste_droit_acces
150
					");
151
152
					//si on a un resultat
153
					if ((is_array($query)) && (count($query) > 0)) {
154
						foreach ($query as $obj) {
155
							$this->modif_seo = $obj->seo;
156
							$this->modif_contenu = $obj->contenu;
157
							$this->modif_navigation = $obj->navigation;
158
							$this->supprimer_page = $obj->supprimer;
159
						}
160
161
						//si les trois sont différent de 0 on renvoit true soinon false
162
						if (($this->modif_seo != 0) || ($this->modif_contenu != 0) || ($this->modif_navigation != 0) || ($this->supprimer_page != 0)) {
163
							return true;
164
						}
165
						else {
166
							return false;
167
						}
168
					}
169
				}
170
				else {
171
					return false;
172
				}
173
			}
174
			else {
175
				$this->modif_seo = 1;
176
				$this->modif_contenu = 1;
177
				$this->modif_navigation = 1;
178
				$this->supprimer_page = 1;
179
180
				return true;
181
			}
182
		}
183
184
		/**
185
		 * pour savoir si un utilisateur à le droit de supprimer, modifier ou ajouter des trucs
186
		 * @param $droit_acces
187
		 * @return bool
188
		 */
189
		public function getDroitAccesAction($droit_acces) {
190
			$liste_droit_acces = $this->getListeDroitAcces();
191
192
			if (($this->super_admin == 1) || (in_array($droit_acces, $liste_droit_acces))) {
193
				return true;
194
			}
195
			else {
196
				return false;
197
			}
198
		}
199
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
200
    
201
    
202
    
203
		//-------------------------- SETTER ----------------------------------------------------------------------------//
204
205
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
206
	}