mobmash.click/html/index.php

59 lines
1.5 KiB
PHP
Raw Normal View History

2024-07-27 22:03:17 +00:00
<?php
require_once __DIR__ . "/../core.php";
2024-07-30 21:14:08 +00:00
require_once __DIR__ . "/../lib/pairing.php";
2024-08-01 18:50:08 +00:00
require_once __DIR__ . "/../lib/rating.php";
2024-07-27 22:03:17 +00:00
2024-08-01 18:50:08 +00:00
function renderChoice(): void {
[$left, $right] = [$_SESSION["left"], $_SESSION["right"]];
$title = "Test";
$content = function() use ($left, $right) {
include __DIR__ . "/../view/fragments/mobSelection.php";
};
include __DIR__ . "/../view/layout.php";
}
function reload(): void {
header("LOCATION: /");
http_send_status(303);
}
function newPairing(): array {
return makeInitialPairing(session_id());
}
2024-07-27 22:03:17 +00:00
2024-08-01 18:50:08 +00:00
const LEFT = 0;
const RIGHT = 1;
2024-07-27 22:03:17 +00:00
2024-08-01 18:50:08 +00:00
function voteAndNextPairing(int $winner): array {
addMatch($_SESSION["left"]["id"], $_SESSION["right"]["id"], $winner, session_id());
$winnerMob = ($winner == 0) ? $_SESSION["left"] : $_SESSION["right"];
[$left, $right] = makeFollowUpPairing(session_id(), $winnerMob["id"]);
if (($winner == LEFT && $left["id"] != $winnerMob["id"]) ||
($winner == RIGHT && $right["id"] != $winnerMob["id"])
) {
[$left, $right] = [$right, $left];
}
return [$left, $right];
}
session_start();
2024-07-27 22:03:17 +00:00
2024-08-01 18:50:08 +00:00
[$_SESSION["left"], $_SESSION["right"], $render] = match (true) {
isset($_GET["new"]), !isset($_SESSION["left"]) => [...newPairing(), false],
isset($_GET["left"]) => [...voteAndNextPairing(LEFT), false],
isset($_GET["right"]) => [...voteAndNextPairing(RIGHT), false],
default => [$_SESSION["left"], $_SESSION["right"], true],
2024-07-27 22:03:17 +00:00
};
2024-08-01 18:50:08 +00:00
if ($render) {
renderChoice();
} else {
reload();
}