2022-04-26 21:20:32 +00:00
|
|
|
<?php $app = require '../../../app/inc.php';
|
2022-03-30 08:51:46 +00:00
|
|
|
/**
|
2022-05-08 20:00:11 +00:00
|
|
|
* Magique
|
2022-03-30 08:51:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
use App\Teamtable\TeamMapper;
|
|
|
|
use App\Timetable\TimeMapper;
|
|
|
|
|
2022-04-14 20:59:42 +00:00
|
|
|
$team_mapper = new TeamMapper($app->database->conn);
|
|
|
|
$time_mapper = new TimeMapper($app->database->conn);
|
2022-03-30 08:51:46 +00:00
|
|
|
|
2022-04-26 13:00:38 +00:00
|
|
|
$prev_hash = filter_input(INPUT_GET, 'h');
|
2022-03-30 08:51:46 +00:00
|
|
|
|
2022-04-26 13:00:38 +00:00
|
|
|
$teams = [];
|
2022-04-27 10:57:26 +00:00
|
|
|
$team_map = [];
|
2022-05-08 20:00:11 +00:00
|
|
|
$laps = [];
|
2022-04-26 13:00:38 +00:00
|
|
|
$time_ref = NULL;
|
2022-03-30 08:51:46 +00:00
|
|
|
|
2022-04-26 13:00:38 +00:00
|
|
|
foreach ($time_mapper->getAll() as $time)
|
2022-04-04 09:09:58 +00:00
|
|
|
{
|
2022-04-26 13:00:38 +00:00
|
|
|
if (!isset($teams[$time->team_id]))
|
|
|
|
{
|
|
|
|
$teams[$time->team_id] = $team_mapper->get($time->team_id);
|
|
|
|
}
|
|
|
|
$team = $teams[$time->team_id];
|
|
|
|
|
2022-04-27 10:57:26 +00:00
|
|
|
if (!isset($team_map[$team->id]))
|
2022-04-26 13:00:38 +00:00
|
|
|
{
|
2022-04-27 10:57:26 +00:00
|
|
|
$team_map[$team->id] = [
|
|
|
|
"name" => htmlspecialchars($team->name),
|
|
|
|
"company" => htmlspecialchars($team->company),
|
|
|
|
];
|
2022-04-26 13:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($time_ref === NULL)
|
|
|
|
{
|
|
|
|
$time_ref = $time->date->getTimestamp();
|
|
|
|
}
|
2022-04-04 09:09:58 +00:00
|
|
|
|
|
|
|
$row = [
|
2022-04-26 13:00:38 +00:00
|
|
|
"id" => $team->id,
|
|
|
|
"time" => ($time->date->getTimestamp() - $time_ref)
|
2022-04-04 09:09:58 +00:00
|
|
|
];
|
|
|
|
|
2022-05-08 20:00:11 +00:00
|
|
|
array_push($laps, $row);
|
2022-04-04 09:09:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 13:00:38 +00:00
|
|
|
$data = [
|
|
|
|
"map" => [
|
2022-04-27 10:57:26 +00:00
|
|
|
"team" => $team_map,
|
2022-04-26 13:00:38 +00:00
|
|
|
"time_reference" => $time_ref
|
|
|
|
],
|
2022-05-08 20:00:11 +00:00
|
|
|
"laps" => $laps
|
2022-04-26 13:00:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$hash = 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
|
|
|
]);
|
|
|
|
}
|
2022-05-08 20:00:11 +00:00
|
|
|
|
2022-03-30 08:51:46 +00:00
|
|
|
http_response_code(204);
|