%PDF- %PDF-
Direktori : /www/varak.net/losik.varak.net/app/ |
Current File : //www/varak.net/losik.varak.net/app/match-detail.php |
<?php /** * Created by IntelliJ IDEA. * User: mvarak * Date: 10/10/2017 * Time: 3:09 PM */ function cmp($a, $b) { if($a->finalPercent == $b->finalPercent) return 0; return $a->finalPercent < $b->finalPercent ? 1 : -1; } $matchInfo = dibi::query("SELECT [guid], [name] FROM [matches] WHERE [id]=%i", $id)->fetch(); $stagenames = dibi::query("SELECT [name], [order] FROM [stages] WHERE [match]=%i ORDER BY [order]", $id); $minimums = array(); $result = dibi::query("SELECT [stageid], min([totaltime]) [ttime] FROM [display_results] WHERE [match]=%i GROUP BY [stageid]", $id); foreach ($result as $res) { $minimums[$res->stageid] = $res->ttime; } $stages = array(); $result = dibi::query("SELECT [shooterid], [shootername], [division], [totaltime], [stageid], [stageorder] FROM [display_results] WHERE [match] = %i ORDER BY [stageorder]", $id); foreach ($result as $res) { if (!isset($stages[$res->shooterid])) { $stages[$res->shooterid] = new stdClass(); $stages[$res->shooterid]->name = $res->shootername; $stages[$res->shooterid]->stages = array(); $stages[$res->shooterid]->total = 0; $stages[$res->shooterid]->division = $res->division; } $stages[$res->shooterid]->stages[$res->stageid] = sprintf("%0.2f", ($minimums[$res->stageid] / $res->totaltime) * 100); $stages[$res->shooterid]->total += ($minimums[$res->stageid] / $res->totaltime) * 100; } $max = 0; foreach ($stages as $user => $stage) { if($max < $stages[$user]->total) $max = $stages[$user]->total; } foreach ($stages as $user => $stage) $stages[$user]->finalPercent = sprintf("%0.2f", ($stages[$user]->total / $max) * 100); uasort($stages, 'cmp'); $smarty->assign('numStages', count($minimums)); $smarty->assign('results', $stages); $smarty->assign('stagenames', $stagenames); $smarty->assign('uuid', $matchInfo->guid); $smarty->assign('matchName', $matchInfo->name);