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