1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: anthony |
5
|
|
|
* Date: 08/12/2016 |
6
|
|
|
* Time: 20:44 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace modules\bataille\app\controller; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use core\App; |
13
|
|
|
|
14
|
|
|
class CentreRecherche { |
15
|
|
|
private $coef_centre; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
19
|
|
|
public function __construct() { |
20
|
|
|
$dbc = App::getDb(); |
21
|
|
|
$dbc1 = Bataille::getDb(); |
22
|
|
|
|
23
|
|
|
$query = $dbc1->select("coef_centre_recherche")->from("configuration")->where("ID_configuration", "=", 1)->get(); |
24
|
|
|
|
25
|
|
|
if ((is_array($query)) && (count($query) == 1)) { |
26
|
|
|
foreach ($query as $obj) $this->coef_centre = $obj->coef_centre_recherche; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$query = $dbc->select()->from("_bataille_centre_recherche")->where("ID_base", "=", Bataille::getIdBase())->get(); |
30
|
|
|
|
31
|
|
View Code Duplication |
if ((is_array($query)) && (count($query) > 0)) { |
|
|
|
|
32
|
|
|
foreach ($query as $obj) { |
33
|
|
|
$recherche_base[] = [ |
|
|
|
|
34
|
|
|
"recherche" => $obj->recherche, |
35
|
|
|
"niveau" => $obj->niveau, |
36
|
|
|
"type" => $obj->type |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$query = $dbc1->select()->from("recherche") |
42
|
|
|
->where("niveau_centre", "<=", Bataille::getBatiment()->getNiveauBatiment("centre_recherche")) |
43
|
|
|
->get(); |
44
|
|
|
|
45
|
|
View Code Duplication |
if ((is_array($query)) && (count($query) > 0)) { |
|
|
|
|
46
|
|
|
foreach ($query as $obj) { |
47
|
|
|
$all_recherche[] = [ |
|
|
|
|
48
|
|
|
"recherche" => $obj->recherche, |
49
|
|
|
"type" => $obj->type, |
50
|
|
|
"cout" => unserialize($obj->cout) |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$count = count($all_recherche); |
|
|
|
|
56
|
|
|
|
57
|
|
|
for ($i=0 ; $i<$count ; $i++) { |
58
|
|
|
if ((in_array($all_recherche[$i]["recherche"], $recherche_base[$i]))) { |
59
|
|
|
$niveau = $recherche_base[$i]["niveau"]; |
|
|
|
|
60
|
|
|
if ($niveau == 1) $this->coef_centre = 1; |
61
|
|
|
|
62
|
|
|
$all_recherche[$i]["cout"] = [ |
63
|
|
|
"eau" => $all_recherche[$i]["cout"]["eau"]*($this->coef_centre*$niveau), |
64
|
|
|
"electricite" => $all_recherche[$i]["cout"]["electricite"]*($this->coef_centre*$niveau), |
65
|
|
|
"fer" => $all_recherche[$i]["cout"]["fer"]*($this->coef_centre*$niveau), |
66
|
|
|
"fuel" => $all_recherche[$i]["cout"]["fuel"]*($this->coef_centre*$niveau) |
67
|
|
|
]; |
68
|
|
|
$ameliorer = true; |
69
|
|
|
} |
70
|
|
|
else { |
71
|
|
|
$ameliorer = false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$centre_recherche[] = [ |
|
|
|
|
75
|
|
|
"recherche" => $all_recherche[$i]["recherche"], |
76
|
|
|
"type" => $all_recherche[$i]["type"], |
77
|
|
|
"cout" => $all_recherche[$i]["cout"], |
78
|
|
|
"ameliorer" => $ameliorer |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
Bataille::setValues(["centre_recherche" => $centre_recherche]); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
|
88
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
89
|
|
|
/** |
90
|
|
|
* @param $type |
91
|
|
|
* @return array|int |
92
|
|
|
* permet de renvoyer toutes es recherches déjà effectuées pour notre base en fonction |
93
|
|
|
* d'un type donné |
94
|
|
|
*/ |
95
|
|
|
public function getAllRechercheType($type) { |
96
|
|
|
$dbc = App::getDb(); |
97
|
|
|
|
98
|
|
|
$query = $dbc->select()->from("_bataille_centre_recherche")->where("type", "=", $type)->get(); |
99
|
|
|
|
100
|
|
View Code Duplication |
if ((is_array($query)) && (count($query) > 0)) { |
|
|
|
|
101
|
|
|
foreach ($query as $obj) { |
102
|
|
|
$recherche[] = [ |
|
|
|
|
103
|
|
|
"niveau" => $obj->niveau, |
104
|
|
|
"recherche" => $obj->recherche |
105
|
|
|
]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $recherche; |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return 0; |
112
|
|
|
} |
113
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
|
117
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
118
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
119
|
|
|
|
120
|
|
|
} |
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.