Game-Jaming/Backend/Controllers/keyWord/GetKeyWinner.php

32 lines
1.2 KiB
PHP
Raw Normal View History

2021-03-10 13:16:08 +00:00
<?php
2021-03-11 12:20:10 +00:00
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use \Backend\Models\KeyWord;
use \Backend\Models\GameJam;
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 (!isAdmin()) {
if (isset($_GET['genKeyWord'])) {
2021-03-19 08:18:19 +00:00
$gameJamId = $_GET['gameJamId'];
2021-03-11 12:20:10 +00:00
$game_jam = GameJam::find($gameJamId);
2021-04-19 07:15:15 +00:00
$all_registration_in_game_jam_id = Registration::where("game_jam_id", $game_jam->id)->pluck("id")->toArray();
$find_all_keywords = KeyWord::whereIn("group_id", $all_registration_in_game_jam_id)->inRandomOrder()->take(6)->get();
2021-03-11 12:20:10 +00:00
$game_jam->key_word = $find_all_keywords->first()->key_word;
2021-04-19 07:15:15 +00:00
if (!$game_jam->save()) {
2021-03-19 12:25:27 +00:00
http_response_code(500);
2021-04-19 07:15:15 +00:00
} else {
2021-03-19 12:25:27 +00:00
http_response_code(201);
}
2021-03-11 12:20:10 +00:00
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' => $find_all_keywords->jsonSerialize()));
2021-04-19 07:15:15 +00:00
} else {
2021-03-23 12:39:44 +00:00
http_response_code(400);
2021-03-11 12:20:10 +00:00
}
2021-04-19 07:15:15 +00:00
} else {
2021-03-23 12:39:44 +00:00
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
2021-03-11 12:20:10 +00:00
}