1
|
|
|
<?php |
2
|
|
|
namespace modules\bataille\app\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
use core\HTML\flashmessage\FlashMessage; |
7
|
|
|
use modules\messagerie\app\controller\Messagerie; |
8
|
|
|
|
9
|
|
|
class Faction extends PermissionsFaction { |
10
|
|
|
protected $id_faction; |
11
|
|
|
protected $id_autre_faction; |
12
|
|
|
protected $nom_faction; |
13
|
|
|
|
14
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
15
|
|
|
public function __construct() { |
16
|
|
|
|
17
|
|
|
} |
18
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
22
|
|
|
public function getIdFaction(){ |
23
|
|
|
return $this->id_faction; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $id_faction |
28
|
|
|
* @return bool |
29
|
|
|
* permet de tester si le joueur est dans la faction affichée |
30
|
|
|
*/ |
31
|
|
|
private function getTestFactionPlayer($id_faction) { |
32
|
|
|
$dbc = App::getDb(); |
33
|
|
|
$id_ma_faction = 0; |
34
|
|
|
|
35
|
|
|
$query = $dbc->select("ID_faction")->from("_bataille_infos_player")->where("ID_identite", "=", Bataille::getIdIdentite())->get(); |
36
|
|
|
|
37
|
|
|
foreach ($query as $obj) { |
38
|
|
|
$id_ma_faction = $obj->ID_faction; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($id_ma_faction == $id_faction) { |
42
|
|
|
Bataille::setValues([ |
43
|
|
|
"ma_faction" => true, |
44
|
|
|
"id_identite_player" => Bataille::getIdIdentite() |
45
|
|
|
]); |
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return false; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return mixed |
54
|
|
|
* fonction qui renvoi l'ID de la faction du joueur |
55
|
|
|
*/ |
56
|
|
|
public function getFactionPlayer($id_identite = null) { |
57
|
|
|
$dbc = App::getDb(); |
58
|
|
|
|
59
|
|
|
if ($id_identite === null) { |
60
|
|
|
$id_identite = Bataille::getIdIdentite(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$query = $dbc->select("ID_faction")->from("_bataille_infos_player") |
64
|
|
|
->where("ID_identite", "=", $id_identite, "AND") |
65
|
|
|
->where("ID_faction", ">", 0) |
66
|
|
|
->get(); |
67
|
|
|
|
68
|
|
|
if (count($query) > 0) { |
69
|
|
|
foreach ($query as $obj) { |
70
|
|
|
$this->id_faction = $obj->ID_faction; |
71
|
|
|
$this->getInfosFaction(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->id_faction = ""; |
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param null $id_faction |
83
|
|
|
* fonction qui récupère les infos de la faction |
84
|
|
|
*/ |
85
|
|
|
public function getInfosFaction($id_faction = null) { |
86
|
|
|
$dbc = App::getDb(); |
87
|
|
|
|
88
|
|
|
if ($id_faction === null) { |
89
|
|
|
$id_faction = $this->id_faction; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->getTestFactionPlayer($id_faction); |
93
|
|
|
|
94
|
|
|
$query = $dbc->select("identite.pseudo") |
95
|
|
|
->select("_bataille_faction.ID_faction") |
96
|
|
|
->select("_bataille_faction.nom_faction") |
97
|
|
|
->select("_bataille_faction.points_faction") |
98
|
|
|
->select("_bataille_faction.img_profil") |
99
|
|
|
->select("_bataille_faction.description") |
100
|
|
|
->from("_bataille_faction") |
101
|
|
|
->from("identite") |
102
|
|
|
->where("_bataille_faction.ID_faction", "=", $id_faction, "AND") |
103
|
|
|
->where("_bataille_faction.ID_identite", "=", "identite.ID_identite", "", true) |
104
|
|
|
->get(); |
105
|
|
|
|
106
|
|
|
if ((count($query) == 1)) { |
107
|
|
|
foreach ($query as $obj) { |
108
|
|
|
Bataille::setValues(["faction" => [ |
109
|
|
|
"id_faction" => $obj->ID_faction, |
110
|
|
|
"nom" => $obj->nom_faction, |
111
|
|
|
"points_faction" => $obj->points_faction, |
112
|
|
|
"description" => $obj->description, |
113
|
|
|
"url_img" => $obj->img_profil, |
114
|
|
|
"pseudo_chef" => $obj->pseudo |
115
|
|
|
]]); |
116
|
|
|
|
117
|
|
|
$this->nom_faction = $obj->nom_faction; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return array |
124
|
|
|
* fonction qui récupère les membres d'un faction |
125
|
|
|
*/ |
126
|
|
|
public function getMembreFaction() { |
127
|
|
|
$dbc = App::getDb(); |
128
|
|
|
|
129
|
|
|
$query = $dbc->select() |
130
|
|
|
->from("_bataille_infos_player") |
131
|
|
|
->from("identite") |
132
|
|
|
->where("_bataille_infos_player.ID_faction", "=", $this->id_faction, "AND") |
133
|
|
|
->where("_bataille_infos_player.ID_identite", "=", "identite.ID_identite", "", true) |
134
|
|
|
->orderBy("_bataille_infos_player.points", "DESC") |
135
|
|
|
->get(); |
136
|
|
|
|
137
|
|
|
$membre = []; |
138
|
|
|
$liste_membre = []; |
139
|
|
|
foreach ($query as $obj) { |
140
|
|
|
$membre[] = [ |
141
|
|
|
"id_identite" => $obj->ID_identite, |
142
|
|
|
"pseudo" => $obj->pseudo, |
143
|
|
|
"points" => $obj->points, |
144
|
|
|
"rang_faction" => $obj->rang_faction, |
145
|
|
|
"chef" => $this->getTestChefFaction($obj->ID_identite, $this->id_faction), |
146
|
|
|
"permissions" => $this->getMembrePermissions($obj->ID_identite, $this->id_faction) |
147
|
|
|
]; |
148
|
|
|
|
149
|
|
|
$liste_membre[] = $obj->pseudo; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
Bataille::setValues(["membres_faction" => $membre]); |
153
|
|
|
|
154
|
|
|
return $liste_membre; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param $nom_faction |
159
|
|
|
* @return bool |
160
|
|
|
* ajout d'une fonction pour tester si une faction existe ou non renvoi true si elle existe |
161
|
|
|
*/ |
162
|
|
|
protected function getFactionExist($nom_faction) { |
163
|
|
|
$dbc = App::getDb(); |
164
|
|
|
|
165
|
|
|
$query = $dbc->select("ID_faction")->from("_bataille_faction")->where("nom_faction", "=", $nom_faction)->get(); |
166
|
|
|
|
167
|
|
|
if (count($query) > 0) { |
168
|
|
|
foreach ($query as $obj) { |
169
|
|
|
$this->id_autre_faction = $obj->ID_faction; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return true; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
return false; |
176
|
|
|
} |
177
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
181
|
|
|
/** |
182
|
|
|
* @param $id_identite |
183
|
|
|
* @return bool |
184
|
|
|
* fonction qui permet de renvoyer un membre d'un faction |
185
|
|
|
*/ |
186
|
|
|
public function setRenvoyerMembre($id_identite) { |
187
|
|
|
$dbc = App::getDb(); |
188
|
|
|
$permissions_membre = $this->getPermissionsMembre($this->id_faction); |
189
|
|
|
|
190
|
|
|
if ($permissions_membre == "chef" || in_array("RENVOYER_MEMBRE", $permissions_membre)) { |
191
|
|
|
$dbc->update("ID_faction", 0) |
192
|
|
|
->update("rang_faction", "") |
193
|
|
|
->from("_bataille_infos_player") |
194
|
|
|
->where("ID_identite", "=", $id_identite, "AND") |
195
|
|
|
->where("ID_faction", "=", $this->id_faction, "", true) |
196
|
|
|
->set(); |
197
|
|
|
|
198
|
|
|
$this->setSupprilerAllPermissions($id_identite); |
199
|
|
|
|
200
|
|
|
FlashMessage::setFlash("Le membre a bien été renvoyé de la faction", "success"); |
201
|
|
|
return true; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
FlashMessage::setFlash("Vous n'avez pas l'autorisation de renvoyer un membre"); |
205
|
|
|
return false; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param $pseudo |
210
|
|
|
* @return bool |
211
|
|
|
*/ |
212
|
|
|
public function setInviterMembre($pseudo) { |
213
|
|
|
$dbc = App::getDb(); |
214
|
|
|
$permissions_membre = $this->getPermissionsMembre($this->id_faction); |
215
|
|
|
|
216
|
|
|
if ($permissions_membre == "chef" || in_array("INVITER_MEMBRE", $permissions_membre)) { |
217
|
|
|
$id_identite = Bataille::getPlayerExist($pseudo); |
218
|
|
|
if ($id_identite== false) { |
|
|
|
|
219
|
|
|
FlashMessage::setFlash("Ce joueur n'existe pas"); |
220
|
|
|
return false; |
221
|
|
|
} |
222
|
|
|
if (in_array($pseudo, $this->getMembreFaction())) { |
223
|
|
|
FlashMessage::setFlash("Ce joueur est déjà dans votre faction ou est en attente d'invitation, vous ne pouvez pas l'inviter à nouveau"); |
224
|
|
|
return false; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
$infos = [ |
228
|
|
|
"nom_faction" => $this->nom_faction |
229
|
|
|
]; |
230
|
|
|
|
231
|
|
|
require(MODULEROOT."bataille/app/controller/rapports/invitation-faction.php"); |
232
|
|
|
|
233
|
|
|
$messagerie = new Messagerie(); |
234
|
|
|
$messagerie->setEnvoyerMessage("Invitation rejoindre faction", $id_identite, $message); |
|
|
|
|
235
|
|
|
|
236
|
|
|
$dbc->insert("ID_faction", $this->id_faction)->insert("ID_identite", $id_identite) |
237
|
|
|
->into("_bataille_faction_invitation")->set(); |
238
|
|
|
return true; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
FlashMessage::setFlash("Vous n'avez pas l'autorisation d'inviter un membre"); |
242
|
|
|
return false; |
243
|
|
|
} |
244
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
245
|
|
|
} |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.