2021-03-11 12:21:16 +00:00
|
|
|
<?php
|
|
|
|
require_once "../../../bootstrap.php";
|
|
|
|
require_once "../Admin/Admin.php";
|
|
|
|
use Backend\Models\Group;
|
|
|
|
use Backend\Models\Vote;
|
2021-03-12 13:05:31 +00:00
|
|
|
use \Illuminate\Support\Collection;
|
2021-03-11 12:21:16 +00:00
|
|
|
|
|
|
|
if(isAdmin() && isset($_GET['gameJamId'])){
|
|
|
|
$groups = Group::where('game_jam_id',$_GET['gameJamId'])->get();
|
2021-03-12 13:05:31 +00:00
|
|
|
$winningGroups = new Collection();
|
2021-03-11 12:21:16 +00:00
|
|
|
$i = -1;
|
|
|
|
foreach ($groups as $group){
|
|
|
|
$x = Vote::where('group_id', $group->id)->count();
|
|
|
|
if($x>$i){
|
2021-03-12 13:05:31 +00:00
|
|
|
$winningGroups = new Collection();
|
|
|
|
$winningGroups->push($group);
|
|
|
|
|
2021-03-11 12:21:16 +00:00
|
|
|
$i = $x;
|
|
|
|
}
|
|
|
|
elseif ($i === $x){
|
2021-03-12 13:05:31 +00:00
|
|
|
$winningGroups->push($group);
|
2021-03-11 12:21:16 +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:21:16 +00:00
|
|
|
header('Content-Type: application/json;charset=UTF-8');
|
2021-03-12 13:05:31 +00:00
|
|
|
echo $winningGroups->toJson(JSON_PRETTY_PRINT);
|
|
|
|
|
|
|
|
|
2021-03-19 12:25:27 +00:00
|
|
|
}else{
|
|
|
|
http_response_code(401);
|
2021-03-11 12:21:16 +00:00
|
|
|
}
|
|
|
|
|