1
|
|
|
<?php |
2
|
|
|
namespace AL\Common\DAO; |
3
|
|
|
|
4
|
|
|
require_once __DIR__."/../../lib/Db.php" ; |
5
|
|
|
require_once __DIR__."/../Model/Game/GameRelease.php" ; |
6
|
|
|
require_once __DIR__."/../Model/Game/Memory.php" ; |
7
|
|
|
require_once __DIR__."/../Model/PubDev/PubDev.php" ; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* DAO for Game Releases |
11
|
|
|
*/ |
12
|
|
|
class GameReleaseDAO { |
13
|
|
|
private $mysqli; |
14
|
|
|
|
15
|
|
|
const LICENSE_COMMERCIAL = 'Commercial'; |
16
|
|
|
const LICENSE_NON_COMMERCIAL = 'Non-Commercial'; |
17
|
|
|
|
18
|
|
|
const TYPE_BUDGET = 'Budget'; |
19
|
|
|
const TYPE_RERELEASE = 'Re-release'; |
20
|
|
|
const TYPE_BUDGET_RERELEASE = 'Budget re-release'; |
21
|
|
|
const TYPE_PLAYABLE_DEMO = 'Playable demo'; |
22
|
|
|
const TYPE_NON_PLAYABLE_DEMO = 'Non-playable demo'; |
23
|
|
|
const TYPE_SLIDESHOW = 'Slideshow'; |
24
|
|
|
const TYPE_UNOFFICIAL = 'Unofficial'; |
25
|
|
|
const TYPE_DATADISK = 'Data disk'; |
26
|
|
|
const TYPE_REVIEWCOPY = 'Review copy'; |
27
|
|
|
|
28
|
|
|
const STATUS_DEVELOPMENT = 'Development'; |
29
|
|
|
const STATUS_UNFINISHED = 'Unfinished'; |
30
|
|
|
const STATUS_UNRELEASED = 'Unreleased'; |
31
|
|
|
|
32
|
|
|
public function __construct($mysqli) { |
33
|
|
|
$this->mysqli = $mysqli; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get all the license types |
38
|
|
|
* @return String[] A list of license types |
39
|
|
|
*/ |
40
|
|
|
public function getLicenseTypes() { |
41
|
|
|
return array( |
42
|
|
|
GameReleaseDAO::LICENSE_COMMERCIAL, |
43
|
|
|
GameReleaseDAO::LICENSE_NON_COMMERCIAL |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get all the game release types |
49
|
|
|
* @return String[] A list of game release types |
50
|
|
|
*/ |
51
|
|
|
public function getTypes() { |
52
|
|
|
return array( |
53
|
|
|
GameReleaseDAO::TYPE_BUDGET, |
54
|
|
|
GameReleaseDAO::TYPE_RERELEASE, |
55
|
|
|
GameReleaseDAO::TYPE_BUDGET_RERELEASE, |
56
|
|
|
GameReleaseDAO::TYPE_PLAYABLE_DEMO, |
57
|
|
|
GameReleaseDAO::TYPE_NON_PLAYABLE_DEMO, |
58
|
|
|
GameReleaseDAO::TYPE_SLIDESHOW, |
59
|
|
|
GameReleaseDAO::TYPE_UNOFFICIAL, |
60
|
|
|
GameReleaseDAO::TYPE_DATADISK, |
61
|
|
|
GameReleaseDAO::TYPE_REVIEWCOPY |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get all the game release status |
67
|
|
|
* @return String[] A list of game release status |
68
|
|
|
*/ |
69
|
|
|
public function getStatus() { |
70
|
|
|
return array( |
71
|
|
|
GameReleaseDAO::STATUS_DEVELOPMENT, |
72
|
|
|
GameReleaseDAO::STATUS_UNFINISHED, |
73
|
|
|
GameReleaseDAO::STATUS_UNRELEASED |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Insert a release for a game |
79
|
|
|
* |
80
|
|
|
* @param integer $game_id Id of the game the release is for |
81
|
|
|
* @param string $name Alternative name for the release (optional) |
82
|
|
|
* @param date $date Date of the release (optional) |
|
|
|
|
83
|
|
|
* @param string $license New license of the release |
84
|
|
|
* @param string $type New type of release |
85
|
|
|
* @param string $publisher_id New ID of the publisher of the release |
86
|
|
|
* @return integer ID of the inserted release |
87
|
|
|
*/ |
88
|
|
|
public function addReleaseForGame( |
89
|
|
|
$game_id, |
90
|
|
|
$name = null, |
91
|
|
|
$date = null, |
92
|
|
|
$license = null, |
93
|
|
|
$type = null, |
94
|
|
|
$status = null, |
95
|
|
|
$publisher_id = null, |
96
|
|
|
$hd_installable = null, |
97
|
|
|
$notes = null |
98
|
|
|
) { |
99
|
|
|
|
100
|
|
|
$stmt = \AL\Db\execute_query( |
101
|
|
|
"GameReleaseDAO: addReleaseForGame", |
102
|
|
|
$this->mysqli, |
103
|
|
|
"INSERT INTO game_release |
104
|
|
|
(game_id, `name`, `date`, license, type, pub_dev_id, status, hd_installable, notes) |
105
|
|
|
VALUES |
106
|
|
|
(?, ?, ?, ?, ?, ?, ?, ?, ?)", |
107
|
|
|
"issssiiss", $game_id, $name, $date, $license, $type, $publisher_id, $status, $hd_installable, $notes |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$id = $stmt->insert_id; |
111
|
|
|
|
112
|
|
|
$stmt->close(); |
113
|
|
|
|
114
|
|
|
return $id; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get all the releases for a game |
119
|
|
|
* @param integer $game_id ID of the game to get releases for |
120
|
|
|
* @return \AL\Common\Model\Game\GameRelease[] An array of releases |
121
|
|
|
*/ |
122
|
|
|
public function getReleasesForGame($game_id) { |
123
|
|
|
$stmt = \AL\Db\execute_query( |
124
|
|
|
"GameRelaseDAO: getReleasesForGame", |
125
|
|
|
$this->mysqli, |
126
|
|
|
"SELECT |
127
|
|
|
game_release.id, game_release.name, game_release.`date`, license, game_release.type, |
128
|
|
|
pub_dev.pub_dev_id, pub_dev.pub_dev_name, pub_dev_text.pub_dev_profile, |
129
|
|
|
pub_dev_text.pub_dev_imgext, game_release.status, game_release.hd_installable, game_release.notes, |
130
|
|
|
menu_sets.name, menus.number, menus.issue, menu_disks.part |
131
|
|
|
FROM game_release |
132
|
|
|
LEFT JOIN pub_dev ON game_release.pub_dev_id = pub_dev.pub_dev_id |
133
|
|
|
LEFT JOIN pub_dev_text ON pub_dev.pub_dev_id = pub_dev_text.pub_dev_id |
134
|
|
|
LEFT JOIN menu_disk_contents ON menu_disk_contents.game_release_id = game_release.id |
135
|
|
|
LEFT JOIN menu_disks ON menu_disk_contents.menu_disk_id = menu_disks.id |
136
|
|
|
LEFT JOIN menus ON menu_disks.menu_id = menus.id |
137
|
|
|
LEFT JOIN menu_sets ON menu_sets.id = menus.menu_set_id |
138
|
|
|
WHERE game_release.game_id = ? |
139
|
|
|
GROUP BY game_release.id |
140
|
|
|
ORDER BY date ASC", |
141
|
|
|
"i", $game_id |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
\AL\Db\bind_result( |
145
|
|
|
"GameRelaseDAO: getReleasesForGame", |
146
|
|
|
$stmt, |
147
|
|
|
$id, $name, $date, $license, $type, |
|
|
|
|
148
|
|
|
$pub_dev_id, $pub_dev_name, $pub_dev_profile, $pub_dev_imgext, |
|
|
|
|
149
|
|
|
$status, $hd_installable, $notes, |
|
|
|
|
150
|
|
|
$menu_set_name, $menu_number, $menu_issue, $menu_disk_part |
|
|
|
|
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
$releases = []; |
154
|
|
|
while ($stmt->fetch()) { |
155
|
|
|
$releases[] = new \AL\Common\Model\Game\GameRelease( |
156
|
|
|
$id, $game_id, $name, $date, $license, $type, |
157
|
|
|
($pub_dev_id != null) |
158
|
|
|
? new \AL\Common\Model\PubDev\PubDev($pub_dev_id, $pub_dev_name, $pub_dev_profile, $pub_dev_imgext) |
159
|
|
|
: null, |
160
|
|
|
$status, $hd_installable, $notes, $menu_set_name.' '.$menu_number.' '.$menu_issue.' '.$menu_disk_part |
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$stmt->close(); |
165
|
|
|
|
166
|
|
|
return $releases; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Get a single release from its ID |
171
|
|
|
* |
172
|
|
|
* @param integer $release_id ID of the release to get |
173
|
|
|
* @return \AL\Common\Model\Game\GameRelease a release, or null if not found |
174
|
|
|
*/ |
175
|
|
|
public function getRelease($release_id) { |
176
|
|
|
$stmt = \AL\Db\execute_query( |
177
|
|
|
"GameReleaseDAO: getRelease: $release_id", |
178
|
|
|
$this->mysqli, |
179
|
|
|
"SELECT |
180
|
|
|
game_release.id, game_release.game_id, game_release.name, game_release.`date`, license, |
181
|
|
|
game_release.type, pub_dev.pub_dev_id, pub_dev.pub_dev_name, pub_dev_text.pub_dev_profile, |
182
|
|
|
pub_dev_text.pub_dev_imgext, game_release.status, game_release.hd_installable, |
183
|
|
|
game_release.notes, |
184
|
|
|
menu_sets.name, menus.number, menus.issue, menu_disks.part |
185
|
|
|
FROM game_release |
186
|
|
|
LEFT JOIN pub_dev ON game_release.pub_dev_id = pub_dev.pub_dev_id |
187
|
|
|
LEFT JOIN pub_dev_text ON pub_dev.pub_dev_id = pub_dev_text.pub_dev_id |
188
|
|
|
LEFT JOIN menu_disk_contents ON menu_disk_contents.game_release_id = game_release.id |
189
|
|
|
LEFT JOIN menu_disks ON menu_disk_contents.menu_disk_id = menu_disks.id |
190
|
|
|
LEFT JOIN menus ON menu_disks.menu_id = menus.id |
191
|
|
|
LEFT JOIN menu_sets ON menu_sets.id = menus.menu_set_id |
192
|
|
|
WHERE game_release.id = ? |
193
|
|
|
GROUP BY game_release.id", |
194
|
|
|
"i", $release_id |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
\AL\Db\bind_result( |
198
|
|
|
"GameReleaseDAO: getRelease: $release_id", |
199
|
|
|
$stmt, |
200
|
|
|
$id, $game_id, $name, $date, $license, $type, |
|
|
|
|
201
|
|
|
$pub_dev_id, $pub_dev_name, $pub_dev_profile, $pub_dev_imgext, |
|
|
|
|
202
|
|
|
$status, $hd_installable, $notes, |
|
|
|
|
203
|
|
|
$menu_set_name, $menu_number, $menu_issue, $menu_disk_part |
|
|
|
|
204
|
|
|
); |
205
|
|
|
|
206
|
|
|
$release = null; |
207
|
|
|
if ($stmt->fetch()) { |
208
|
|
|
$release = new \AL\Common\Model\Game\GameRelease( |
209
|
|
|
$id, $game_id, $name, $date, $license, $type, |
210
|
|
|
($pub_dev_id != null) |
211
|
|
|
? new \AL\Common\Model\PubDev\PubDev($pub_dev_id, $pub_dev_name, $pub_dev_profile, $pub_dev_imgext) |
212
|
|
|
: null, |
213
|
|
|
$status, $hd_installable, $notes, $menu_set_name.' '.$menu_number.' '.$menu_issue.' '.$menu_disk_part |
214
|
|
|
); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
$stmt->close(); |
218
|
|
|
|
219
|
|
|
return $release; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Delete a release |
224
|
|
|
* |
225
|
|
|
* @param integer $release_id ID of the release to delete |
226
|
|
|
*/ |
227
|
|
|
public function deleteRelease($release_id) { |
228
|
|
|
// Delete linked data |
229
|
|
|
$stmt = \AL\Db\execute_query( |
|
|
|
|
230
|
|
|
"GameRelaseDAO: deleteRelease", |
231
|
|
|
$this->mysqli, |
232
|
|
|
"DELETE FROM game_release_resolution WHERE game_release_id = ?", |
233
|
|
|
"i", $release_id |
234
|
|
|
); |
235
|
|
|
$stmt = \AL\Db\execute_query( |
236
|
|
|
"GameRelaseDAO: deleteRelease", |
237
|
|
|
$this->mysqli, |
238
|
|
|
"DELETE FROM game_release_system_enhanced WHERE game_release_id = ?", |
239
|
|
|
"i", $release_id |
240
|
|
|
); |
241
|
|
|
$stmt = \AL\Db\execute_query( |
242
|
|
|
"GameRelaseDAO: deleteRelease", |
243
|
|
|
$this->mysqli, |
244
|
|
|
"DELETE FROM game_release_system_incompatible WHERE game_release_id = ?", |
245
|
|
|
"i", $release_id |
246
|
|
|
); |
247
|
|
|
$stmt = \AL\Db\execute_query( |
248
|
|
|
"GameRelaseDAO: deleteRelease", |
249
|
|
|
$this->mysqli, |
250
|
|
|
"DELETE FROM game_release_location WHERE game_release_id = ?", |
251
|
|
|
"i", $release_id |
252
|
|
|
); |
253
|
|
|
$stmt = \AL\Db\execute_query( |
254
|
|
|
"GameRelaseDAO: deleteRelease", |
255
|
|
|
$this->mysqli, |
256
|
|
|
"DELETE FROM game_release_aka WHERE game_release_id = ?", |
257
|
|
|
"i", $release_id |
258
|
|
|
); |
259
|
|
|
$stmt = \AL\Db\execute_query( |
260
|
|
|
"GameRelaseDAO: deleteRelease", |
261
|
|
|
$this->mysqli, |
262
|
|
|
"DELETE FROM game_release_trainer_option WHERE release_id = ?", |
263
|
|
|
"i", $release_id |
264
|
|
|
); |
265
|
|
|
$stmt = \AL\Db\execute_query( |
266
|
|
|
"GameRelaseDAO: deleteRelease", |
267
|
|
|
$this->mysqli, |
268
|
|
|
"DELETE FROM game_release_distributor WHERE game_release_id = ?", |
269
|
|
|
"i", $release_id |
270
|
|
|
); |
271
|
|
|
$stmt = \AL\Db\execute_query( |
272
|
|
|
"GameRelaseDAO: deleteRelease", |
273
|
|
|
$this->mysqli, |
274
|
|
|
"DELETE FROM game_release_emulator_incompatibility WHERE release_id = ?", |
275
|
|
|
"i", $release_id |
276
|
|
|
); |
277
|
|
|
$stmt = \AL\Db\execute_query( |
278
|
|
|
"GameRelaseDAO: deleteRelease", |
279
|
|
|
$this->mysqli, |
280
|
|
|
"DELETE FROM game_release_memory_enhanced WHERE release_id = ?", |
281
|
|
|
"i", $release_id |
282
|
|
|
); |
283
|
|
|
$stmt = \AL\Db\execute_query( |
284
|
|
|
"GameRelaseDAO: deleteRelease", |
285
|
|
|
$this->mysqli, |
286
|
|
|
"DELETE FROM game_release_memory_minimum WHERE release_id = ?", |
287
|
|
|
"i", $release_id |
288
|
|
|
); |
289
|
|
|
$stmt = \AL\Db\execute_query( |
290
|
|
|
"GameRelaseDAO: deleteRelease", |
291
|
|
|
$this->mysqli, |
292
|
|
|
"DELETE FROM game_release_tos_version_incompatibility WHERE release_id = ?", |
293
|
|
|
"i", $release_id |
294
|
|
|
); |
295
|
|
|
$stmt = \AL\Db\execute_query( |
296
|
|
|
"GameRelaseDAO: deleteRelease", |
297
|
|
|
$this->mysqli, |
298
|
|
|
"DELETE FROM game_release_copy_protection WHERE release_id = ?", |
299
|
|
|
"i", $release_id |
300
|
|
|
); |
301
|
|
|
$stmt = \AL\Db\execute_query( |
302
|
|
|
"GameRelaseDAO: deleteRelease", |
303
|
|
|
$this->mysqli, |
304
|
|
|
"DELETE FROM game_release_disk_protection WHERE release_id = ?", |
305
|
|
|
"i", $release_id |
306
|
|
|
); |
307
|
|
|
$stmt = \AL\Db\execute_query( |
308
|
|
|
"GameRelaseDAO: deleteRelease", |
309
|
|
|
$this->mysqli, |
310
|
|
|
"DELETE FROM game_release_language WHERE release_id = ?", |
311
|
|
|
"i", $release_id |
312
|
|
|
); |
313
|
|
|
$stmt = \AL\Db\execute_query( |
314
|
|
|
"GameRelaseDAO: deleteRelease", |
315
|
|
|
$this->mysqli, |
316
|
|
|
"DELETE FROM game_release WHERE id = ?", |
317
|
|
|
"i", $release_id |
318
|
|
|
); |
319
|
|
|
|
320
|
|
|
$stmt->close(); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Update the base attributes of a release |
325
|
|
|
* |
326
|
|
|
* @param integer $release_id ID of the release to update |
327
|
|
|
* @param string $name New name of the release |
328
|
|
|
* @param string $date New date of the release |
329
|
|
|
* @param string $license New license of the release |
330
|
|
|
* @param string $type New type of release |
331
|
|
|
* @param string $publisher_id New ID of the publisher of the release |
332
|
|
|
*/ |
333
|
|
|
public function updateRelease($release_id, $name, $date, $license, $type, $publisher_id, $status, $notes) { |
334
|
|
|
$stmt = \AL\Db\execute_query( |
335
|
|
|
"GameReleaseDAO: updateRelease", |
336
|
|
|
$this->mysqli, |
337
|
|
|
"UPDATE game_release |
338
|
|
|
SET |
339
|
|
|
`name` = ?, |
340
|
|
|
`date` = ?, |
341
|
|
|
`license` = ?, |
342
|
|
|
`type` = ?, |
343
|
|
|
`pub_dev_id` = ?, |
344
|
|
|
`status` = ?, |
345
|
|
|
`notes` = ? |
346
|
|
|
WHERE id = ?", |
347
|
|
|
"ssssissi", $name, $date, $license, $type, $publisher_id, $status, $notes, $release_id |
348
|
|
|
); |
349
|
|
|
|
350
|
|
|
$stmt->close(); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Update the hd_installable attribute of a release |
356
|
|
|
* |
357
|
|
|
* @param integer $release_id ID of the release to update |
358
|
|
|
* @param bool $hd_installable |
359
|
|
|
*/ |
360
|
|
|
public function updateHdRelease($release_id, $hd_installable) { |
361
|
|
|
$stmt = \AL\Db\execute_query( |
362
|
|
|
"GameReleaseDAO: updateHdRelease", |
363
|
|
|
$this->mysqli, |
364
|
|
|
"UPDATE game_release |
365
|
|
|
SET |
366
|
|
|
`hd_installable` = ? |
367
|
|
|
WHERE id = ?", |
368
|
|
|
"ii", $hd_installable, $release_id |
369
|
|
|
); |
370
|
|
|
|
371
|
|
|
$stmt->close(); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Get all the distinct release years we have in the DB |
376
|
|
|
* |
377
|
|
|
* @return integer[] List of years |
378
|
|
|
*/ |
379
|
|
|
public function getAllReleasesYears() { |
380
|
|
|
$stmt = \AL\Db\execute_query( |
381
|
|
|
"GameReleaseDAO: getAllReleasesYears", |
382
|
|
|
$this->mysqli, |
383
|
|
|
"SELECT DISTINCT YEAR(`date`) FROM game_release |
384
|
|
|
WHERE `date` IS NOT NULL AND `date` <> 0 |
385
|
|
|
ORDER by `date` ASC", |
386
|
|
|
null, null |
387
|
|
|
); |
388
|
|
|
|
389
|
|
|
\AL\Db\bind_result( |
390
|
|
|
"GameRelaseDAO: getAllReleases", |
391
|
|
|
$stmt, |
392
|
|
|
$year |
393
|
|
|
); |
394
|
|
|
|
395
|
|
|
$years = []; |
396
|
|
|
while ($stmt->fetch()) { |
397
|
|
|
$years[] = $year; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
$stmt->close(); |
401
|
|
|
|
402
|
|
|
return $years; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths