Passed
Push — master ( 79a95c...32f7fb )
by Anthony
05:55
created

DroitAcces::getDroitAcces()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 2
nop 1
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
			$this->id_identite = $_SESSION["idlogin".CLEF_SITE];
28
29
			//on test voir si super admin
30
			$query = $dbc->select("super_admin")->select("liste_droit")->from("identite")->where("ID_identite", "=", $this->id_identite)->get();
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->select()->from("droit_acces")
75
				->from("liste_droit_acces")
76
				->from("liaison_liste_droit")
77
				->where("liste_droit_acces.ID_liste_droit_acces", "=", $this->id_liste_droit_acces, "AND")
78
				->where("droit_acces.ID_droit_acces", "=", "liaison_liste_droit.ID_droit_acces", "AND", true)
79
				->where("liste_droit_acces.ID_liste_droit_acces", "=", "liaison_liste_droit.ID_liste_droit_acces", "", true)
80
				->get();
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
		 * @param $id_page
91
		 */
92
		private function getListeDroitModificationContenu($id_page) {
93
			$dbc = App::getDb();
94
95
			//on check si il a le droit de modifier ou supprimer cette page
96
			$query = $dbc->select()->from("droit_acces_page")
97
				->from("liste_droit_acces")
98
				->where("droit_acces_page.ID_page", "=", $id_page, "AND")
99
				->where("liste_droit_acces.ID_liste_droit_acces", "=", $this->id_liste_droit_acces, "AND")
100
				->where("droit_acces_page.ID_liste_droit_acces", "=", "liste_droit_acces.ID_liste_droit_acces", "", true)
101
				->get();
102
103
			//si on a un resultat
104
			if ((is_array($query)) && (count($query) > 0)) {
105
				foreach ($query as $obj) {
106
					$this->modif_seo = $obj->seo;
107
					$this->modif_contenu = $obj->contenu;
108
					$this->modif_navigation = $obj->navigation;
109
					$this->supprimer_page = $obj->supprimer;
110
				}
111
			}
112
		}
113
114
		/**
115
		 * fonction qui permet de gérer les droits d'accès sur les contenus :
116
		 * - creer une page
117
		 * - modifier du contenu (SEO, navigation, contenu)
118
		 * - supprimer une page
119
		 * si on est super admin on passe outre tous les tests
120
		 * @param $droit
121
		 * @param $id_page
122
		 * @return bool|null
123
		 */
124
		public function getDroitAccesContenu($droit, $id_page) {
125
			$liste_droit_acces = $this->getListeDroitAcces();
126
127
			$this->getListeDroitModificationContenu($id_page);
128
129
			$array_modif = [$this->modif_seo, $this->modif_contenu, $this->modif_navigation];
130
131
			//si les trois sont différent de 0 on renvoit true soinon false
132
			if (($this->super_admin == 1) || ((in_array($droit, $liste_droit_acces)) && in_array(1, $array_modif))) {
133
				return true;
134
			}
135
			else {
136
				return false;
137
			}
138
		}
139
140
		/**
141
		 * pour savoir si un utilisateur à le droit de supprimer, modifier ou ajouter des trucs
142
		 * @param $droit_acces
143
		 * @return bool
144
		 */
145
		public function getDroitAcces($droit_acces) {
146
			$liste_droit_acces = $this->getListeDroitAcces();
147
148
			if (($this->super_admin == 1) || (in_array($droit_acces, $liste_droit_acces))) {
149
				return true;
150
			}
151
			else {
152
				return false;
153
			}
154
		}
155
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
156
    
157
    
158
    
159
		//-------------------------- SETTER ----------------------------------------------------------------------------//
160
161
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
162
	}