flash.moe/public/collection/dump.php
2020-08-20 00:02:37 +00:00

63 lines
1.8 KiB
PHP

<?php
require_once '_inc.php';
header('Content-Type: application/json; charset=utf-8');
$output = [];
$hideOwnershipInfo = !empty($_GET['h']);
switch(filter_input(INPUT_GET, 't')) {
case 'systems':
$getSystems = $pdo->prepare(sprintf(
'
SELECT s.*, (
SELECT COUNT(`game_id`)
FROM `col_games`
WHERE `sys_id` = s.`sys_id`
) AS `sys_games`%s
FROM `col_systems` AS s
',
$hideOwnershipInfo
? ''
: ',
(
SELECT COUNT(`game_id`)
FROM `col_games_ownership`
WHERE `game_id` IN (
SELECT `game_id`
FROM `col_games`
WHERE `sys_id` = s.`sys_id`
)
) AS `sys_games_owned`'
));
$getSystems->execute();
$output = $getSystems->fetchAll(PDO::FETCH_ASSOC);
break;
case 'games':
$sysId = filter_input(INPUT_GET, 'sys', FILTER_SANITIZE_NUMBER_INT);
$showAllGames = $sysId === null;
$getGames = $pdo->prepare(sprintf(
'
SELECT g.*%s
FROM `col_games` AS g
%s
',
$hideOwnershipInfo
? ''
: ', (
SELECT COUNT(`game_id`) > 0
FROM `col_games_ownership`
WHERE `game_id` = g.`game_id`
) AS `game_owned`',
$showAllGames ? '' : 'WHERE `sys_id` = :sys'
));
if(!$showAllGames)
$getGames->bindValue('sys', $sysId);
$getGames->execute();
$output = $getGames->fetchAll(PDO::FETCH_ASSOC);
break;
}
echo json_encode($output);