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
2022-04-04 16:08:39 +00:00

45 lines
874 B
PHP

<?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;
$teamMapper = new TeamMapper($app->database->conn);
$timeMapper = new TimeMapper($app->database->conn);
$prev_hash = (int)filter_input(INPUT_GET, 'h');
$data = [];
$times = $timeMapper->getAll();
foreach ($times as $time)
{
$team = $teamMapper->get($time->teamId);
if (!$team)
{
return;
}
$row = [
"name" => $team->name,
"date" => $time->date
];
array_push($data, $row);
}
$hash = crc32(serialize($data));
if ($prev_hash !== $hash)
{
$app->api([
"hash" => $hash,
"data" => $data
]);
}
// return nothing
http_response_code(204);