1
|
|
|
<?php |
2
|
|
|
namespace AL\Common\DAO; |
3
|
|
|
|
4
|
|
|
require_once __DIR__."/../../lib/Db.php" ; |
5
|
|
|
require_once __DIR__."/../Model/Game/Emulator.php" ; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* DAO for Emulators |
9
|
|
|
*/ |
10
|
|
|
class EmulatorDAO { |
11
|
|
|
private $mysqli; |
12
|
|
|
|
13
|
|
|
public function __construct($mysqli) { |
14
|
|
|
$this->mysqli = $mysqli; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get all emulators |
19
|
|
|
* |
20
|
|
|
* @return \AL\Common\Model\Game\Emulator[] An array of emulators |
21
|
|
|
*/ |
22
|
|
|
public function getAllEmulators() { |
23
|
|
|
$stmt = \AL\Db\execute_query( |
24
|
|
|
"EmulatorDAO: getAllEmulator", |
25
|
|
|
$this->mysqli, |
26
|
|
|
"SELECT id, name FROM emulator ORDER by name", |
27
|
|
|
null, null |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
\AL\Db\bind_result( |
31
|
|
|
"EmulatorDAO: getAllEmulator", |
32
|
|
|
$stmt, |
33
|
|
|
$id, $name |
|
|
|
|
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$emulators = []; |
37
|
|
|
while ($stmt->fetch()) { |
38
|
|
|
$emulators[] = new \AL\Common\Model\Game\Emulator( |
39
|
|
|
$id, $name |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$stmt->close(); |
44
|
|
|
|
45
|
|
|
return $emulators; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get a map containing all emulators, indexed by ID |
50
|
|
|
* |
51
|
|
|
* @return \AL\Common\Model\Game\Emulator[] A map of emulators |
52
|
|
|
*/ |
53
|
|
|
public function getAllEmulatorsAsMap() { |
54
|
|
|
$emulators = $this->getAllEmulators(); |
55
|
|
|
$emulatorsMap = array(); |
56
|
|
|
foreach ($emulators as $emulator) { |
57
|
|
|
$emulatorsMap[$emulator->getId()] = $emulator; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $emulatorsMap; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get all emulator IDs incompatible with a release |
65
|
|
|
* |
66
|
|
|
* @param integer Release ID |
|
|
|
|
67
|
|
|
* @return integer[] List of incompatible emulator IDs |
68
|
|
|
*/ |
69
|
|
|
public function getIncompatibleEmulatorIdsForRelease($release_id) { |
70
|
|
|
$stmt = \AL\Db\execute_query( |
71
|
|
|
"EmulatorDAO: getIncompatibleEmulatorIdsForRelease", |
72
|
|
|
$this->mysqli, |
73
|
|
|
"SELECT emulator_id FROM game_release_emulator_incompatibility WHERE release_id = ?", |
74
|
|
|
"i", $release_id |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
\AL\Db\bind_result( |
78
|
|
|
"EmulatorDAO: getIncompatibleEmulatorIdsForRelease", |
79
|
|
|
$stmt, |
80
|
|
|
$emulator_id |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$emulators = []; |
84
|
|
|
while ($stmt->fetch()) { |
85
|
|
|
$emulators[] = $emulator_id; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$stmt->close(); |
89
|
|
|
|
90
|
|
|
return $emulators; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get all emulator incompatible with a release |
95
|
|
|
* |
96
|
|
|
* @param integer Release ID |
97
|
|
|
* @return integer[] List of incompatible emulators |
98
|
|
|
*/ |
99
|
|
|
public function getIncompatibleEmulatorForRelease($release_id) { |
100
|
|
|
$stmt = \AL\Db\execute_query( |
101
|
|
|
"EmulatorDAO: getIncompatibleEmulatorForRelease", |
102
|
|
|
$this->mysqli, |
103
|
|
|
"SELECT emulator.id, emulator.name |
104
|
|
|
FROM game_release_emulator_incompatibility |
105
|
|
|
JOIN emulator on game_release_emulator_incompatibility.emulator_id = emulator.id |
106
|
|
|
WHERE release_id = ?", |
107
|
|
|
"i", $release_id |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
\AL\Db\bind_result( |
111
|
|
|
"EmulatorDAO: getIncompatibleEmulatorForRelease", |
112
|
|
|
$stmt, |
113
|
|
|
$id, $name |
|
|
|
|
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
$emulators = []; |
117
|
|
|
while ($stmt->fetch()) { |
118
|
|
|
$emulators[] = new \AL\Common\Model\Game\Emulator( |
119
|
|
|
$id, $name |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
$stmt->close(); |
124
|
|
|
|
125
|
|
|
return $emulators; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get all emulator IDs incompatible with a release |
131
|
|
|
* |
132
|
|
|
* @param integer Release ID |
133
|
|
|
* @return integer[] List of incompatible emulator IDs |
134
|
|
|
*/ |
135
|
|
|
public function getIncompatibleEmulatorsWithNameForRelease($release_id) { |
136
|
|
|
$stmt = \AL\Db\execute_query( |
137
|
|
|
"EmulatorDAO: getIncompatibleEmulatorIdsForRelease", |
138
|
|
|
$this->mysqli, |
139
|
|
|
"SELECT game_release_emulator_incompatibility.emulator_id, |
140
|
|
|
emulator.name FROM game_release_emulator_incompatibility |
141
|
|
|
LEFT JOIN emulator ON (game_release_emulator_incompatibility.emulator_id = emulator.id) |
142
|
|
|
WHERE release_id = ?", |
143
|
|
|
"i", $release_id |
144
|
|
|
); |
145
|
|
|
|
146
|
|
|
\AL\Db\bind_result( |
147
|
|
|
"EmulatorDAO: getIncompatibleEmulatorIdsForRelease", |
148
|
|
|
$stmt, |
149
|
|
|
$emulator_id, $emulator_name |
|
|
|
|
150
|
|
|
); |
151
|
|
|
|
152
|
|
|
$emulators = []; |
153
|
|
|
while ($stmt->fetch()) { |
154
|
|
|
$emulators[] = new \AL\Common\Model\Game\Emulator($emulator_id, $emulator_name); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$stmt->close(); |
158
|
|
|
|
159
|
|
|
return $emulators; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Set the list of emulators a release is incompatible with |
164
|
|
|
* |
165
|
|
|
* @param integer Release ID |
166
|
|
|
* @param integer[] List of emulator IDs |
|
|
|
|
167
|
|
|
*/ |
168
|
|
|
public function setIncompatibleEmulatorsForRelease($release_id, $emulators) { |
169
|
|
|
$stmt = \AL\Db\execute_query( |
170
|
|
|
"EmulatorDAO: setIncompatibleEmulatorsForRelease", |
171
|
|
|
$this->mysqli, |
172
|
|
|
"DELETE FROM game_release_emulator_incompatibility WHERE release_id = ?", |
173
|
|
|
"i", $release_id |
174
|
|
|
); |
175
|
|
|
|
176
|
|
|
foreach ($emulators as $id) { |
177
|
|
|
$stmt = \AL\Db\execute_query( |
178
|
|
|
"EmulatorDAO: setIncompatibleEmulatorsForRelease", |
179
|
|
|
$this->mysqli, |
180
|
|
|
"INSERT INTO game_release_emulator_incompatibility (release_id, emulator_id) VALUES (?, ?)", |
181
|
|
|
"ii", $release_id, $id |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$stmt->close(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* add a emulator to the database |
190
|
|
|
* |
191
|
|
|
* @param varchar emulator |
192
|
|
|
*/ |
193
|
|
|
public function addEmulator($emulator) { |
194
|
|
|
$stmt = \AL\Db\execute_query( |
195
|
|
|
"EmulatorDAO: addEmulator", |
196
|
|
|
$this->mysqli, |
197
|
|
|
"INSERT INTO emulator (`name`) VALUES (?)", |
198
|
|
|
"s", $emulator |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
$stmt->close(); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* delete a emulator |
206
|
|
|
* |
207
|
|
|
* @param int emulator_id |
|
|
|
|
208
|
|
|
*/ |
209
|
|
|
public function deleteEmulator($emulator_id) { |
210
|
|
|
$stmt = \AL\Db\execute_query( |
211
|
|
|
"EmulatorDAO: deleteEmulator", |
212
|
|
|
$this->mysqli, |
213
|
|
|
"DELETE FROM emulator WHERE id = ?", |
214
|
|
|
"i", $emulator_id |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$stmt->close(); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* update a emulator |
222
|
|
|
* |
223
|
|
|
* @param int emulator_id |
224
|
|
|
* @param varchar emulator_name |
|
|
|
|
225
|
|
|
*/ |
226
|
|
|
public function updateEmulator($emulator_id, $emulator_name) { |
227
|
|
|
$stmt = \AL\Db\execute_query( |
228
|
|
|
"EmulatorDAO: updateEmulator", |
229
|
|
|
$this->mysqli, |
230
|
|
|
"UPDATE emulator SET name = ? WHERE id = ?", |
231
|
|
|
"si", $emulator_name, $emulator_id |
232
|
|
|
); |
233
|
|
|
|
234
|
|
|
$stmt->close(); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|