This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/public/race/sync.php

46 lines
913 B
PHP
Raw Normal View History

2022-03-30 08:51:46 +00:00
<?php $app = require '../../app/inc.php';
/**
* We originally wanted to use SSE for this, but the hosting provider
* did not support that so we resorted to simple polling instead
*/
use App\Teamtable\TeamMapper;
use App\Timetable\TimeMapper;
2022-04-04 09:09:58 +00:00
$teamMapper = new TeamMapper($app->database->conn);
2022-03-30 08:51:46 +00:00
$timeMapper = new TimeMapper($app->database->conn);
2022-03-30 12:11:39 +00:00
$prev_hash = (int)filter_input(INPUT_GET, 'h');
2022-03-30 08:51:46 +00:00
2022-04-04 09:09:58 +00:00
$data = [];
2022-03-30 08:51:46 +00:00
$times = $timeMapper->getAll();
2022-04-04 09:09:58 +00:00
foreach ($times as $time)
{
$team = $teamMapper->get($time->teamId);
if (!$team)
{
return;
}
$row = [
"name" => $team->name,
"rounds" => $team->rounds,
"bestTime" => $team->bestTime
];
array_push($data, $row);
}
$hash = crc32(serialize($data));
2022-03-30 08:51:46 +00:00
if ($prev_hash !== $hash)
{
$app->api([
"hash" => $hash,
2022-04-04 09:09:58 +00:00
"data" => $data
2022-03-30 08:51:46 +00:00
]);
}
// return nothing
http_response_code(204);