Game-Jaming/Backend/Controllers/GameJam/GetGameJam.php

35 lines
1.0 KiB
PHP

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE");
require_once(realpath(dirname(__FILE__) . "/../../../bootstrap.php"));
use Backend\Models\GameJam;
if (isset($_GET['gameJamId'])) {
$dbValue = GameJam::find($_GET['gameJamId']);
}elseif (isset($_GET['hasEnded'])){
$hasEnded = $_GET['hasEnded'];
if($hasEnded == 0 OR $hasEnded == 1){
if ($hasEnded){
$dbValue = GameJam::where("is_finished",1)->get();
}else{
$dbValue = GameJam::where("is_finished",0)->get();
}
}
else{
$dbValue = GameJam::all();
}
}
else {
$dbValue = GameJam::all();
}
header('Content-Type: application/json;charset=UTF-8');
echo json_encode(array('data' => $dbValue->jsonSerialize()));
//var_dump(headers_list());