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
|
|
|
* @return mixed |
20
|
|
|
* fonction qui renvoi l'ID de la faction du joueur |
21
|
|
|
*/ |
22
|
|
|
public function getFactionPlayer() { |
|
|
|
|
23
|
|
|
$dbc = App::getDb(); |
24
|
|
|
|
25
|
|
|
$query = $dbc->select("ID_faction")->from("_bataille_infos_player") |
26
|
|
|
->where("ID_identite", "=", Bataille::getIdIdentite(), "AND") |
27
|
|
|
->where("ID_faction", ">", 0) |
28
|
|
|
->get(); |
29
|
|
|
|
30
|
|
|
if ((count($query) > 0)) { |
31
|
|
|
foreach ($query as $obj) { |
32
|
|
|
$this->id_faction = $obj->ID_faction; |
33
|
|
|
$this->getInfosFaction(); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param null $id_faction |
40
|
|
|
* fonction qui récupère les infos de la faction |
41
|
|
|
*/ |
42
|
|
|
public function getInfosFaction($id_faction = null) { |
43
|
|
|
$dbc = App::getDb(); |
44
|
|
|
|
45
|
|
|
if ($id_faction === null) { |
46
|
|
|
$id_faction = $this->id_faction; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$query = $dbc->select("identite.pseudo") |
50
|
|
|
->select("_bataille_faction.nom_faction") |
51
|
|
|
->select("_bataille_faction.img_profil") |
52
|
|
|
->select("_bataille_faction.description") |
53
|
|
|
->from("_bataille_faction") |
54
|
|
|
->from("identite") |
55
|
|
|
->where("_bataille_faction.ID_faction", "=", $id_faction, "AND") |
56
|
|
|
->where("_bataille_faction.ID_identite", "=", "identite.ID_identite", "", true) |
57
|
|
|
->get(); |
58
|
|
|
|
59
|
|
|
if ((count($query) == 1)) { |
60
|
|
|
foreach ($query as $obj) { |
61
|
|
|
Bataille::setValues(["faction" => [ |
62
|
|
|
"nom" => $obj->nom_faction, |
63
|
|
|
"description" => $obj->description, |
64
|
|
|
"url_img" => $obj->img_profil, |
65
|
|
|
"pseudo_chef" => $obj->pseudo |
66
|
|
|
]]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* fonction qui récupère les membres d'un faction |
73
|
|
|
*/ |
74
|
|
|
public function getMembreFaction() { |
75
|
|
|
$dbc = App::getDb(); |
76
|
|
|
|
77
|
|
|
$query = $dbc->select() |
78
|
|
|
->from("_bataille_infos_player") |
79
|
|
|
->from("identite") |
80
|
|
|
->where("_bataille_infos_player.ID_faction", "=", $this->id_faction) |
81
|
|
|
->where("_bataille_infos_player.ID_identite", "=", "identite.ID_identite", "", true) |
82
|
|
|
->get(); |
83
|
|
|
|
84
|
|
|
$membre = []; |
85
|
|
|
foreach ($query as $obj) { |
86
|
|
|
$memebre[] = [ |
|
|
|
|
87
|
|
|
"pseudo" => $obj->pseudo, |
88
|
|
|
"points" => $obj->points |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
Bataille::setValues(["faction" => $membre]); |
93
|
|
|
} |
94
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
98
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
99
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.