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
+4
View File
@@ -6,3 +6,7 @@ $rennplanJson = file_get_contents('https://api.sat.regattatech.de/api/v1/rennpla
$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/');
$pagerApi = "https://sat.regattatech.de/api/v1/page/";
$pagerApiSecret = "foobar";
+100 -2
View File
@@ -14,8 +14,75 @@ foreach ($rennplanRaw as $lauf) {
// Bootdaten abrufen
$boote = json_decode($bootJson, true);
$bootMap = [];
$bootIdMap = [];
foreach ($boote as $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
@@ -43,13 +110,13 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
<html lang="de">
<head>
<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">
</head>
<body class="bg-light">
<div class="container py-4">
<h1 class="mb-4">Moderation <?php echo $eventname; ?></h1>
<h1 class="mb-4">Moderation <?= htmlspecialchars($eventname) ?></h1>
<!-- Aktuelles Rennen -->
<div class="card mb-4">
@@ -78,6 +145,7 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
<p><strong>Notizen:</strong> <?= htmlspecialchars($boot['notizen'] ?? '') ?></p>
</div>
</div>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
@@ -121,9 +189,26 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
<?php endif; ?>
<?php endfor; ?>
</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: ?>
<p><strong>Letztes Rennen im Lauf</strong></p>
<?php endif; ?>
</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=<?= min($totalRennen - 1, $rennenIndex + 1) ?>" class="btn btn-primary">Nächstes Rennen</a>
</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>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>