Skip to content

Instantly share code, notes, and snippets.

@marceljuenemann
Last active September 1, 2025 20:24
Show Gist options
  • Save marceljuenemann/7b9d6d9c8d1650582ec378589e251f50 to your computer and use it in GitHub Desktop.
Save marceljuenemann/7b9d6d9c8d1650582ec378589e251f50 to your computer and use it in GitHub Desktop.
This is an example showing how to use the NSV API for fetching details about a team. The code is an AI-generated adaptation of the twig templates used in the actual production system.
<?php
$team = json_decode(file_get_contents("https://nsv-online.de/ligen/bezirk1-2425/api/teams/7951/"));
if (!empty($team->pairingsByDivision)) {
echo '<div class="col-12 col-lg-6 nsv-print-w50">';
foreach ($team->pairingsByDivision as $divisionId => $pairings) {
// You may need to fetch division info separately
echo "<h4 class='mt-4'>Division $divisionId</h4>";
echo "<table class='nsv-table text-center'><tr>
<th>R</th>
<th>Tag</th>
<th>H/G</th>
<th>Gegner</th>
<th>Erg.</th>
</tr>";
foreach ($pairings as $pairing) {
echo "<tr>";
echo "<td><a href='{$pairing->uri}'>{$pairing->round}</a></td>";
echo "<td><a href='{$pairing->uri}'>" . (!empty($pairing->date) ? date('d.m.', strtotime($pairing->date)) : '') . "</a></td>";
echo "<td>" . ($pairing->home ? 'Heim' : 'Gast') . "</td>";
echo "<td class='text-start'>{$pairing->opponent->name}</td>";
echo "<td class='text-nowrap'><a href='{$pairing->uri}'>" . (!empty($pairing->result) ? $pairing->result : '') . "</a></td>";
echo "</tr>";
}
echo "</table>";
}
echo "</div>";
} elseif (!empty($team->division)) {
echo '<div class="col-12">';
echo '<h4 class="mt-4">Staffel</h4>';
echo $team->division->name;
echo '</div>';
}
echo '<div class="col-12 col-lg-6 nsv-print-w50">';
echo '<h4 class="mt-4">Spiellokal</h4>';
if (!empty($team->venue)) {
echo @htmlspecialchars($team->venue->name) . "<br>";
echo @htmlspecialchars($team->venue->street) . "<br>";
echo @htmlspecialchars($team->venue->postCode) . " " . @htmlspecialchars($team->venue->city) . "<br>";
if (!empty($team->venue->phone)) echo "Tel. " . @htmlspecialchars($team->venue->phone) . "<br>";
if (!empty($team->venue->note)) echo "<i>" . @htmlspecialchars($team->venue->note) . "</i><br>";
if (!empty($team->venue->isAccessible)) echo "<img src='/ligen/_templates/systemicons/barrierefrei_zugang.jpg' alt='Zugang barrierefrei' width='25' height='25'>";
if (!empty($team->venue->hasAccessibleToilet)) echo "<img src='/ligen/_templates/systemicons/barrierefrei_wc.jpg' alt='WC barrierefrei' width='25' height='25'>";
if (!empty($team->venue->directionsUri)) echo "<a href='" . @htmlspecialchars($team->venue->directionsUri) . "' target='_blank'>Google Maps</a><br>";
}
echo '<h4 class="mt-4">Mannschaftsführer:in</h4>';
if (!empty($team->captain)) {
echo @htmlspecialchars($team->captain->name) . "<br>";
if (!empty($team->captain->phone)) echo "Tel. " . @htmlspecialchars($team->captain->phone) . "<br>";
if (!empty($team->captain->phone2)) echo "Tel. " . @htmlspecialchars($team->captain->phone2) . "<br>";
if (!empty($team->captain->mail)) echo @htmlspecialchars($team->captain->mail) . "<br>";
}
if (!empty($team->additionalRecipients)) {
echo '<h4 class="mt-4">Zusätzliche E-Mail Empfänger</h4>';
foreach ($team->additionalRecipients as $recipient) {
echo "<span class='badge bg-secondary'>" . @htmlspecialchars($recipient) . "</span> ";
}
} else {
echo '<h4 class="mt-4">Zusätzliche E-Mail Empfänger</h4>Keine';
}
echo '</div>';
echo '<h4 class="mt-4">Aufstellung</h4>';
echo "<div class='overflow-auto'>";
echo "<table class='nsv-table borders-bold text-center' cellpadding='3'>";
echo "<tr>
<th>Nr.</th>
<th>Name</th>
<th class='border-right-bold'>DWZ</th>";
// Pairing headers
if (!empty($team->pairingsByDivision)) {
foreach ($team->pairingsByDivision as $divisionId => $pairings) {
foreach ($pairings as $pairing) {
echo "<th class='nsv-details'><a href='{$pairing->uri}'>&nbsp;{$pairing->round}&nbsp;</a></th>";
}
}
}
echo "<th class='border-left-bold'>Pkt</th>
<th>Sp.</th>
<th>%</th>
</tr>";
if (!empty($team->playersByTeamNumber)) {
foreach ($team->playersByTeamNumber as $teamNumber => $players) {
foreach ($players as $player) {
echo "<tr>";
echo "<td class='text-end'>" . @htmlspecialchars($player->number) . "</td>";
echo "<td class='text-start'>" . @htmlspecialchars($player->name);
if (!empty($player->isGuest)) {
echo " <span class='badge bg-secondary rounded-circle ms-1'>G</span>";
}
echo "</td>";
echo "<td class='border-right-bold'>" . @htmlspecialchars($player->dwz) . "</td>";
// Player games
if (!empty($team->pairingsByDivision)) {
foreach ($team->pairingsByDivision as $divisionId => $pairings) {
foreach ($pairings as $pairing) {
if (!empty($player->games->{$pairing->id})) {
$game = $player->games->{$pairing->id};
echo "<td class='nsv-details'><a href='{$pairing->uri}'>" . @htmlspecialchars($game->result) . "</a></td>";
} else {
echo "<td class='nsv-details'></td>";
}
}
}
}
$points = !empty($player->points) ? $player->points : 0;
$gameCount = !empty($player->gameCount) ? $player->gameCount : 0;
echo "<td class='border-left-bold'>" . ($gameCount ? number_format($points, 1) : '') . "</td>";
echo "<td>" . ($gameCount ? $gameCount : '') . "</td>";
echo "<td>" . ($gameCount ? round(100 * $points / $gameCount) : '') . "</td>";
echo "</tr>";
}
}
}
echo "</table></div>";
echo "<pre>";
print_r($team);
echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment