feat: Implementiere farbige Tippübersicht mit Joker-Anzeige

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-04 06:11:02 +02:00
parent b7cfb834f7
commit 2127a40b9e
2 changed files with 105 additions and 30 deletions

View file

@ -28,10 +28,40 @@ if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
$allRoundsInSeason = Round::getBySeason($selectedRound['season_id']);
$roundsToShow = [];
$all_game_ids = [];
foreach ($allRoundsInSeason as $round) {
if ($round['id'] <= $selectedRound['id']) {
$round['games'] = Game::getGamesByRound($round['id']);
$gamesOfRound = Game::getGamesByRound($round['id']);
$round['games'] = $gamesOfRound;
$roundsToShow[] = $round;
if (!empty($gamesOfRound)) {
$all_game_ids = array_merge($all_game_ids, array_column($gamesOfRound, 'id'));
}
}
}
// Hole alle zahlenden User der Saison
$db = Database::getConnection();
$stmt_users = $db->prepare("SELECT u.id, u.name FROM users u JOIN payments p ON u.id = p.user_id WHERE p.season_id = ? ORDER BY u.name ASC");
$stmt_users->execute([$selectedRound['season_id']]);
$users = $stmt_users->fetchAll(\PDO::FETCH_ASSOC);
// Hole alle relevanten Tipps
$tipps_map = [];
if (!empty($all_game_ids) && !empty($users)) {
$user_ids = array_column($users, 'id');
$game_placeholders = implode(',', array_fill(0, count($all_game_ids), '?'));
$user_placeholders = implode(',', array_fill(0, count($user_ids), '?'));
$stmt_tipps = $db->prepare("
SELECT user_id, game_id, score1 AS tipp1, score2 AS tipp2, joker
FROM tipps
WHERE game_id IN ($game_placeholders) AND user_id IN ($user_placeholders)
");
$stmt_tipps->execute(array_merge($all_game_ids, $user_ids));
foreach ($stmt_tipps->fetchAll(\PDO::FETCH_ASSOC) as $tipp) {
$tipps_map[$tipp['user_id']][$tipp['game_id']] = $tipp;
}
}

View file

@ -1,45 +1,90 @@
<?php
use App\Models\Game;
use App\Models\Tipp;
// Stellt sicher, dass die benötigten Variablen vorhanden sind
if (!isset($selectedRound) || !isset($roundsToShow)) {
if (!isset($selectedRound) || !isset($roundsToShow) || !isset($users) || !isset($tipps_map)) {
echo "Fehler: Daten für die Rundenansicht nicht gefunden.";
exit;
}
$pageTitle = 'Rundenübersicht - ' . htmlspecialchars($selectedRound['name']);
$pageTitle = 'Tippübersicht - ' . htmlspecialchars($selectedRound['name']);
require __DIR__ . '/partials/header.php';
?>
<style>
/* Styling für die Punkt-Zellen (aus Rangliste übernommen) */
.tipp-cell { text-align: center; position: relative; }
.col_exact { background-color: #28a745 !important; color: white; } /* Exaktes Ergebnis */
.col_diff { background-color: #ffc107 !important; } /* Richtige Tordifferenz */
.col_tendenz { background-color: #17a2b8 !important; color: white; } /* Richtige Tendenz */
.joker-icon { font-size: 0.7em; vertical-align: top; }
th.game-header { white-space: normal; } /* Erlaubt Umbruch im Header */
.table-container { width: 100%; overflow-x: auto; margin-top: 20px; }
</style>
<h1>Tippübersicht bis: <?php echo htmlspecialchars($selectedRound['name']); ?></h1>
<?php foreach ($roundsToShow as $round): ?>
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
<?php if (!empty($round['games'])): ?>
<table>
<thead>
<tr>
<th>Anpfiff</th>
<th>Heim</th>
<th>Gast</th>
<th>Ergebnis</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($round['games'] as $game): ?>
<?php if (empty($users)): ?>
<p>Keine teilnehmenden Spieler für diese Saison gefunden.</p>
<?php else: ?>
<?php foreach ($roundsToShow as $round): ?>
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
<?php if (!empty($round['games'])): ?>
<div class="table-container">
<table>
<thead>
<tr>
<td><?php echo htmlspecialchars((new DateTime($game['kickoff']))->format('d.m.Y H:i')); ?></td>
<td><?php echo htmlspecialchars($game['team1']); ?></td>
<td><?php echo htmlspecialchars($game['team2']); ?></td>
<td><?php echo App\Models\Game::getResultString($game['score1'], $game['score2'], $game['kickoff']); ?></td>
<td><?php echo App\Models\Game::isLocked($game['kickoff']) ? 'Gesperrt' : 'Offen'; ?></td>
<th>Spieler</th>
<?php foreach ($round['games'] as $game): ?>
<th class="game-header">
<?php echo htmlspecialchars($game['team1']); ?><br>
<?php echo htmlspecialchars($game['team2']); ?><br>
<small>(<?php echo Game::getResultString($game['score1'], $game['score2'], $game['kickoff']); ?>)</small>
</th>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>Für diese Runde wurden keine Spiele gefunden.</p>
<?php endif; ?>
<?php endforeach; ?>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo htmlspecialchars($user['name']); ?></td>
<?php foreach ($round['games'] as $game): ?>
<?php
$tipp = $tipps_map[$user['id']][$game['id']] ?? null;
$color = '';
$text = '-';
$is_joker = false;
if ($tipp && $game['score1'] > -1) {
$color = Tipp::getCol($game['score1'], $game['score2'], $tipp['tipp1'], $tipp['tipp2'], $tipp['joker']);
}
if ($tipp) {
// Zeige Tipps nur für gesperrte Spiele
if (Game::isLocked($game['kickoff'])) {
$text = $tipp['tipp1'] . ':' . $tipp['tipp2'];
} else {
$text = 'verdeckt';
}
$is_joker = (bool)$tipp['joker'];
}
?>
<td class="tipp-cell <?php echo htmlspecialchars($color); ?>">
<?php echo htmlspecialchars($text); ?>
<?php if ($is_joker && Game::isLocked($game['kickoff'])): ?>
<span class="joker-icon" title="Joker">🃏</span>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>Für diese Runde wurden keine Spiele gefunden.</p>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<p><a href="/">Zurück zur Startseite</a></p>