diff options
Diffstat (limited to 'includes/travelling.php')
-rw-r--r-- | includes/travelling.php | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/includes/travelling.php b/includes/travelling.php index bb24172..b74c826 100644 --- a/includes/travelling.php +++ b/includes/travelling.php @@ -1,13 +1,20 @@ <?php $travelling = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling.json"), true); + +$json_cloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc-members.json"), true); +$json_raindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd-members.json"), true); + +if (!isset($json_cloudburst)) $json_cloudburst = []; +if (!isset($json_raindrops)) $json_raindrops = []; + $members = [...array_map(function ($i) { $i["_system"] = "ynmuc"; return $i; -}, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc-members.json"), true)), ...array_map(function ($i) { +}, $json_cloudburst), ...array_map(function ($i) { $i["_system"] = "gdapd"; return $i; -}, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd-members.json"), true))]; +}, $json_raindrops)]; foreach ($members as $member) { if (!isset($travelling[$member["id"]])) { @@ -26,15 +33,15 @@ function withTravelers(array $members, string $system): array { $i['system'] = $system; return $i; }, array_filter($members, function ($i) use ($travelling) { - return !$travelling[$i['id']]['travelling']; + return !(isset($travelling[$i['id']]) && $travelling[$i['id']]['travelling']); })), ...array_filter(array_map(function ($i) use ($system) { $i['system'] = $system === "gdapd" ? "ynmuc" : "gdapd"; return $i; }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($system === "gdapd" ? "ynmuc" : "gdapd") . "-members.json"), true)), function ($i) use ($travelling) { - return $travelling[$i['id']]['travelling']; + return isset($travelling[$i['id']]) && $travelling[$i['id']]['travelling']; }) ]; } -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling.json", json_encode($travelling, JSON_PRETTY_PRINT));
\ No newline at end of file +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling.json", utf8_encode(json_encode($travelling, JSON_PRETTY_PRINT)));
\ No newline at end of file |