diff --git a/html/index.php b/html/index.php index 6c5033d..2fe4998 100644 --- a/html/index.php +++ b/html/index.php @@ -1,15 +1,14 @@ query("SELECT * FROM mm_mobs WHERE enabled = true"); + $result = $result->fetchAll(PDO::FETCH_ASSOC); + return $result[array_rand($result)]; +} + +function findPair(string $session, int $current): array|false { + global $pdo; + + error_log($current); + + // language=sql + $query = $pdo->prepare(<<execute([$session, $current]); + $result = $query->fetch(PDO::FETCH_ASSOC); + + if ($result === false) { + return false; + } else { + return [ + [ + "id" => $result["mob"], + "name" => $result["mob_name"], + "image" => $result["mob_image"], + "rating" => $result["mob_rating"], + ], + [ + "id" => $result["opponent"], + "name" => $result["opponent_name"], + "image" => $result["opponent_image"], + "rating" => $result["opponent_rating"], + ] + ]; + } +} + +function makeInitialPairing(string $session): array { + $current = getRandomMob()["id"]; + return findPair($session, $current); +} + +function makeFollowUpPairing(string $session, int $winner): array { + return findPair($session, $winner); +} \ No newline at end of file diff --git a/lib/rating.php b/lib/rating.php index d92fdf8..5eb50dd 100644 --- a/lib/rating.php +++ b/lib/rating.php @@ -2,13 +2,6 @@ require_once __DIR__ . "/database.php"; -function getRandomMob(): array { - global $pdo; - $result = $pdo->query("SELECT * FROM mm_mobs WHERE enabled = true"); - $result = $result->fetchAll(PDO::FETCH_ASSOC); - return $result[array_rand($result)]; -} - function getEloForMob(int $mob): int { global $pdo; $query = $pdo->prepare("SELECT * FROM mm_current_rating WHERE mob = ?");