1
|
|
|
<?php |
2
|
|
|
namespace AL\Common\DAO; |
3
|
|
|
|
4
|
|
|
require_once __DIR__."/../../lib/Db.php" ; |
5
|
|
|
require_once __DIR__."/../Model/Game/TrainerOption.php" ; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* DAO for Trainer Option |
9
|
|
|
*/ |
10
|
|
|
class TrainerOptionDAO { |
11
|
|
|
private $mysqli; |
12
|
|
|
|
13
|
|
|
public function __construct($mysqli) { |
14
|
|
|
$this->mysqli = $mysqli; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get all Trainer Options |
19
|
|
|
* |
20
|
|
|
* @return \AL\Common\Model\Game\TrainerOptions[] An array of options |
21
|
|
|
*/ |
22
|
|
|
public function getAllTrainerOptions() { |
23
|
|
|
$stmt = \AL\Db\execute_query( |
24
|
|
|
"TrainerOptionDAO: getAllTrainerOptions", |
25
|
|
|
$this->mysqli, |
26
|
|
|
"SELECT id, name FROM trainer_option ORDER BY name", |
27
|
|
|
null, null |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
\AL\Db\bind_result( |
31
|
|
|
"TrainerOptionDAO: getAllTrainerOptions", |
32
|
|
|
$stmt, |
33
|
|
|
$id, $name |
|
|
|
|
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$trainer_options = []; |
37
|
|
|
while ($stmt->fetch()) { |
38
|
|
|
$trainer_options[] = new \AL\Common\Model\Game\TrainerOption( |
39
|
|
|
$id, $name |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$stmt->close(); |
44
|
|
|
|
45
|
|
|
return $trainer_options; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get list of trainer_option IDs for a game release |
50
|
|
|
* |
51
|
|
|
* @param integer release ID |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
public function getTrainerOptionsForRelease($release_id) { |
54
|
|
|
$stmt = \AL\Db\execute_query( |
55
|
|
|
"TrainerOptionDAO: getTrainerOptionsForRelease", |
56
|
|
|
$this->mysqli, |
57
|
|
|
"SELECT trainer_option_id, name |
58
|
|
|
FROM game_release_trainer_option LEFT JOIN |
59
|
|
|
trainer_option ON (game_release_trainer_option.trainer_option_id = trainer_option.id) |
60
|
|
|
WHERE release_id = ?", |
61
|
|
|
"i", $release_id |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
\AL\Db\bind_result( |
65
|
|
|
"TrainerOptionDAO: getTrainerOptionsForRelease", |
66
|
|
|
$stmt, |
67
|
|
|
$trainer_option_id, $name |
|
|
|
|
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$trainer_options = []; |
71
|
|
|
while ($stmt->fetch()) { |
72
|
|
|
$trainer_options[] = new \AL\Common\Model\Game\TrainerOption( |
73
|
|
|
$trainer_option_id, $name |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$stmt->close(); |
78
|
|
|
|
79
|
|
|
return $trainer_options; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set the list of trainer options for this release |
84
|
|
|
* |
85
|
|
|
* @param integer release ID |
86
|
|
|
* @param integer[] List of trainer option IDs |
|
|
|
|
87
|
|
|
*/ |
88
|
|
|
public function setTrainerOptionsForRelease($release_id, $trainer_option_id) { |
89
|
|
|
$stmt = \AL\Db\execute_query( |
90
|
|
|
"TrainerOptionDAO: setTrainerOptionsForRelease", |
91
|
|
|
$this->mysqli, |
92
|
|
|
"DELETE FROM game_release_trainer_option WHERE release_id = ?", |
93
|
|
|
"i", $release_id |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
foreach ($trainer_option_id as $id) { |
97
|
|
|
$stmt = \AL\Db\execute_query( |
98
|
|
|
"TrainerOptionDAO: setTrainerOptionsForRelease", |
99
|
|
|
$this->mysqli, |
100
|
|
|
"INSERT INTO game_release_trainer_option (release_id, trainer_option_id) VALUES (?, ?)", |
101
|
|
|
"ii", $release_id, $id |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$stmt->close(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* add a trainer_option to the database |
110
|
|
|
* |
111
|
|
|
* @param varchar trainer_option |
|
|
|
|
112
|
|
|
*/ |
113
|
|
|
public function addTrainerOption($trainer_option) { |
114
|
|
|
$stmt = \AL\Db\execute_query( |
115
|
|
|
"TrainerOptionDAO: addTrainerOption", |
116
|
|
|
$this->mysqli, |
117
|
|
|
"INSERT INTO trainer_option (`name`) VALUES (?)", |
118
|
|
|
"s", $trainer_option |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$stmt->close(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* delete a $trainer_option |
126
|
|
|
* |
127
|
|
|
* @param int $trainer_option_id |
128
|
|
|
*/ |
129
|
|
|
public function deleteTrainerOption($trainer_option_id) { |
130
|
|
|
$stmt = \AL\Db\execute_query( |
131
|
|
|
"TrainerOptionDAO: deleteTrainerOption", |
132
|
|
|
$this->mysqli, |
133
|
|
|
"DELETE FROM trainer_option WHERE id = ?", |
134
|
|
|
"i", $trainer_option_id |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$stmt->close(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* update a trainer_option |
142
|
|
|
* |
143
|
|
|
* @param int trainer_option_id |
|
|
|
|
144
|
|
|
* @param varchar trainer_option_name |
|
|
|
|
145
|
|
|
*/ |
146
|
|
|
public function updateTrainerOption($trainer_option_id, $trainer_option_name) { |
147
|
|
|
$stmt = \AL\Db\execute_query( |
148
|
|
|
"TrainerOptionDAO: updateTrainerOption", |
149
|
|
|
$this->mysqli, |
150
|
|
|
"UPDATE trainer_option SET name = ? WHERE id = ?", |
151
|
|
|
"si", $trainer_option_name, $trainer_option_id |
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
$stmt->close(); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|