43 lines
960 B
PHP
43 lines
960 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
|
|
*
|
|
* This page compiles a set of data and sends it if the provided hash of
|
|
* the data is not equal.
|
|
*/
|
|
|
|
use App\Teamtable\TeamMapper;
|
|
use App\Timetable\TimeMapper;
|
|
|
|
$team_mapper = new TeamMapper($app->database->conn);
|
|
$time_mapper = new TimeMapper($app->database->conn);
|
|
|
|
$prev_hash = (int)filter_input(INPUT_GET, 'h');
|
|
|
|
$data = [];
|
|
$times = $time_mapper->getAll();
|
|
|
|
foreach ($times as $time)
|
|
{
|
|
$team = $team_mapper->get($time->team_id);
|
|
|
|
$row = [
|
|
"name" => $team->name,
|
|
"date" => $time->date->getTimestamp()
|
|
];
|
|
|
|
array_push($data, $row);
|
|
}
|
|
|
|
$hash = crc32(serialize($data));
|
|
|
|
if ($prev_hash !== $hash)
|
|
{
|
|
$app->api([
|
|
"hash" => $hash,
|
|
"data" => $data
|
|
]);
|
|
}
|
|
// return nothing
|
|
http_response_code(204); |