summaryrefslogtreecommitdiff
path: root/pages/api/evening.php
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-06-23 12:49:45 +0200
committerRaindropsSys <contact@minteck.org>2023-06-23 12:49:45 +0200
commit68efbff6a981bf5c3081ee4574e14b64a731ff47 (patch)
tree59a95cd1eae3062c40565cc69adda0ae55843e38 /pages/api/evening.php
parent23563c7188e089929b60f9e10721c6fc43a220ff (diff)
downloadpluralconnect-68efbff6a981bf5c3081ee4574e14b64a731ff47.tar.gz
pluralconnect-68efbff6a981bf5c3081ee4574e14b64a731ff47.tar.bz2
pluralconnect-68efbff6a981bf5c3081ee4574e14b64a731ff47.zip
Updated 2 files (automated)
Diffstat (limited to 'pages/api/evening.php')
-rw-r--r--pages/api/evening.php37
1 files changed, 27 insertions, 10 deletions
diff --git a/pages/api/evening.php b/pages/api/evening.php
index 9884e05..4d420ab 100644
--- a/pages/api/evening.php
+++ b/pages/api/evening.php
@@ -9,6 +9,7 @@ if (!$isLoggedIn || $isLowerLoggedIn) {
$pairs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/pairs.json"), true);
$ignored = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json"), true);
+$locked = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/locked.json"), true);
$data = [];
$members = $members = [
@@ -94,23 +95,23 @@ usort($pairs, function ($a, $b) use ($members) {
$times = [];
foreach ($a[0] as $id) {
- $times[] = getLastFronted($members, $id);
+ if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id);
}
foreach ($a[1] as $id) {
- $times[] = getLastFronted($members, $id);
+ if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id);
}
- $timeA = time() - min(...$times);
+ $timeA = time() - min($times);
$times = [];
foreach ($b[0] as $id) {
- $times[] = getLastFronted($members, $id);
+ if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id);
}
foreach ($b[1] as $id) {
- $times[] = getLastFronted($members, $id);
+ if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id);
}
- $timeB = time() - min(...$times);
+ $timeB = time() - min($times);
return $timeB - $timeA;
}); $pairs = array_values($pairs); foreach ($pairs as $pair): $times = [];
@@ -118,21 +119,37 @@ usort($pairs, function ($a, $b) use ($members) {
foreach ($pair[1] as $id): $times[] = getLastFronted($members, $id); endforeach;
endforeach;
-$listI = 0; for ($i = 0; $i < 2; $i++): $pair = $pairs[$listI];
+$listI = 0; for ($i = 0; $i < 7; $i++): $pair = $pairs[$listI];
+ $realPair = $pair;
+
+ if (isset($locked[date('Y-m-d', time() + 86400 * $i)])) {
+ $pair = array_map(function ($i) {
+ return explode(",", $i);
+ }, explode("|", $locked[date('Y-m-d', time() + 86400 * $i)]));
+ }
+
$data[$i] = [];
if (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) {
$data[$i][0] = [];
$data[$i][1] = [];
foreach ($pair[0] as $id):
- $data[$i][0][] = getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"];
+ $data[$i][0][] = (getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"]) . (isset($locked[date('Y-m-d', time() + 86400 * $i)]) ? "*" : "");
endforeach;
foreach ($pair[1] as $id):
- $data[$i][1][] = getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"];
+ $data[$i][1][] = (getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"]) . (isset($locked[date('Y-m-d', time() + 86400 * $i)]) ? "*" : "");
endforeach;
} else {
$data[$i] = null;
}
-if (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) $listI++; if ($listI === count($pairs)) $listI = 0; endfor;
+
+ if (
+ (!isset($locked[date('Y-m-d', time() + 86400 * $i)]) && !in_array(date('Y-m-d', time() + 86400 * $i), $ignored))
+ || (isset($locked[date('Y-m-d', time() + 86400 * $i)]) && $locked[date('Y-m-d', time() + 86400 * $i)] === implode(",", $realPair[0]) . "|" . implode(",", $realPair[1]))
+ ) {
+ $listI++;
+ }
+
+ if ($listI === count($pairs)) $listI = 0; endfor;
header("Content-Type: application/json");
die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file