-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
56 lines (52 loc) · 1.96 KB
/
api.php
File metadata and controls
56 lines (52 loc) · 1.96 KB
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
<?php
$dataSource = __DIR__ . '/data/morkstates.json';
$result=array();
header('Content-Type: application/json');
if (file_exists($dataSource)) {
$statesData = file_get_contents($dataSource);
$morkStates = json_decode($statesData, true);
if (!empty($morkStates) and is_array($morkStates)) {
//load the last update time
$lastUpdateTime = @file_get_contents(__DIR__ . '/data/lastupdate.dat');
$result['info'] = array();
$result['info'] = array(
'version' => 1,
'last_update' => $lastUpdateTime,
);
$result['states'] = array();
foreach ($morkStates as $state) {
$stateDistricts=array();
$stateCommunities=array();
if (isset($state['districts']) and is_array($state['districts'])) {
foreach ($state['districts'] as $district) {
$stateDistricts[] = array(
'name' => $district['name'],
'alert' => $district['alert'],
'changed' => $district['changed'],
);
}
}
if (isset($state['community']) and is_array($state['community'])) {
foreach ($state['community'] as $community) {
$stateCommunities[] = array(
'name' => $community['name'],
'alert' => $community['alert'],
'changed' => $community['changed'],
);
}
}
$result['states'][$state['id']] = array(
'name' => $state['name'],
'alert' => $state['alert'],
'changed' => $state['changed'],
'districts' => $stateDistricts,
'community' => $stateCommunities,
);
}
print(json_encode($result));
} else {
print(json_encode($result));
}
} else {
print(json_encode($result));
}