|
1
|
|
|
<?php |
|
2
|
|
|
namespace modules\bataille\app\controller; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class Points { |
|
6
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
|
7
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
|
11
|
|
|
/** |
|
12
|
|
|
* @param $id_base |
|
13
|
|
|
* @return int |
|
14
|
|
|
* renvoi les points de la base |
|
15
|
|
|
*/ |
|
16
|
|
|
public static function getPointsBase($id_base) { |
|
|
|
|
|
|
17
|
|
|
$dbc = App::getDb(); |
|
18
|
|
|
|
|
19
|
|
|
//on récupère les points de la base en cours |
|
20
|
|
|
$query = $dbc->select("points") |
|
21
|
|
|
->from("_bataille_base") |
|
22
|
|
|
->where("ID_base", "=", $id_base) |
|
23
|
|
|
->where("ID_identite", "=", $_SESSION['id_login'].CLEF_SITE) |
|
24
|
|
|
->get(); |
|
25
|
|
|
|
|
26
|
|
|
if ((is_array($query)) && (count($query) > 1)) { |
|
27
|
|
|
foreach ($query as $obj) { |
|
28
|
|
|
return $obj->points; |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
return 0; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return mixed |
|
37
|
|
|
* fonction qui renvoi le nombre de points à ajouter à la base lorsqu'on update un batiment |
|
38
|
|
|
*/ |
|
39
|
|
|
private static function getPointAjoutBatiment() { |
|
40
|
|
|
$dbc = self::getDb(); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$query = $dbc->select("points_batiment")->from("configuration")->where("ID_configuration", "=", 1)->get(); |
|
43
|
|
|
|
|
44
|
|
|
foreach ($query as $obj) return $obj->points_batiment; |
|
45
|
|
|
} |
|
46
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
|
50
|
|
|
/** |
|
51
|
|
|
* @param $id_base |
|
52
|
|
|
* @param $type |
|
53
|
|
|
* fonction qui ajoute des points à la base en fonction du type |
|
54
|
|
|
* le type peut etre : batiment, attaque, defense, troupe |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function setAjouterPoints($id_base, $type) { |
|
|
|
|
|
|
57
|
|
|
$dbc = App::getDb(); |
|
58
|
|
|
|
|
59
|
|
|
if ($type == "batiment") { |
|
60
|
|
|
$req = $dbc->update("points", self::getPointsBase($id_base)+self::getPointAjoutBatiment()); |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$req->from("_bataille_base") |
|
|
|
|
|
|
65
|
|
|
->where("ID_base", $id_base) |
|
66
|
|
|
->where("ID_identite", $_SESSION['id_login'].CLEF_SITE) |
|
67
|
|
|
->set(); |
|
68
|
|
|
} |
|
69
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
|
70
|
|
|
|
|
71
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: