-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_races_for_menu.php
80 lines (47 loc) · 1.81 KB
/
get_races_for_menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
header('Cache-Control: no-cashe');
header('Pragma: no-cache');
header('Content-Type: application/json');
$path = 'data/races.json';
$file = file_get_contents($path);
$races_file = json_decode($file, true);
unset($file);
$out_array = array();
$racer_from_file = array();
$road = 0;
$old_roads = array();
$values_from_file = array_values($races_file);
foreach($races_file as $racer_from_file){
foreach($old_roads as $num => $num_road){
if ((int) $racer_from_file['road'] == $num_road){
break;
$road = false;
}
if (($num + 1) == count($old_roads)){
$road = $racer_from_file['road'];
}
}
if ($road !== false){
$racer_from_file_cycle = array();
$min = false;
foreach($values_from_file as $count => $racer_from_file_cycle){
if ((int) $racer_from_file_cycle ['road'] == $road ) {
$time_cycle = (int) $values_from_file [$min] ['time'];
if ($min === false){
$min = $count;
}
if ((int) $racer_from_file_cycle['time'] <= $time_cycle){
$min = $count;
}
}
}
$out_array []= array('name' => $values_from_file [$min] ['name'],
'human_time' => $values_from_file [$min] ['human_time'],
'road' => $values_from_file [$min] ['road']);
$old_roads []= $road;
$road = false;
}
}
$out_json = json_encode($out_array);
echo $out_json;
?>