add pager api
This commit is contained in:
@@ -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";
|
||||
@@ -14,14 +14,81 @@ 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
|
||||
$ergebnisse = isset(json_decode($ergebnisseJson, true)['ergebnisse'])
|
||||
? json_decode($ergebnisseJson, true)['ergebnisse']
|
||||
: [];
|
||||
? json_decode($ergebnisseJson, true)['ergebnisse']
|
||||
: [];
|
||||
|
||||
// Aktuelles Rennen per Index (über URL)
|
||||
$rennenIndex = isset($_GET['rennen']) ? intval($_GET['rennen']) : 0;
|
||||
@@ -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">
|
||||
@@ -60,12 +127,12 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
|
||||
$bootName = $current["bahn$i"];
|
||||
$boot = $bootMap[$bootName] ?? null;
|
||||
?>
|
||||
<div class="mb-2">
|
||||
<strong>Bahn <?= $i ?>:</strong> <?= htmlspecialchars($bootName) ?>
|
||||
<?php if ($boot): ?>
|
||||
<button class="btn btn-sm btn-outline-secondary ms-2" data-bs-toggle="collapse" data-bs-target="#bootDetails<?= $i ?>">Details</button>
|
||||
<div class="mb-2">
|
||||
<strong>Bahn <?= $i ?>:</strong> <?= htmlspecialchars($bootName) ?>
|
||||
<?php if ($boot): ?>
|
||||
<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="card card-body">
|
||||
<div class="card card-body">
|
||||
<p><strong>Wer sind wir:</strong> <?= nl2br(htmlspecialchars($boot['wernsindwir'] ?? '')) ?></p>
|
||||
<p><strong>Woher kommen wir:</strong> <?= htmlspecialchars($boot['woherkommenwir'] ?? '') ?></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>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user