Passed
Push — master ( cbd1a4...c22ee8 )
by Anthony
03:09
created

DroitAcces   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 195
Duplicated Lines 7.69 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 18
Bugs 1 Features 0
Metric Value
wmc 35
c 18
b 1
f 0
lcom 1
cbo 2
dl 15
loc 195
rs 9

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 4
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 getListeDroitModificationContenu() 0 27 5
A getDroitAccesPage() 0 11 4
A getDroitAccesContenu() 0 15 4
A getDroitAccesAction() 0 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
		public function __construct() {
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...
25
			$dbc = \core\App::getDb();
26
27
			$this->id_identite = $_SESSION["idlogin".CLEF_SITE];
28
29
			//on test voir si super admin
30
			$query = $dbc->query("SELECT super_admin,liste_droit FROM identite WHERE ID_identite=".$this->id_identite);
31
32
			if ((is_array($query)) && (count($query) > 0)) {
33
				foreach ($query as $obj) {
34
					$this->super_admin = $obj->super_admin;
35
					$this->id_liste_droit_acces = $obj->liste_droit;
36
				}
37
			}
38
		}
39
		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
40
    
41
    
42
    
43
		//-------------------------- GETTER ----------------------------------------------------------------------------//
44
		public function getLogged(){
45
			return $this->logged;
46
		}
47
		public function getSuperAdmin(){
48
			return $this->super_admin;
49
		}
50
		public function getIdListeDroitAcces(){
51
			return $this->id_liste_droit_acces;
52
		}
53
		public function getModifSeo(){
54
			return $this->modif_seo;
55
		}
56
		public function getModifContenu(){
57
			return $this->modif_contenu;
58
		}
59
		public function getModifNavigation(){
60
			return $this->modif_navigation;
61
		}
62
		public function getSupprimerPage(){
63
			return $this->supprimer_page;
64
		}
65
66
		/**
67
		 * @return array
68
		 */
69
		private function getListeDroitAcces() {
70
			$dbc = App::getDb();
71
72
			$liste_droit_acces = [];
73
74
			$query = $dbc->query("SELECT * FROM droit_acces, liste_droit_acces, liaison_liste_droit WHERE
75
								droit_acces.ID_droit_acces = liaison_liste_droit.ID_droit_acces AND
76
								liste_droit_acces.ID_liste_droit_acces = liaison_liste_droit.ID_liste_droit_acces AND
77
								liste_droit_acces.ID_liste_droit_acces = $this->id_liste_droit_acces
78
				");
79
80
			if ((is_array($query)) && (count($query) > 0)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
81
				foreach ($query as $obj) $liste_droit_acces[] = $obj->droit_acces;
82
			}
83
84
			return $liste_droit_acces;
85
		}
86
87
		/**
88
		 * @return array
89
		 */
90
		private function getListeDroitPage($page) {
91
			$dbc = App::getDb();
92
			$droit_acces = [];
93
94
			$query = $dbc->query("SELECT droit_acces FROM droit_acces WHERE page LIKE '%$page%'");
95
			if ((is_array($query)) && (count($query) > 0)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
96
				foreach ($query as $obj) $droit_acces = $obj->droit_acces;
97
			}
98
99
			return $droit_acces;
100
		}
101
102
		/**
103
		 * @param $id_page
104
		 */
105
		private function getListeDroitModificationContenu($id_page) {
106
			$dbc = App::getDb();
107
108
			//on check si il a le droit de modifier ou supprimer cette page
109
			$query = $dbc->query("SELECT * FROM droit_acces_page, liste_droit_acces WHERE
110
									droit_acces_page.ID_liste_droit_acces = liste_droit_acces.ID_liste_droit_acces AND
111
									droit_acces_page.ID_page = $id_page AND
112
									liste_droit_acces.ID_liste_droit_acces = $this->id_liste_droit_acces
113
					");
114
115
			//si on a un resultat
116
			if ((is_array($query)) && (count($query) > 0)) {
117
				foreach ($query as $obj) {
118
					$this->modif_seo = $obj->seo;
119
					$this->modif_contenu = $obj->contenu;
120
					$this->modif_navigation = $obj->navigation;
121
					$this->supprimer_page = $obj->supprimer;
122
				}
123
			}
124
125
			if ($this->super_admin == 1) {
126
				$this->modif_seo = 1;
127
				$this->modif_contenu = 1;
128
				$this->modif_navigation = 1;
129
				$this->supprimer_page = 1;
130
			}
131
		}
132
133
		//autres getter
134
		/**
135
		 * pour savoir si en fonction des droits d'accès de l'utilisateur il peu ou non accéder à cete page
136
		 * on passe outre les test si on est super admin
137
		 * @param string $page
138
		 * @return bool
139
		 */
140
		public function getDroitAccesPage($page) {
141
			//page sans droit dans admin
142
			$all_access = array("gestion-comptes/mon-compte", "index");
143
144
			if (($this->super_admin == 1) || (in_array($this->getListeDroitPage($page), $this->getListeDroitAcces()))|| (in_array($page, $all_access))) {
145
				return true;
146
			}
147
			else {
148
				return false;
149
			}
150
		}
151
152
		/**
153
		 * fonction qui permet de gérer les droits d'accès sur les contenus :
154
		 * - creer une page
155
		 * - modifier du contenu (SEO, navigation, contenu)
156
		 * - supprimer une page
157
		 * si on est super admin on passe outre tous les tests
158
		 * @param $droit
159
		 * @param $id_page
160
		 * @return bool|null
161
		 */
162
		public function getDroitAccesContenu($droit, $id_page) {
163
			$liste_droit_acces = $this->getListeDroitAcces();
164
165
			$this->getListeDroitModificationContenu($id_page);
166
167
			$array_modif = [$this->modif_seo, $this->modif_contenu, $this->modif_navigation];
168
169
			//si les trois sont différent de 0 on renvoit true soinon false
170
			if (($this->super_admin == 1) || ((in_array($droit, $liste_droit_acces)) && in_array(1, $array_modif))) {
171
				return true;
172
			}
173
			else {
174
				return false;
175
			}
176
		}
177
178
		/**
179
		 * pour savoir si un utilisateur à le droit de supprimer, modifier ou ajouter des trucs
180
		 * @param $droit_acces
181
		 * @return bool
182
		 */
183
		public function getDroitAccesAction($droit_acces) {
184
			$liste_droit_acces = $this->getListeDroitAcces();
185
186
			if (($this->super_admin == 1) || (in_array($droit_acces, $liste_droit_acces))) {
187
				return true;
188
			}
189
			else {
190
				return false;
191
			}
192
		}
193
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
194
    
195
    
196
    
197
		//-------------------------- SETTER ----------------------------------------------------------------------------//
198
199
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
200
	}