Game-Jaming/Backend/Controllers/Polls/GetWinner.php

33 lines
902 B
PHP

<?php
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use Backend\Models\Group;
use Backend\Models\Vote;
use \Illuminate\Support\Collection;
if(isAdmin() && isset($_GET['gameJamId'])){
$groups = Group::where('game_jam_id',$_GET['gameJamId'])->get();
$winningGroups = new Collection();
$i = -1;
foreach ($groups as $group){
$x = Vote::where('group_id', $group->id)->count();
if($x>$i){
$winningGroups = new Collection();
$winningGroups->push($group);
$i = $x;
}
elseif ($i === $x){
$winningGroups->push($group);
}
}
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 $winningGroups->toJson(JSON_PRETTY_PRINT);
}