commit | author | age
|
c077c7
|
1 |
<?php |
JK |
2 |
function createVehiclesList($trips, $mapping, $saveConfig = FALSE) { |
|
3 |
$lines = []; |
|
4 |
foreach($trips as $trip) { |
|
5 |
$lines[$trip['line']][] = [ |
|
6 |
'trip' => $trip, |
|
7 |
'vehicle' => $mapping[$trip['id']] ?? [], |
|
8 |
]; |
|
9 |
} |
|
10 |
foreach($lines as &$line) { |
|
11 |
usort($line, function($a, $b) { |
|
12 |
return (substr($a['vehicle']['num'] ?? '', 2) <=> substr($b['vehicle']['num'] ?? '', 2)); |
|
13 |
}); |
|
14 |
} |
|
15 |
unset($line); |
|
16 |
ksort($lines); |
|
17 |
|
|
18 |
if($saveConfig) { |
|
19 |
$twigLoader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../templates'); |
|
20 |
$twig = new \Twig\Environment($twigLoader); |
|
21 |
|
|
22 |
$vehiclesHtml = $twig->render('vehicles.html', [ |
|
23 |
'lines' => $lines, |
|
24 |
'prefix' => $saveConfig['prefix'], |
|
25 |
]); |
|
26 |
if(!file_put_contents($saveConfig['result_vehicles_temp'], $vehiclesHtml)) { |
|
27 |
throw new Exception('Vehicles save failed'); |
|
28 |
} |
|
29 |
rename($saveConfig['result_vehicles_temp'], $saveConfig['result_vehicles']); |
|
30 |
} |
|
31 |
|
|
32 |
return $lines; |
|
33 |
} |