add pager api

This commit is contained in:
Thies Mueller
2026-06-04 19:10:47 +02:00
parent 2d766c4e5b
commit f9dbc096c5
2 changed files with 114 additions and 12 deletions
+5 -1
View File
@@ -5,4 +5,8 @@ $rennplanJson = file_get_contents('https://api.sat.regattatech.de/api/v1/rennpla
$bootJson = file_get_contents('https://api.sat.regattatech.de/api/v1/boot/'); $bootJson = file_get_contents('https://api.sat.regattatech.de/api/v1/boot/');
$ergebnisseJson = file_get_contents('https://api.sat.regattatech.de/api/v1/results/current/'); $ergebnisseJson = file_get_contents('https://api.sat.regattatech.de/api/v1/results/current/');
$pagerApi = "https://sat.regattatech.de/api/v1/page/";
$pagerApiSecret = "foobar";
+109 -11
View File
@@ -14,14 +14,81 @@ foreach ($rennplanRaw as $lauf) {
// Bootdaten abrufen // Bootdaten abrufen
$boote = json_decode($bootJson, true); $boote = json_decode($bootJson, true);
$bootMap = []; $bootMap = [];
$bootIdMap = [];
foreach ($boote as $boot) { foreach ($boote as $boot) {
$bootMap[$boot['name']] = $boot; $bootMap[$boot['name']] = $boot;
$bootIdMap[$boot['name']] = $boot['id'];
}
// Pager
function pageTeam($message, $pagerApi, $pagerApiSecret)
{
$ch = curl_init($pagerApi);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $message,
CURLOPT_HTTPHEADER => [
'Content-Type: text/plain',
'Authorization: Bearer ' . $pagerApiSecret
]
]);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
// Paging
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
switch ($_POST['action']) {
case 'page_team':
if (!empty($_POST['bootid'])) {
pageTeam($_POST['bootid'], $pagerApi, $pagerApiSecret);
}
break;
case 'page_next':
if (isset($_POST['rennen']) && isset($rennplan[(int)$_POST['rennen'] + 1])) {
$nextRace = $rennplan[(int)$_POST['rennen'] + 1];
for ($i = 1; $i <= 3; $i++) {
if (empty($nextRace["bahn$i"])) {
continue;
}
$bootName = $nextRace["bahn$i"];
if (isset($bootIdMap[$bootName])) {
pageTeam(
$bootIdMap[$bootName],
$pagerApi,
$pagerApiSecret
);
}
}
}
break;
case 'page_all':
pageTeam(
'ALL',
$pagerApi,
$pagerApiSecret
);
break;
}
} }
// Ergebnisse abrufen // Ergebnisse abrufen
$ergebnisse = isset(json_decode($ergebnisseJson, true)['ergebnisse']) $ergebnisse = isset(json_decode($ergebnisseJson, true)['ergebnisse'])
? json_decode($ergebnisseJson, true)['ergebnisse'] ? json_decode($ergebnisseJson, true)['ergebnisse']
: []; : [];
// Aktuelles Rennen per Index (über URL) // Aktuelles Rennen per Index (über URL)
$rennenIndex = isset($_GET['rennen']) ? intval($_GET['rennen']) : 0; $rennenIndex = isset($_GET['rennen']) ? intval($_GET['rennen']) : 0;
@@ -43,13 +110,13 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
<html lang="de"> <html lang="de">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Moderation <?php echo $eventname; ?></title> <title>Moderation <?= htmlspecialchars($eventname) ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head> </head>
<body class="bg-light"> <body class="bg-light">
<div class="container py-4"> <div class="container py-4">
<h1 class="mb-4">Moderation <?php echo $eventname; ?></h1> <h1 class="mb-4">Moderation <?= htmlspecialchars($eventname) ?></h1>
<!-- Aktuelles Rennen --> <!-- Aktuelles Rennen -->
<div class="card mb-4"> <div class="card mb-4">
@@ -60,12 +127,12 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
$bootName = $current["bahn$i"]; $bootName = $current["bahn$i"];
$boot = $bootMap[$bootName] ?? null; $boot = $bootMap[$bootName] ?? null;
?> ?>
<div class="mb-2"> <div class="mb-2">
<strong>Bahn <?= $i ?>:</strong> <?= htmlspecialchars($bootName) ?> <strong>Bahn <?= $i ?>:</strong> <?= htmlspecialchars($bootName) ?>
<?php if ($boot): ?> <?php if ($boot): ?>
<button class="btn btn-sm btn-outline-secondary ms-2" data-bs-toggle="collapse" data-bs-target="#bootDetails<?= $i ?>">Details</button> <button class="btn btn-sm btn-outline-secondary ms-2" data-bs-toggle="collapse" data-bs-target="#bootDetails<?= $i ?>">Details</button>
<div class="collapse mt-2" id="bootDetails<?= $i ?>"> <div class="collapse mt-2" id="bootDetails<?= $i ?>">
<div class="card card-body"> <div class="card card-body">
<p><strong>Wer sind wir:</strong> <?= nl2br(htmlspecialchars($boot['wernsindwir'] ?? '')) ?></p> <p><strong>Wer sind wir:</strong> <?= nl2br(htmlspecialchars($boot['wernsindwir'] ?? '')) ?></p>
<p><strong>Woher kommen wir:</strong> <?= htmlspecialchars($boot['woherkommenwir'] ?? '') ?></p> <p><strong>Woher kommen wir:</strong> <?= htmlspecialchars($boot['woherkommenwir'] ?? '') ?></p>
<p><strong>Trommlerin:</strong> <?= htmlspecialchars($boot['trommlerin'] ?? '-') ?></p> <p><strong>Trommlerin:</strong> <?= htmlspecialchars($boot['trommlerin'] ?? '-') ?></p>
@@ -78,8 +145,9 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
<p><strong>Notizen:</strong> <?= htmlspecialchars($boot['notizen'] ?? '') ?></p> <p><strong>Notizen:</strong> <?= htmlspecialchars($boot['notizen'] ?? '') ?></p>
</div> </div>
</div> </div>
<?php endif; ?> </div>
</div> <?php endif; ?>
</div>
<?php endif; ?> <?php endif; ?>
<?php endfor; ?> <?php endfor; ?>
</div> </div>
@@ -121,9 +189,26 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
<?php endif; ?> <?php endif; ?>
<?php endfor; ?> <?php endfor; ?>
</ul> </ul>
<form method="post" class="mt-3">
<input
type="hidden"
name="action"
value="page_next">
<input
type="hidden"
name="rennen"
value="<?= $rennenIndex ?>">
<button
type="submit"
class="btn btn-warning">
Alle Boote des nächsten Rennens pagen
</button>
</form>
<?php else: ?> <?php else: ?>
<p><strong>Letztes Rennen im Lauf</strong></p> <p><strong>Letztes Rennen im Lauf</strong></p>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
@@ -132,6 +217,19 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
<a href="?rennen=<?= max(0, $rennenIndex - 1) ?>" class="btn btn-outline-secondary">Vorheriges Rennen</a> <a href="?rennen=<?= max(0, $rennenIndex - 1) ?>" class="btn btn-outline-secondary">Vorheriges Rennen</a>
<a href="?rennen=<?= min($totalRennen - 1, $rennenIndex + 1) ?>" class="btn btn-primary">Nächstes Rennen</a> <a href="?rennen=<?= min($totalRennen - 1, $rennenIndex + 1) ?>" class="btn btn-primary">Nächstes Rennen</a>
</div> </div>
<hr>
<form method="post">
<input
type="hidden"
name="action"
value="page_all">
<button
type="submit"
class="btn btn-danger">
Alle Teams pagen
</button>
</form>
</div> </div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>