Game-Jaming/Backend/Controllers/FileHandler/GetGameData.php

25 lines
1.1 KiB
PHP
Raw Normal View History

2021-03-11 12:20:10 +00:00
<?php
require_once "../../../bootstrap.php";
2021-04-19 07:15:15 +00:00
2021-03-11 12:20:10 +00:00
use \Backend\Models\GameData;
use \Backend\Models\Group;
2021-04-19 07:15:15 +00:00
use Backend\Models\Registration;
2021-03-11 12:20:10 +00:00
2021-04-19 07:15:15 +00:00
if (isset($_GET['gameDataId'])) {
$openGameDataStream = GameData::find($_GET['gameDataId']);
} elseif (isset($_GET['registrationId'])) {
$openGameDataStream = Registration::find($_GET['registrationId']);
} elseif (isset($_GET['groupId'])) {
$registrationIds = Registration::where("group_id", $_GET['groupId'])->pluck("game_data_id")->toArray();
$openGameDataStream = GameData::whereIn("id", $registrationIds)->get();
} elseif (isset($_GET['gameJamId'])) {
$gameDataIds = Group::where("game_jam_id", $_GET['gameJamId'])->pluck("game_data_id")->toArray();
2021-03-11 13:22:19 +00:00
$openGameDataStream = GameData::whereIn("id", $gameDataIds)->get();
2021-04-19 07:15:15 +00:00
} else {
2021-03-11 12:20:10 +00:00
$openGameDataStream = GameData::all();
}
2021-03-19 08:18:19 +00:00
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
2021-03-11 12:20:10 +00:00
header('Content-Type: application/json;charset=UTF-8');
2021-03-22 14:29:18 +00:00
echo json_encode(array('data' => $openGameDataStream->jsonSerialize()));