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

30 lines
768 B
PHP
Raw Normal View History

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
}
}
header('Content-Type: application/json;charset=UTF-8');
2021-03-12 13:05:31 +00:00
echo $winningGroups->toJson(JSON_PRETTY_PRINT);
2021-03-11 12:21:16 +00:00
}