diff options
Diffstat (limited to 'includes/fragments/evening.inc')
-rw-r--r-- | includes/fragments/evening.inc | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/includes/fragments/evening.inc b/includes/fragments/evening.inc new file mode 100644 index 0000000..851b69f --- /dev/null +++ b/includes/fragments/evening.inc @@ -0,0 +1,245 @@ +<?php + +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json", "{}"); +$cache = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"), true); + +if (!isset($cache["content"]) || date('Y-m-d') !== $cache["day"]) { + ob_start(); + + $members = $members = [ + ...array_map(function ($i) { + $system = "ynmuc"; + $i["_lastFronted"] = -1; + $id = $i["id"]; + $memberData = $i; + + $fronters = array_map(function ($item) { + return $item["id"]; + }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]); + + if (in_array($id, $fronters)) { + $i["_lastFronted"] = time(); + } else { + $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true); + + $thisMember = array_filter($switches, function ($item) use ($memberData) { + return in_array($memberData["id"], $item["members"]); + }); + + $thisMember = array_values($thisMember); + $frontingEnd = null; + + if (count($thisMember) > 0) { + $thisIndex = array_search($thisMember[0], $switches); + + $frontingStart = $thisMember[0]; + $frontingEnd = $switches[$thisIndex - 1]; + } + + if ($frontingEnd !== null && isset($frontingStart)) { + $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]); + } + } + + return $i; + }, array_values(array_filter(scoreOrderGlobal(), function ($i) { + return $i["_system"] === "ynmuc"; + }))), + ...array_map(function ($i) { + $system = "gdapd"; + $i["_lastFronted"] = -1; + $id = $i["id"]; + $memberData = $i; + + $fronters = array_map(function ($item) { + return $item["id"]; + }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]); + + if (in_array($id, $fronters)) { + $i["_lastFronted"] = time(); + } else { + $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true); + + $thisMember = array_filter($switches, function ($item) use ($memberData) { + return in_array($memberData["id"], $item["members"]); + }); + + $thisMember = array_values($thisMember); + $frontingEnd = null; + + if (count($thisMember) > 0) { + $thisIndex = array_search($thisMember[0], $switches); + + $frontingStart = $thisMember[0]; + $frontingEnd = $switches[$thisIndex - 1]; + } + + if ($frontingEnd !== null && isset($frontingStart)) { + $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]); + } + } + + return $i; + }, array_values(array_filter(scoreOrderGlobal(), function ($i) { + return $i["_system"] === "gdapd"; + }))) + ]; global $pages; global $lang; global $use2023UI; global $ignored; ?> + +<style> + @media (max-width: 767px) { + .member-name, .member-list-separator { + display: none; + } + + .member-collection { + width: 100%; + text-align: center; + } + } + + .member-link:hover { + opacity: .75; + } +</style> + +<div class="container"> + <div> + <?php global $use2023UI; if ($use2023UI): ?> + <h4>Evening schedule</h4> + <?php else: ?> + <h2>Evening schedule</h2> + <?php endif; ?> + + <?php if (time() < 1686787200): ?> + <div class="alert alert-warning"> + <b>The evening schedule will replace the fronting schedule starting June 15<sup>th</sup>.</b> The fronting schedule page contains more information and shows the schedule up to that date. The evening schedule is experimental until then. + </div> + <?php endif; ?> + + <details> + <summary style="list-style: none; outline: none; cursor: text;"> + <p>Click on the "Ignore" button to mark an evening as ignored and shift the schedule one day after. You can revert this by clicking on "Unignore".</p> + </summary> + <ul> + <?php usort($pairs, function ($a, $b) use ($members) { + $times = []; + + foreach ($a[0] as $id) { + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); + } + foreach ($a[1] as $id) { + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); + } + + $timeA = time() - min($times); + $times = []; + + foreach ($b[0] as $id) { + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); + } + foreach ($b[1] as $id) { + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); + } + + $timeB = time() - min($times); + + return $timeB - $timeA; + }); $pairs = array_values($pairs); foreach ($pairs as $pair): $times = []; ?> + <li> + <?php foreach ($pair[0] as $id): ?> + <img style="width: 24px;" src="<?= getAsset("ynmuc", $id) ?>"> <?= getMemberWithoutSystem($id)["display_name"] ?> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + with + <?php foreach ($pair[1] as $id): ?> + <img style="width: 24px;" src="<?= getAsset("gdapd", $id) ?>"> <?= getMemberWithoutSystem($id)["display_name"] ?> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + (<?= time() - max($times) ?>) + </li> + <?php endforeach; ?> + </ul> + </details> + + <?php $listI = 0; for ($i = 0; $i < 15; $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)])); + } + + if (time() + 86400 * $i >= 1686787200): ?> + <?php global $use2023UI; if ($use2023UI): ?> + <h6><?= date('l j', time() + 86400 * $i) ?></h6> + <?php else: ?> + <h4><?= date('l j', time() + 86400 * $i) ?></h4> + <?php endif; ?> + <div style="display: grid; grid-template-columns: repeat(2, 1fr) 100px 150px; grid-gap: 20px; margin-bottom: 10px;"> + <div style="display: flex; align-items: center;<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>opacity: .75; filter: saturate(0);<?php endif; ?>"> + <div class="member-collection"> + <?php foreach ($pair[0] as $id): ?> + <a class="member-link <?php if (isset($locked[date('Y-m-d', time() + 86400 * $i)])): ?>text-warning" style="font-weight: bold;<?php endif; ?>" href="/<?= getMemberWithoutSystem($id)["name"] ?>"><img style="width: 24px;" src="<?= getAsset("ynmuc", $id, "heads") ?>"> <span class="member-name" style="<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>text-decoration: line-through;<?php endif; ?>"><?= getMemberWithoutSystem($id)["display_name"] ?></span></a><br class="member-list-separator"> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + </div> + </div> + <div style="display: flex; align-items: center;<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>opacity: .75; filter: saturate(0);<?php endif; ?>"> + <div class="member-collection"> + <?php foreach ($pair[1] as $id): ?> + <a class="member-link <?php if (isset($locked[date('Y-m-d', time() + 86400 * $i)])): ?>text-warning" style="font-weight: bold;<?php endif; ?>" href="/<?= getMemberWithoutSystem($id)["name"] ?>"><img style="width: 24px;" src="<?= getAsset("gdapd", $id, "heads") ?>"> <span class="member-name" style="<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>text-decoration: line-through;<?php endif; ?>"><?= getMemberWithoutSystem($id)["display_name"] ?></span></a><br class="member-list-separator"> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + </div> + </div> + <div style="display: flex; align-items: center; justify-content: center;"> + <?php + + $times = []; + + foreach ($pair[0] as $id) { + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); + } + foreach ($pair[1] as $id) { + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); + } + + $time = time() - min($times); + echo(timeAgo(time() - $time)); + + ?> + </div> + <div style="display: flex; align-items: center; justify-content: center;"> + <?php if (isset($locked[date('Y-m-d', time() + 86400 * $i)])): ?> + <a href="?lock&day=<?= date('Y-m-d', time() + 86400 * $i) ?>&data=<?= implode(",", $pair[0]) . "|" . implode(",", $pair[1]) ?>" class="btn btn-outline-secondary">Unlock</a> + <?php else: ?> + <a href="?lock&day=<?= date('Y-m-d', time() + 86400 * $i) ?>&data=<?= implode(",", $pair[0]) . "|" . implode(",", $pair[1]) ?>" class="btn btn-outline-primary">Lock</a> + <?php endif; ?> + <?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?> + <a href="?ignore=0&day=<?= date('Y-m-d', time() + 86400 * $i) ?>" class="btn btn-outline-<?= $use2023UI ? "secondary" : "success" ?>">Unignore</a> + <?php else: ?> + <a href="?ignore=1&day=<?= date('Y-m-d', time() + 86400 * $i) ?>" class="btn btn-outline-<?= $use2023UI ? "primary" : "danger" ?>">Ignore</a> + <?php endif; ?> + </div> + </div> + <?= $i < 14 ? "<hr>" : "" ?> + <?php endif; + + 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; ?> + </div> +</div> +<?php + + $cache["content"] = ob_get_contents(); + $cache["day"] = date('Y-m-d'); + ob_end_clean(); +} + +echo($cache["content"]); +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json", json_encode($cache)); + +?>
\ No newline at end of file |