1
|
|
|
<?php |
2
|
|
|
namespace modules\bataille\app\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
use core\functions\ChaineCaractere; |
7
|
|
|
|
8
|
|
|
class PermissionsFaction { |
9
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
10
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
14
|
|
|
/** |
15
|
|
|
* @param $id_identite |
16
|
|
|
* @param $id_faction |
17
|
|
|
* @return bool |
18
|
|
|
* permet de savoir si le joueur en question est le chef de la faction |
19
|
|
|
*/ |
20
|
|
|
protected function getTestChefFaction($id_identite, $id_faction) { |
21
|
|
|
$dbc = App::getDb(); |
22
|
|
|
|
23
|
|
|
$query = $dbc->select("ID_identite")->from("_bataille_faction") |
24
|
|
|
->where("ID_identite", "=", $id_identite, "AND") |
25
|
|
|
->where("ID_faction", "=", $id_faction) |
26
|
|
|
->get(); |
27
|
|
|
|
28
|
|
|
if (count($query) > 0) { |
29
|
|
|
return true; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return int |
37
|
|
|
* fonction qui renvoi le nombre de permissions |
38
|
|
|
*/ |
39
|
|
|
private function getNombrePermissions() { |
40
|
|
|
$dbc = App::getDb(); |
41
|
|
|
|
42
|
|
|
$query = $dbc->select()->from("_bataille_faction_permissions")->get(); |
43
|
|
|
|
44
|
|
|
return count($query); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return array |
49
|
|
|
* fonction qui liste toutes les permissions |
50
|
|
|
*/ |
51
|
|
|
public function getListPermissions() { |
52
|
|
|
$dbc = App::getDb(); |
53
|
|
|
|
54
|
|
|
$query = $dbc->select()->from("_bataille_faction_permissions")->get(); |
55
|
|
|
|
56
|
|
|
$permissions = []; |
57
|
|
|
if (count($query) > 0) { |
58
|
|
|
foreach ($query as $obj) { |
59
|
|
|
$permissions[] = str_replace("_", " ", $obj->permission); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
Bataille::setValues(["liste_permissions" => $permissions]); |
64
|
|
|
return $permissions; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $id_identite |
69
|
|
|
* @param $id_faction |
70
|
|
|
* @return array|string |
71
|
|
|
* permet de récupérer les permissions d'un membre de la faction |
72
|
|
|
*/ |
73
|
|
|
protected function getMembrePermissions($id_identite, $id_faction) { |
74
|
|
|
$dbc = App::getDb(); |
75
|
|
|
|
76
|
|
|
$nb_permissions = $this->getNombrePermissions(); |
77
|
|
|
|
78
|
|
|
if ($this->getTestChefFaction($id_identite, $id_faction) === true) { |
79
|
|
|
$permissions = []; |
80
|
|
|
for ($i=1 ; $i<=$nb_permissions ; $i++) { |
81
|
|
|
$permissions[$i] = "checked"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $permissions; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
$permissions = []; |
89
|
|
|
for ($i=1 ; $i<=$nb_permissions ; $i++) { |
90
|
|
|
$query = $dbc->select()->from("_bataille_faction_permission_player") |
91
|
|
|
->where("ID_faction", "=", $id_faction, "AND") |
92
|
|
|
->where("ID_identite", "=", $id_identite, "AND") |
93
|
|
|
->where("ID_permission", "=", $i) |
94
|
|
|
->get(); |
95
|
|
|
|
96
|
|
|
$permissions[$i] = ""; |
97
|
|
|
if (count($query) == 1) { |
98
|
|
|
$permissions[$i] = "checked"; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
return $permissions; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param $id_faction |
108
|
|
|
* @return bool |
109
|
|
|
* fonction qui renvoi les permission du membre connecté |
110
|
|
|
*/ |
111
|
|
|
public function getPermissionsMembre($id_faction) { |
112
|
|
|
$dbc = App::getDb(); |
113
|
|
|
|
114
|
|
|
if ($this->getTestChefFaction(Bataille::getIdIdentite(), $id_faction) == true) { |
|
|
|
|
115
|
|
|
Bataille::setValues(["permission_player" => "chef"]); |
116
|
|
|
return true; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$query = $dbc->select() |
120
|
|
|
->from("_bataille_faction_permission_player") |
121
|
|
|
->from("_bataille_faction_permissions") |
122
|
|
|
->where("ID_identite", "=", Bataille::getIdIdentite(), "AND") |
123
|
|
|
->where("ID_faction", "=", $id_faction, "AND") |
124
|
|
|
->where("_bataille_faction_permission_player.ID_permission", "=", "_bataille_faction_permissions.ID_permissions", "", true) |
125
|
|
|
->get(); |
126
|
|
|
|
127
|
|
|
$permissions = []; |
128
|
|
|
if ((count($query) > 0)) { |
129
|
|
|
foreach ($query as $obj) { |
130
|
|
|
$permissions[] = $obj->permission; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
Bataille::setValues(["permission_player" => $permissions]); |
135
|
|
|
} |
136
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
140
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
141
|
|
|
} |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.