Passed
Push — master ( 1d9b86...df2d47 )
by Anthony
02:56
created

DroitAcces::getModifSeo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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