new database
This commit is contained in:
@@ -13,15 +13,15 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp): string
|
||||
$headerType = mime_content_type($gameFileTmp);
|
||||
$headerTypeMatch = array('application/zip');
|
||||
|
||||
if(in_array($headerType,$headerTypeMatch)){
|
||||
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
||||
if(empty($gameFileName)){
|
||||
if (in_array($headerType, $headerTypeMatch)) {
|
||||
$gameFileNewName = uniqid("", true) . "." . $fileActualExtGame;
|
||||
if (empty($gameFileName)) {
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
||||
rename($gameFileTmp, "../../Games/" . $gameFileNewName);
|
||||
return $gameFileNewName;
|
||||
}else{
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Wrong file type gameFile"]);
|
||||
exit();
|
||||
@@ -39,17 +39,17 @@ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp):
|
||||
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
||||
|
||||
$headerType = mime_content_type($thumbnailFileTmp);
|
||||
$headerTypeMatch = array('image/png', 'image/jpeg','image/gif', 'image/svg+xml',);
|
||||
$headerTypeMatch = array('image/png', 'image/jpeg', 'image/gif', 'image/svg+xml',);
|
||||
|
||||
if(in_array($headerType,$headerTypeMatch)){
|
||||
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
|
||||
if(empty($thumbnailFileName)){
|
||||
if (in_array($headerType, $headerTypeMatch)) {
|
||||
$thumbnailFileNewName = uniqid("", true) . "." . $fileActualExtThumb;
|
||||
if (empty($thumbnailFileName)) {
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
||||
rename($thumbnailFileTmp, "../../../Frontend/images/" . $thumbnailFileNewName);
|
||||
return $thumbnailFileNewName;
|
||||
}else{
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Wrong file type thumbnailFile"]);
|
||||
exit();
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
<?php
|
||||
require_once "../../../bootstrap.php";
|
||||
|
||||
use \Backend\Models\GameData;
|
||||
use \Backend\Models\Group;
|
||||
use Backend\Models\Registration;
|
||||
|
||||
if(isset($_GET['gameDataId'])){
|
||||
$openGameDataStream = GameData::find($_GET['gameDataId']);
|
||||
}elseif(isset($_GET['groupId'])){
|
||||
$openGameDataStream = Group::find($_GET['groupId'])->GameData();
|
||||
}elseif (isset($_GET['gameJamId'])){
|
||||
$gameDataIds = Group::where("game_jam_id",$_GET['gameJamId'])->pluck("game_data_id")->toArray();
|
||||
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();
|
||||
$openGameDataStream = GameData::whereIn("id", $gameDataIds)->get();
|
||||
}else{
|
||||
} else {
|
||||
$openGameDataStream = GameData::all();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,31 @@
|
||||
require_once "../../../bootstrap.php";
|
||||
require_once('../Group/Group.php');
|
||||
require_once('FileHandler.php');
|
||||
use Backend\Models\GameData;
|
||||
|
||||
if(isLogin()){
|
||||
if(isset($_POST['submitUpdate'])){
|
||||
use Backend\Models\GameData;
|
||||
use Backend\Models\Registration;
|
||||
|
||||
if (isLogin()) {
|
||||
if (isset($_POST['submitUpdate'])) {
|
||||
//Get the game data
|
||||
$gameData = GameData::find($_POST['gameDataId']);
|
||||
if ($gameData === null) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "game data not found"]);
|
||||
exit();
|
||||
}
|
||||
//Get the group
|
||||
$group = groupViaToken($_SESSION['token']);
|
||||
if (!in_array($gameData->id, Registration::where("group_id", $group->id)->pluck("game_data_id")->toArray())) {
|
||||
http_response_code(401);
|
||||
exit();
|
||||
}
|
||||
|
||||
$gameFile = $_FILES['gameFile'];
|
||||
$desc = $_POST['description'];
|
||||
$title = $_POST['gameTitle'];
|
||||
$thumbnail = $_FILES['thumbnailFile'];
|
||||
$isWebBased = isset( $_POST['isWebBased']);
|
||||
$isWebBased = isset($_POST['isWebBased']);
|
||||
|
||||
$gameFileName = $_FILES['gameFile']['name'];//Game name
|
||||
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
|
||||
@@ -18,34 +34,29 @@ if(isLogin()){
|
||||
|
||||
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
||||
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
||||
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
|
||||
$thumbnailFileError = $_FILES['thumbnailFile']['error'];//File error
|
||||
|
||||
|
||||
//Get the group
|
||||
$group = groupViaToken($_SESSION['token']);
|
||||
//Get the game data, from the group
|
||||
$gameData = GameData::find($group->game_data_id);
|
||||
$gameData->game_name = $title;
|
||||
if(isset($gameData) && $gameFileError === 0){
|
||||
unlink("../../Games/".$gameData->game_link);
|
||||
$gameData->game_link = ZipFileHandler($gameFileName,$gameFileTmp);
|
||||
if (isset($gameData) && $gameFileError === 0) {
|
||||
unlink("../../Games/" . $gameData->game_link);
|
||||
$gameData->game_link = ZipFileHandler($gameFileName, $gameFileTmp);
|
||||
}
|
||||
$gameData->description = $desc;
|
||||
if(isset($thumbnail) && $thumbnailFileError === 0){
|
||||
unlink("../../../Frontend/images/".$gameData->img);
|
||||
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
|
||||
if (isset($thumbnail) && $thumbnailFileError === 0) {
|
||||
unlink("../../../Frontend/images/" . $gameData->img);
|
||||
$gameData->img = imagesFileHandler($thumbnailFileName, $thumbnailFileTmp);
|
||||
}
|
||||
$gameData->is_web_Based = $isWebBased;
|
||||
if(!$gameData->save()){
|
||||
http_response_code(500);
|
||||
}else{
|
||||
http_response_code(201);
|
||||
if (!$gameData->save()) {
|
||||
http_response_code(500);
|
||||
} else {
|
||||
http_response_code(201);
|
||||
}
|
||||
|
||||
}else{
|
||||
http_response_code(400);
|
||||
} else {
|
||||
http_response_code(400);
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not login"]);
|
||||
} else {
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not login"]);
|
||||
}
|
||||
@@ -2,8 +2,10 @@
|
||||
require_once "../../../bootstrap.php";
|
||||
require_once('../Group/Group.php');
|
||||
require_once('FileHandler.php');
|
||||
|
||||
use Backend\Models\GameData;
|
||||
use Backend\Models\GameJam;
|
||||
use Backend\Models\Registration;
|
||||
|
||||
use Backend\Models\Group;
|
||||
|
||||
@@ -12,26 +14,37 @@ date_default_timezone_set("Europe/Copenhagen");
|
||||
$isImages = false;
|
||||
|
||||
|
||||
if(isLogin()){
|
||||
if (isLogin()) {
|
||||
if (isset($_POST['submitUpload'])) {
|
||||
$group = groupViaToken($_SESSION['token']);
|
||||
$gameJam = GameJam::find($_POST['gameJamId']);
|
||||
if ($gameJam === null) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "gameJam not found"]);
|
||||
exit();
|
||||
}
|
||||
$registration = Registration::where('game_jam_id', $gameJam->id)->where("group_id", $group->id)->frist();
|
||||
if ($registration === null) {
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "group not registered for that game jam"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$group = groupViaToken($_SESSION['token']);
|
||||
|
||||
$gameJam = GameJam::find($group->game_jam_id);
|
||||
$gameJamStartTime = strtotime($gameJam->start_time);
|
||||
$gameJamEndTime = strtotime($gameJam->end_time);
|
||||
$date = date('Y/m/d H:i:s', time());
|
||||
$gameJamStartTime = strtotime($gameJam->start_time);
|
||||
$gameJamEndTime = strtotime($gameJam->end_time);
|
||||
$date = date('Y/m/d H:i:s', time());
|
||||
|
||||
$currentTime = strtotime($date);
|
||||
$currentTime = strtotime($date);
|
||||
|
||||
if($gameJamStartTime <= $currentTime && $gameJamEndTime >= $currentTime){
|
||||
if(!isset($group->game_data_id)){
|
||||
if(isset($_POST['submitUpload'])){
|
||||
if ($gameJamStartTime <= $currentTime && $gameJamEndTime >= $currentTime) {
|
||||
if (!isset($registration->game_data_id)) {
|
||||
//Get the data from the user form
|
||||
$gameFile = $_FILES['gameFile'];
|
||||
$desc = $_POST['description'];
|
||||
$title = $_POST['gameTitle'];
|
||||
$thumbnail = $_FILES['thumbnailFile'];
|
||||
$isWebBased = isset( $_POST['isWebBased']);
|
||||
$isWebBased = isset($_POST['isWebBased']);
|
||||
|
||||
$gameFileName = $_FILES['gameFile']['name'];//Game name
|
||||
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
|
||||
@@ -39,40 +52,40 @@ if(isLogin()){
|
||||
|
||||
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
||||
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
||||
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
|
||||
$thumbnailFileError = $_FILES['thumbnailFile']['error'];//File error
|
||||
|
||||
if($gameFileError === 0){
|
||||
if ($gameFileError === 0) {
|
||||
$gameData = new GameData();
|
||||
$gameData->game_name = $title;
|
||||
$gameData->game_link = ZipFileHandler($gameFileName,$gameFileTmp);
|
||||
$gameData->game_link = ZipFileHandler($gameFileName, $gameFileTmp);
|
||||
$gameData->description = $desc;
|
||||
if(isset($thumbnail) && $thumbnailFileError === 0){
|
||||
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
|
||||
if (isset($thumbnail) && $thumbnailFileError === 0) {
|
||||
$gameData->img = imagesFileHandler($thumbnailFileName, $thumbnailFileTmp);
|
||||
}
|
||||
$gameData->is_web_Based = $isWebBased;
|
||||
$gameData->save();
|
||||
$group->gameData()->associate($gameData);
|
||||
if(! $group->save()){
|
||||
http_response_code(500);
|
||||
}else{
|
||||
http_response_code(201);
|
||||
}
|
||||
$registration->gameData()->associate($gameData);
|
||||
if (!$registration->save()) {
|
||||
http_response_code(500);
|
||||
} else {
|
||||
http_response_code(201);
|
||||
}
|
||||
|
||||
}else{
|
||||
http_response_code(500);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "file already uploaded "]);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Can only upload one file"]);
|
||||
echo json_encode(["message" => "Can only upload when the game jam has started"]);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Can only upload when the game jam has started"]);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not login"]);
|
||||
}
|
||||
Reference in New Issue
Block a user