Passed
Push — master ( b9668a...d3086a )
by Anthony
04:34
created

RelationFaction::getIdFactionRelation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 11
nc 2
nop 1
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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
	}