function autoInput() { $pairings = array(); $standings = array(); for ($rnd = 0; $rnd < sizeof($_POST['pairings']); $rnd++) { $pairings[$rnd] = extractPairings($_POST['pairings'][$rnd]); if ($rnd == 0) { $standings[$rnd] = standFromPairs($_POST['pairings'][$rnd + 1]); } else { $testStr = chop($_POST['standings'][$rnd - 1]); if (strcmp($testStr, "") == 0) { $standings[$rnd] = standFromPairs($_POST['pairings'][$rnd + 1]); } else { $standings[$rnd] = extractStandings($_POST['standings'][$rnd - 1]); } } } $event = new Event($_POST['name']); $sid = $event->mainid; for ($rnd = 0; $rnd < sizeof($pairings); $rnd++) { for ($pair = 0; $pair < sizeof($pairings[$rnd]); $pair++) { $printrnd = $rnd + 1; $playerA = $pairings[$rnd][$pair][0]; $playerB = $pairings[$rnd][$pair][1]; $winner = "D"; if ($rnd == 0) { if (isset($standings[$rnd][$playerA]) && $standings[$rnd][$playerA] > 1) { $winner = "A"; } if (isset($standings[$rnd][$playerB]) && $standings[$rnd][$playerB] > 1) { $winner = "B"; } } else { if (isset($standings[$rnd][$playerA]) && isset($standings[$rnd - 1][$playerA]) && $standings[$rnd][$playerA] - $standings[$rnd - 1][$playerA] > 1) { $winner = "A"; } if (isset($standings[$rnd][$playerB]) && isset($standings[$rnd - 1][$playerB]) && $standings[$rnd][$playerB] - $standings[$rnd - 1][$playerB] > 1) { $winner = "B"; } } $objplayera = Player::findOrCreateByName($playerA); $objplayerb = Player::findOrCreateByName($playerB); $event->addPlayer($playerA); $event->addPlayer($playerB); $event->addMatch($playerA, $playerB, $rnd + 1, $winner); } } $finals = array(); for ($ndx = 0; $ndx < sizeof($_POST['finals']); $ndx++) { $finals[$ndx] = extractFinals($_POST['finals'][$ndx]); } $fid = $event->finalid; $win = ""; $sec = ""; $t4 = array(); $t8 = array(); for ($ndx = 0; $ndx < sizeof($finals); $ndx++) { for ($match = 0; $match < sizeof($finals[$ndx]); $match += 2) { $playerA = $finals[$ndx][$match]; $playerB = $finals[$ndx][$match + 1]; $event->addPlayer($playerA); $event->addPlayer($playerB); if ($ndx < sizeof($finals) - 1) { $winner = detwinner($playerA, $playerB, $finals[$ndx + 1]); } else { $winner = $_POST['champion']; } $res = "D"; if (strcmp($winner, $playerA) == 0) { $res = "A"; } if (strcmp($winner, $playerB) == 0) { $res = "B"; } $event->addMatch($playerA, $playerB, $ndx + 1 + $event->mainrounds, $res); $loser = strcmp($winner, $playerA) == 0 ? $playerB : $playerA; if ($ndx == sizeof($finals) - 1) { $win = $winner; $sec = $loser; } elseif ($ndx == sizeof($finals) - 2) { $t4[] = $loser; } elseif ($ndx == sizeof($finals) - 3) { $t8[] = $loser; } } } $event->setFinalists($win, $sec, $t4, $t8); }
function updateMedals() { $name = $_POST['name']; $event = new Event($_POST['name']); $winner = $_POST['newmatchplayer1']; $second = $_POST['newmatchplayer2']; $t4 = array($_POST['newmatchplayer3'], $_POST['newmatchplayer4']); $t8 = array($_POST['newmatchplayer5'], $_POST['newmatchplayer6'], $_POST['newmatchplayer7'], $_POST['newmatchplayer8']); $event->setFinalists($winner, $second, $t4, $t8); }