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

32 lines
1.2 KiB
PHP

<?php
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use \Backend\Models\KeyWord;
use \Backend\Models\GameJam;
use Backend\Models\Registration;
if (!isAdmin()) {
if (isset($_GET['genKeyWord'])) {
$gameJamId = $_GET['gameJamId'];
$game_jam = GameJam::find($gameJamId);
$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();
$game_jam->key_word = $find_all_keywords->first()->key_word;
if (!$game_jam->save()) {
http_response_code(500);
} else {
http_response_code(201);
}
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json;charset=UTF-8');
echo json_encode(array('data' => $find_all_keywords->jsonSerialize()));
} else {
http_response_code(400);
}
} else {
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
}