1
|
|
|
<?php |
2
|
|
|
namespace modules\bataille\app\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
|
7
|
|
|
class MissionsAleatoire { |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
|
11
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
12
|
|
|
public function __construct() { |
13
|
|
|
$dbc = App::getDb(); |
14
|
|
|
|
15
|
|
|
$query = $dbc->select("last_check_mission")->from("_bataille_base")->where("ID_base", "=", Bataille::getIdBase())->get(); |
16
|
|
|
|
17
|
|
|
if (is_array($query) && (count($query) == 1)) { |
18
|
|
|
foreach ($query as $obj) { |
19
|
|
|
$last_check_mission = $obj->last_check_mission; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
if ($last_check_mission == "") { |
23
|
|
|
$this->setUpdateLastCheckMissions(); |
24
|
|
|
$this->setMissionsAleatoire(); |
25
|
|
|
} |
26
|
|
|
else { |
27
|
|
|
$today = new \DateTime(); |
28
|
|
|
$last_check_mission = new \DateTime($last_check_mission); |
|
|
|
|
29
|
|
|
$interval = $last_check_mission->diff($today); |
30
|
|
|
|
31
|
|
|
$diff_jour = explode("+", $interval->format("%R%a"))[1]; |
32
|
|
|
|
33
|
|
|
if ($diff_jour >= 1) { |
34
|
|
|
$this->setUpdateLastCheckMissions(); |
35
|
|
|
$this->setMissionsAleatoire(); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
45
|
|
|
/** |
46
|
|
|
* fonction qui récupere tous les types de missions et les return dans un array |
47
|
|
|
*/ |
48
|
|
|
private function getTypeMission() { |
49
|
|
|
return explode(",", Bataille::getParam("type_missions")); |
50
|
|
|
} |
51
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
|
55
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
56
|
|
|
/** |
57
|
|
|
* fonction qui met a jour le last_ckeck_missions dans _bataille_base |
58
|
|
|
* le met à la date du jour |
59
|
|
|
*/ |
60
|
|
|
public function setUpdateLastCheckMissions() { |
61
|
|
|
$dbc = App::getDb(); |
62
|
|
|
|
63
|
|
|
$dbc->update("last_check_mission", date("Y-m-d")) |
64
|
|
|
->from("_bataille_base") |
65
|
|
|
->where("ID_base", "=", Bataille::getIdBase()) |
66
|
|
|
->set(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $type |
71
|
|
|
* fonction qui recupere des missions aleatoirement de chaque type et qui les ajoute |
72
|
|
|
* dans la table _bataille_mission_aleatoire |
73
|
|
|
*/ |
74
|
|
|
private function setMissionsAleatoire() { |
75
|
|
|
$dbc = App::getDb(); |
76
|
|
|
$dbc1 = Bataille::getDb(); |
77
|
|
|
|
78
|
|
|
$dbc->delete()->from("_bataille_mission_aleatoire")->where("ID_base", "=", Bataille::getIdBase())->del(); |
79
|
|
|
|
80
|
|
|
$type_missions = $this->getTypeMission(); |
81
|
|
|
|
82
|
|
|
foreach ($type_missions as $un_type) { |
83
|
|
|
$query = $dbc1->select()->from("mission") |
84
|
|
|
->where("type", "=", $un_type) |
85
|
|
|
->orderBy("RAND()") |
86
|
|
|
->limit(0, 3) |
87
|
|
|
->get(); |
88
|
|
|
|
89
|
|
|
if ((is_array($query)) && (count($query))) { |
90
|
|
|
foreach ($query as $obj) { |
91
|
|
|
$dbc->insert("ID_mission", $obj->ID_mission) |
92
|
|
|
->insert("ID_base", Bataille::getIdBase()) |
93
|
|
|
->into("_bataille_mission_aleatoire") |
94
|
|
|
->set(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
100
|
|
|
|
101
|
|
|
} |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: