1
|
|
|
<?php |
2
|
|
|
namespace modules\bataille\app\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
use core\HTML\flashmessage\FlashMessage; |
7
|
|
|
|
8
|
|
|
class Faction extends PermissionsFaction { |
9
|
|
|
protected $id_faction; |
10
|
|
|
|
11
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
12
|
|
|
public function __construct() { |
13
|
|
|
|
14
|
|
|
} |
15
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
19
|
|
|
public function getIdFaction(){ |
20
|
|
|
return $this->id_faction; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param $id_faction |
25
|
|
|
* @return bool |
26
|
|
|
* permet de tester si le joueur est dans la faction affichée |
27
|
|
|
*/ |
28
|
|
|
private function getTestFactionPlayer($id_faction) { |
29
|
|
|
$dbc = App::getDb(); |
30
|
|
|
$id_ma_faction = 0; |
31
|
|
|
|
32
|
|
|
$query = $dbc->select("ID_faction")->from("_bataille_infos_player")->where("ID_identite", "=", Bataille::getIdIdentite())->get(); |
33
|
|
|
|
34
|
|
|
foreach ($query as $obj) { |
35
|
|
|
$id_ma_faction = $obj->ID_faction; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ($id_ma_faction == $id_faction) { |
39
|
|
|
Bataille::setValues(["ma_faction" => true]); |
40
|
|
|
return true; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return false; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return mixed |
48
|
|
|
* fonction qui renvoi l'ID de la faction du joueur |
49
|
|
|
*/ |
50
|
|
|
public function getFactionPlayer($id_identite = null) { |
51
|
|
|
$dbc = App::getDb(); |
52
|
|
|
|
53
|
|
|
if ($id_identite === null) { |
54
|
|
|
$id_identite = Bataille::getIdIdentite(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$query = $dbc->select("ID_faction")->from("_bataille_infos_player") |
58
|
|
|
->where("ID_identite", "=", $id_identite, "AND") |
59
|
|
|
->where("ID_faction", ">", 0) |
60
|
|
|
->get(); |
61
|
|
|
|
62
|
|
|
if (count($query) > 0) { |
63
|
|
|
foreach ($query as $obj) { |
64
|
|
|
$this->id_faction = $obj->ID_faction; |
65
|
|
|
$this->getInfosFaction(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param null $id_faction |
76
|
|
|
* fonction qui récupère les infos de la faction |
77
|
|
|
*/ |
78
|
|
|
public function getInfosFaction($id_faction = null) { |
79
|
|
|
$dbc = App::getDb(); |
80
|
|
|
|
81
|
|
|
if ($id_faction === null) { |
82
|
|
|
$id_faction = $this->id_faction; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->getTestFactionPlayer($id_faction); |
86
|
|
|
|
87
|
|
|
$query = $dbc->select("identite.pseudo") |
88
|
|
|
->select("_bataille_faction.ID_faction") |
89
|
|
|
->select("_bataille_faction.nom_faction") |
90
|
|
|
->select("_bataille_faction.points_faction") |
91
|
|
|
->select("_bataille_faction.img_profil") |
92
|
|
|
->select("_bataille_faction.description") |
93
|
|
|
->from("_bataille_faction") |
94
|
|
|
->from("identite") |
95
|
|
|
->where("_bataille_faction.ID_faction", "=", $id_faction, "AND") |
96
|
|
|
->where("_bataille_faction.ID_identite", "=", "identite.ID_identite", "", true) |
97
|
|
|
->get(); |
98
|
|
|
|
99
|
|
|
if ((count($query) == 1)) { |
100
|
|
|
foreach ($query as $obj) { |
101
|
|
|
Bataille::setValues(["faction" => [ |
102
|
|
|
"id_faction" => $obj->ID_faction, |
103
|
|
|
"nom" => $obj->nom_faction, |
104
|
|
|
"points_faction" => $obj->points_faction, |
105
|
|
|
"description" => $obj->description, |
106
|
|
|
"url_img" => $obj->img_profil, |
107
|
|
|
"pseudo_chef" => $obj->pseudo |
108
|
|
|
]]); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* fonction qui récupère les membres d'un faction |
115
|
|
|
*/ |
116
|
|
|
public function getMembreFaction() { |
117
|
|
|
$dbc = App::getDb(); |
118
|
|
|
|
119
|
|
|
$query = $dbc->select() |
120
|
|
|
->from("_bataille_infos_player") |
121
|
|
|
->from("identite") |
122
|
|
|
->where("_bataille_infos_player.ID_faction", "=", $this->id_faction, "AND") |
123
|
|
|
->where("_bataille_infos_player.ID_identite", "=", "identite.ID_identite", "", true) |
124
|
|
|
->orderBy("_bataille_infos_player.points", "DESC") |
125
|
|
|
->get(); |
126
|
|
|
|
127
|
|
|
$membre = []; |
128
|
|
|
foreach ($query as $obj) { |
129
|
|
|
$membre[] = [ |
130
|
|
|
"id_identite" => $obj->ID_identite, |
131
|
|
|
"pseudo" => $obj->pseudo, |
132
|
|
|
"points" => $obj->points, |
133
|
|
|
"rang_faction" => $obj->rang_faction, |
134
|
|
|
"chef" => $this->getTestChefFaction($obj->ID_identite, $this->id_faction), |
135
|
|
|
"permissions" => $this->getMembrePermissions($obj->ID_identite, $this->id_faction) |
136
|
|
|
]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
Bataille::setValues(["membres_faction" => $membre]); |
140
|
|
|
} |
141
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
145
|
|
|
/** |
146
|
|
|
* @param $id_identite |
147
|
|
|
* @return bool |
148
|
|
|
* fonction qui permet de renvoyer un membre d'un faction |
149
|
|
|
*/ |
150
|
|
|
public function setRenvoyerMembre($id_identite) { |
151
|
|
|
$dbc = App::getDb(); |
152
|
|
|
$permissions_membre = $this->getPermissionsMembre($this->id_faction); |
153
|
|
|
|
154
|
|
|
if ($permissions_membre == "chef" || in_array("RENVOYER_MEMBRE", $permissions_membre)) { |
155
|
|
|
$dbc->update("ID_faction", 0) |
156
|
|
|
->update("rang_faction", "") |
157
|
|
|
->from("_bataille_infos_player") |
158
|
|
|
->where("ID_identite", "=", $id_identite, "AND") |
159
|
|
|
->where("ID_faction", "=", $this->id_faction, "", true) |
160
|
|
|
->set(); |
161
|
|
|
|
162
|
|
|
FlashMessage::setFlash("Le membre a bien été renvoyé de la faction", "success"); |
163
|
|
|
return true; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
FlashMessage::setFlash("Vous n'avez pas l'autorisation de renvoyer un membre"); |
167
|
|
|
return false; |
168
|
|
|
} |
169
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
170
|
|
|
} |