summaryrefslogtreecommitdiff
path: root/includes/travelling.inc
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
committerMinteck <contact@minteck.org>2022-10-10 20:51:39 +0200
commit108525534c28013cfe1897c30e4565f9893f3766 (patch)
treedd3e5132971f96ab5f05e7f3f8f6dbbf379a19bd /includes/travelling.inc
parent2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab (diff)
downloadpluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.gz
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.bz2
pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.zip
Update
Diffstat (limited to 'includes/travelling.inc')
-rw-r--r--includes/travelling.inc47
1 files changed, 47 insertions, 0 deletions
diff --git a/includes/travelling.inc b/includes/travelling.inc
new file mode 100644
index 0000000..edcb267
--- /dev/null
+++ b/includes/travelling.inc
@@ -0,0 +1,47 @@
+<?php
+
+$travelling = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling/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_cloudburst), ...array_map(function ($i) {
+ $i["_system"] = "gdapd";
+ return $i;
+}, $json_raindrops)];
+
+foreach ($members as $member) {
+ if (!isset($travelling[$member["id"]])) {
+ $travelling[$member["id"]] = [
+ "travelling" => false,
+ "history" => []
+ ];
+ }
+}
+
+function withTravelers(array $members, string $system): array {
+ global $travelling;
+
+ return [
+ ...array_map(function ($i) use ($system) {
+ $i['system'] = $system;
+ return $i;
+ }, array_filter($members, function ($i) use ($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 isset($travelling[$i['id']]) && $travelling[$i['id']]['travelling'];
+ })
+ ];
+}
+
+@file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling/travelling.json", utf8_encode(json_encode($travelling, JSON_PRETTY_PRINT))); \ No newline at end of file