66 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php $app = require '../../../app/inc.php';
 | 
						|
/**
 | 
						|
 * Magique
 | 
						|
 */
 | 
						|
 | 
						|
use App\Teamtable\TeamMapper;
 | 
						|
use App\Timetable\TimeMapper;
 | 
						|
 | 
						|
$team_mapper = new TeamMapper($app->database->conn);
 | 
						|
$time_mapper = new TimeMapper($app->database->conn);
 | 
						|
 | 
						|
$prev_hash = filter_input(INPUT_GET, 'h');
 | 
						|
 | 
						|
$teams    = [];
 | 
						|
$team_map = [];
 | 
						|
$laps     = [];
 | 
						|
$time_ref = NULL;
 | 
						|
 | 
						|
foreach ($time_mapper->getAll() as $time)
 | 
						|
{
 | 
						|
    if (!isset($teams[$time->team_id]))
 | 
						|
    {
 | 
						|
        $teams[$time->team_id] = $team_mapper->get($time->team_id);
 | 
						|
    }
 | 
						|
    $team = $teams[$time->team_id];
 | 
						|
 | 
						|
    if (!isset($team_map[$team->id]))
 | 
						|
    {
 | 
						|
        $team_map[$team->id] = [
 | 
						|
            "name"    => htmlspecialchars($team->name),
 | 
						|
            "company" => htmlspecialchars($team->company),
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    if ($time_ref === NULL)
 | 
						|
    {
 | 
						|
        $time_ref = $time->date->getTimestamp();
 | 
						|
    }
 | 
						|
 | 
						|
    $row = [
 | 
						|
        "id"   => $team->id,
 | 
						|
        "time" => ($time->date->getTimestamp() - $time_ref)
 | 
						|
    ];
 | 
						|
 | 
						|
    array_push($laps, $row);
 | 
						|
}
 | 
						|
 | 
						|
$data = [
 | 
						|
    "map" => [
 | 
						|
        "team" => $team_map,
 | 
						|
        "time_reference" => $time_ref
 | 
						|
    ],
 | 
						|
    "laps" => $laps
 | 
						|
];
 | 
						|
 | 
						|
$hash = hash('crc32', serialize($data));
 | 
						|
 | 
						|
if ($prev_hash !== $hash)
 | 
						|
{
 | 
						|
    $app->api([
 | 
						|
            "hash" => $hash,
 | 
						|
            "data" => $data
 | 
						|
        ]);
 | 
						|
}
 | 
						|
 | 
						|
http_response_code(204); |