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