1
|
|
|
<?php |
2
|
|
|
namespace modules\bataille\app\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
use core\HTML\flashmessage\FlashMessage; |
7
|
|
|
|
8
|
|
|
class RelationFaction extends Faction { |
9
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
10
|
|
|
/** |
11
|
|
|
* renvoi la liste des relations d'une faction |
12
|
|
|
*/ |
13
|
|
View Code Duplication |
public function getListeRelation() { |
|
|
|
|
14
|
|
|
$dbc = App::getDb(); |
15
|
|
|
|
16
|
|
|
$query = $dbc->select()->from("_bataille_faction_relation") |
17
|
|
|
->from("_bataille_faction") |
18
|
|
|
->where("_bataille_faction_relation.ID_faction", "=", $this->id_faction, "AND") |
19
|
|
|
->where("_bataille_faction_relation.ID_autre_faction", "=", "_bataille_faction.ID_faction", "", true) |
20
|
|
|
->get(); |
21
|
|
|
|
22
|
|
|
$relations = []; |
23
|
|
|
if (count($query) > 0) { |
24
|
|
|
foreach ($query as $obj) { |
25
|
|
|
$relations[] = [ |
26
|
|
|
"id_relation" => $obj->ID_faction_relation, |
27
|
|
|
"relation" => $obj->relation, |
28
|
|
|
"id_autre_faction" => $obj->ID_autre_faction, |
29
|
|
|
"nom_autre_faction" => $obj->nom_faction |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
Bataille::setValues(["relations" => $relations]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* fonction qui récupère la liste des relations qu'il sera possible |
39
|
|
|
* de mettre dans le select |
40
|
|
|
*/ |
41
|
|
|
public function getAllRelationsPossible() { |
42
|
|
|
$dbc1 = Bataille::getDb(); |
43
|
|
|
|
44
|
|
|
$query = $dbc1->select()->from("faction_relations"); |
45
|
|
|
|
46
|
|
|
$relations = []; |
47
|
|
|
foreach ($query as $obj) { |
48
|
|
|
$relations[] = [ |
49
|
|
|
"relation" => $obj->relation |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
Bataille::setValues(["liste_relations" => $relations]); |
54
|
|
|
return $relations; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $relation |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function getIdFactionRelation($relation) { |
62
|
|
|
$dbc = App::getDb(); |
63
|
|
|
|
64
|
|
|
$query = $dbc->select("ID_autre_faction")->from("_bataille_faction_relation") |
65
|
|
|
->where("relation", "=", $relation, "AND") |
66
|
|
|
->where("ID_faction", "=", $this->id_faction) |
67
|
|
|
->get(); |
68
|
|
|
|
69
|
|
|
$relations = []; |
70
|
|
|
if (count($query) > 0) { |
71
|
|
|
foreach ($query as $obj) { |
72
|
|
|
$relations[] = $obj->ID_autre_faction; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $relations; |
77
|
|
|
} |
78
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
82
|
|
|
/** |
83
|
|
|
* @param $nom_faction |
84
|
|
|
* @param $relation |
85
|
|
|
* @return bool |
86
|
|
|
* fonction qui permet d'ajouter une relation |
87
|
|
|
*/ |
88
|
|
|
public function setAjouterRelation($nom_faction, $relation) { |
89
|
|
|
$dbc = App::getDb(); |
90
|
|
|
|
91
|
|
|
if ($this->getFactionExist($nom_faction) == false) { |
|
|
|
|
92
|
|
|
FlashMessage::setFlash("Cette faction n'existe pas, vérifiez que vous avez correctement écrit son nom"); |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$dbc->insert("relation", $relation) |
97
|
|
|
->insert("ID_faction", $this->id_faction) |
98
|
|
|
->insert("ID_autre_faction", $this->id_autre_faction) |
99
|
|
|
->into("_bataille_faction_relation")->set(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
103
|
|
|
} |
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.