tippspiel2027/tippspiel/src/Views/ranking.php
2026-10-18 21:40:43 +02:00

298 lines
13 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$pageTitle = 'Rangliste';
if ($selectedRound) {
$pageTitle .= ' - ' . htmlspecialchars($selectedRound['name']);
}
$bodyClass = 'ranking-page';
require __DIR__ . '/partials/header.php';
// Stellt sicher, dass die benötigten Variablen vorhanden sind
if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allRounds) || !isset($selectedRound)) {
echo "Fehler: Daten für die Rangliste nicht gefunden.";
// exit; // Besser, eine freundliche Nachricht im Layout anzuzeigen
}
?>
<style>
.game-header {
width: 100px; /* Feste Breite für die Spiele-Spalten */
}
table.ranking-table {
width: auto; /* Keine feste Breite, damit die Tabelle frei wachsen kann */
min-width: 100%;
max-width: none; /* Default-max-width (800px) aufheben */
}
.tipp-points {
width: 55px; /* Breite für den Tipp (z.B. 2:1) */
box-sizing: border-box;
text-align: center;
}
.tipp-joker {
width: 70px; /* Breite für vergrößerten Joker */
box-sizing: border-box;
padding-left: 5px;
text-align: center;
}
.joker-icon {
width: 2rem; /* Größe weiter auf 75% reduziert */
height: 2rem; /* Größe weiter auf 75% reduziert */
vertical-align: middle;
}
.daily-winner-icon {
font-size: 2rem; /* Größe verdoppeln */
vertical-align: middle;
}
#round_id {
font-size: inherit; /* Schriftgröße an die Umgebung anpassen */
}
table th, table td {
padding-top: 0.1rem;
padding-bottom: 0.1rem;
}
/* Kompakter Kopfbereich: Titel, Saison und Rundenwahl auf einer Zeile */
.ranking-toolbar {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 0.3em 0.9em;
margin-bottom: 0.8em;
}
.ranking-toolbar h1 {
margin: 0;
padding: 0;
border-bottom: none;
font-size: 1.3em;
}
.ranking-toolbar .season {
font-family: var(--font-display);
font-weight: 700;
color: var(--pitch-dark);
}
.ranking-toolbar .round-filter {
margin: 0 0 0 auto;
}
.ranking-toolbar .round-filter label {
margin-right: 0.3em;
}
/* Legende als kompakte Fußzeile unter der Tabelle */
.legend.legend-footer {
margin: 10px 0 0;
padding: 6px 10px;
font-size: 0.8em;
gap: 6px 12px;
flex-wrap: nowrap; /* nicht umbrechen, volle Breite nutzen */
justify-content: flex-start;
}
.legend.legend-footer .legend-color { width: 12px; height: 12px; }
.legend.legend-footer .joker-icon { width: 1.1em; height: 1.1em; }
.legend.legend-footer .daily-winner-icon { font-size: 1em; }
/* Rundenpunkte als Link mit Aufschlüsselungs-Popup */
.round-points-link {
background: none;
box-shadow: none;
border: none;
border-radius: 0;
padding: 0;
color: var(--link);
text-transform: none;
letter-spacing: 0;
font-family: var(--font);
font-weight: 700;
text-decoration: underline;
cursor: pointer;
}
.round-points-link:hover { background: none; color: var(--pitch-dark); }
.breakdown-modal { position: fixed; inset: 0; z-index: 100; }
.breakdown-modal[hidden] { display: none; }
.breakdown-modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.breakdown-modal-dialog {
position: relative;
margin: 12vh auto;
max-width: 440px;
width: calc(100% - 2em);
background: #fff;
border-radius: 10px;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
padding: 1.2em 1.2em 1.4em;
}
.breakdown-modal-close {
position: absolute;
top: 0.3em;
right: 0.4em;
background: none;
box-shadow: none;
border: none;
border-radius: 0;
padding: 0.1em 0.3em;
font-size: 1.6em;
line-height: 1;
color: var(--muted);
cursor: pointer;
}
.breakdown-modal-close:hover { background: none; color: var(--ink); }
.bd-title { font-weight: 800; font-size: 1.1em; margin-bottom: 0.6em; color: var(--pitch-dark); }
.bd-table { width: 100%; max-width: none; margin: 0 0 0.8em; border: 1px solid var(--line); }
.bd-table th, .bd-table td { padding: 4px 8px; font-size: 0.9em; }
.bd-table .bd-num { text-align: right; }
.bd-joker { font-size: 0.85em; color: var(--muted); }
.bd-line { display: flex; justify-content: space-between; padding: 0.15em 0; }
.bd-line.bd-total { border-top: 2px solid var(--pitch-dark); margin-top: 0.4em; padding-top: 0.4em; font-weight: 700; }
@media (max-width: 700px) {
.ranking-toolbar h1 { font-size: 1.1em; }
.ranking-toolbar .round-filter { margin-left: 0; }
}
</style>
<div class="ranking-toolbar">
<h1>Rangliste</h1>
<span class="season"><?php echo htmlspecialchars($currentSeason['name']); ?></span>
<?php if ($selectedRound): ?>
<form method="get" class="round-filter">
<input type="hidden" name="page" value="ranking">
<label for="round_id">Runde:</label>
<select name="round_id" id="round_id" onchange="this.form.submit()">
<?php foreach ($allRounds as $round): ?>
<option value="<?php echo $round['id']; ?>" <?php echo ($round['id'] == $selectedRound['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($round['name']); ?>
</option>
<?php endforeach; ?>
</select>
</form>
<?php endif; ?>
</div>
<?php if ($selectedRound): ?>
<?php if (!empty($ranking)): ?>
<table class="ranking-table">
<thead>
<tr>
<th class="text-center">Platz</th>
<th>Name</th>
<th class="text-center"><span class="daily-winner-icon">🏆</span></th>
<th class="text-center">Punkte<br>(Gesamt)</th>
<th class="text-center">Punkte<br>(Runde)</th>
<?php foreach ($games as $game): ?>
<th class="game-header" colspan="2">
<?php echo htmlspecialchars($game['team1']); ?><br>
<?php echo htmlspecialchars($game['team2']); ?><br>
<small>(<?php echo htmlspecialchars(App\Models\Game::getResultString($game['score1'], $game['score2'], $game['kickoff'])); ?>)</small>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($ranking as $entry):
$rowClasses = [];
if ($entry['rank'] <= 3) $rowClasses[] = 'rank-' . $entry['rank'];
if ((int)$entry['user_id'] === (int)App\Core\Auth::id()) $rowClasses[] = 'me';
// Aufschlüsselung der Rundenpunkte für den Popup
$breakdownGamePoints = 0;
$breakdownRows = '';
foreach ($games as $game) {
$cell = $entry['cells'][$game['id']];
$pts = (int)$cell['points'];
$breakdownGamePoints += $pts;
$breakdownRows .= '<tr>'
. '<td>' . htmlspecialchars($game['team1'] . ' – ' . $game['team2']) . '</td>'
. '<td>' . htmlspecialchars($cell['text']) . ($cell['joker'] ? ' <span class="bd-joker">(Joker)</span>' : '') . '</td>'
. '<td class="bd-num">' . $pts . '</td>'
. '</tr>';
}
$breakdownBonus = (int)$entry['points'] - $breakdownGamePoints;
$breakdown = '<div class="bd-title">' . htmlspecialchars($entry['name']) . '</div>'
. '<table class="bd-table"><thead><tr><th>Spiel</th><th>Tipp</th><th>Punkte</th></tr></thead>'
. '<tbody>' . $breakdownRows . '</tbody></table>'
. '<div class="bd-line">Spiele gesamt: <strong>' . $breakdownGamePoints . ' P.</strong></div>';
if ($breakdownBonus > 0) {
$breakdown .= '<div class="bd-line">Rundenbonus (alle Spiele mind. Tendenz): <strong>+' . $breakdownBonus . ' P.</strong></div>';
}
$breakdown .= '<div class="bd-line bd-total">Rundenpunkte: <strong>' . (int)$entry['points'] . ' P.</strong></div>';
?>
<tr<?php if ($rowClasses) echo ' class="' . implode(' ', $rowClasses) . '"'; ?>
<?php if ((int)$entry['user_id'] === (int)App\Core\Auth::id()) echo ' id="me-row"'; ?>>
<td class="text-center"><span class="rank-badge"><?php echo $entry['rank']; ?>.</span></td>
<td><?php echo htmlspecialchars($entry['name']); ?></td>
<td class="text-center"><?php echo $entry['is_day_winner'] ? '<span class="daily-winner-icon">🏆</span>' : ''; ?></td>
<td class="text-center"><strong><?php echo $entry['total']; ?></strong></td>
<td class="text-center"><button type="button" class="round-points-link" data-breakdown="<?php echo htmlspecialchars($breakdown, ENT_QUOTES); ?>"><?php echo (int)$entry['points']; ?></button></td>
<?php foreach ($games as $game): ?>
<?php
$tipp = $entry['cells'][$game['id']];
// Farbklasse kommt fertig aus Tipp::getCol (col_tendenz / col_exact / col_joker_exact)
$td_class = $tipp['color'];
$title = "Punkte: " . $tipp['points'];
?>
<td class="tipp-cell tipp-points <?php echo htmlspecialchars($td_class); ?>" title="<?php echo $title; ?>">
<?php echo htmlspecialchars($tipp['text']); ?>
</td>
<td class="tipp-cell tipp-joker" title="<?php echo $title; ?>">
<?php if ($tipp['joker']): ?>
<img src="/img/joker.png" alt="Joker" class="joker-icon" title="Joker">
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>Für diese Saison gibt es noch keine Rangliste (möglicherweise haben noch keine Spieler bezahlt).</p>
<?php endif; ?>
<div class="legend legend-footer">
<div class="legend-item"><span class="daily-winner-icon">🏆</span> Tagessieger</div>
<div class="legend-item"><img src="/img/joker.png" alt="Joker" class="joker-icon"> Joker gesetzt</div>
<div class="legend-item"><div class="legend-color" style="background-color: var(--col-tendenz);"></div> Richtige Tendenz</div>
<div class="legend-item"><div class="legend-color" style="background-color: var(--col-exact);"></div> Richtiges Ergebnis</div>
<div class="legend-item"><div class="legend-color" style="background-color: var(--col-joker-exact);"></div> Richtiges Ergebnis mit Joker</div>
</div>
<?php else: ?>
<p>Keine Runde für die Anzeige ausgewählt oder gefunden.</p>
<?php endif; ?>
<div class="breakdown-modal" id="breakdown-modal" hidden>
<div class="breakdown-modal-backdrop" data-close></div>
<div class="breakdown-modal-dialog" role="dialog" aria-modal="true">
<button type="button" class="breakdown-modal-close" data-close aria-label="Schließen">&times;</button>
<div class="breakdown-modal-body" id="breakdown-modal-body"></div>
</div>
</div>
<script>
// Springe beim Laden zur eigenen Zeile, falls der eingeloggte Spieler in der Tabelle ist
window.addEventListener('load', function () {
var me = document.getElementById('me-row');
if (me) {
me.scrollIntoView({ block: 'center' });
}
});
(function () {
var modal = document.getElementById('breakdown-modal');
var body = document.getElementById('breakdown-modal-body');
if (!modal || !body) return;
function open(html) { body.innerHTML = html; modal.hidden = false; }
function close() { modal.hidden = true; }
document.querySelectorAll('.round-points-link').forEach(function (btn) {
btn.addEventListener('click', function () {
open(btn.getAttribute('data-breakdown'));
});
});
modal.addEventListener('click', function (e) {
if (e.target.hasAttribute && e.target.hasAttribute('data-close')) close();
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') close();
});
})();
</script>
<?php require __DIR__ . '/partials/footer.php'; ?>