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