From a82d14c168ebc55f01d456d73e55e294352cafde Mon Sep 17 00:00:00 2001 From: torsten Date: Tue, 27 Oct 2026 08:47:08 +0100 Subject: [PATCH] ... --- tippspiel/public/css/style.css | 22 ++++ tippspiel/public/index.php | 17 ++- tippspiel/public/sw.js | 15 ++- tippspiel/src/Models/Ranking.php | 145 +++++++++++++++++++++--- tippspiel/src/Views/home.php | 19 ++++ tippspiel/src/Views/partials/footer.php | 21 ++++ 6 files changed, 213 insertions(+), 26 deletions(-) diff --git a/tippspiel/public/css/style.css b/tippspiel/public/css/style.css index ccfdcaf..7527e2b 100644 --- a/tippspiel/public/css/style.css +++ b/tippspiel/public/css/style.css @@ -95,6 +95,28 @@ a { color: var(--link); } box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); } +/* Automatisch ermittelte Gewinne je abgeschlossener Runde (Startseite) */ +.round-winnings-title { + margin: 0 0 0.1em; +} +.round-winnings { + list-style: none; + margin: 0 0 0.8em; + padding: 0; +} +.round-winnings li { + padding: 0.1em 0; +} +.round-winnings .win-type { + color: var(--muted); + font-size: 0.9em; +} +.round-note { + margin: 0 0 0.6em; + color: var(--muted); + font-style: italic; +} + /* Sprungziele (#round-…, #playerid_…) nicht unter der fixierten Navigation verstecken */ [id] { scroll-margin-top: 90px; } a:hover { color: var(--pitch-dark); } diff --git a/tippspiel/public/index.php b/tippspiel/public/index.php index 77dfc9b..2082876 100644 --- a/tippspiel/public/index.php +++ b/tippspiel/public/index.php @@ -6,6 +6,12 @@ require_once __DIR__ . '/../src/autoload.php'; // Auth-System initialisieren App\Core\Auth::start(); +// HTML-Seiten nicht cachen: Sie enthalten den Login-Status und dürfen nach +// Ablauf der Session nicht als veraltete, eingeloggte Ansicht erscheinen. +header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); +header('Pragma: no-cache'); +header('Expires: 0'); + use App\Core\Database; use App\Core\Auth; use App\Core\Mailer; @@ -985,17 +991,22 @@ if ($page === 'reminder') { try { $currentSeason = Season::getViewSeason(); $message = Setting::getMessage(); + $rounds = []; + $roundSummaries = []; if ($currentSeason) { - $rounds = []; foreach (Round::getBySeason($currentSeason['id']) as $round) { if (Round::isCompleted(Game::getGamesByRound($round['id']))) { $rounds[] = $round; } } $rounds = array_reverse($rounds); - } else { - $rounds = []; + + // Gewinne und Besonderheiten je Runde automatisch aus der Wertung + if (!empty($rounds)) { + $result = Ranking::compute($currentSeason['id'], (int)$rounds[0]['id']); + $roundSummaries = Ranking::roundSummary($result); + } } require __DIR__ . '/../src/Views/home.php'; diff --git a/tippspiel/public/sw.js b/tippspiel/public/sw.js index b144eec..535c0fc 100644 --- a/tippspiel/public/sw.js +++ b/tippspiel/public/sw.js @@ -1,10 +1,10 @@ // Service Worker für Tippspiel 2027 -// Cacht statische Assets (App-Shell) für schnellen Start und eingeschränkten Offline-Betrieb. -// Dynamische Seiten (HTML) bleiben network-first, damit keine veralteten Inhalte ausgeliefert werden. +// Cacht nur statische Assets (App-Shell) für schnellen Start. +// HTML-Seiten werden bewusst NICHT gecacht: Sie enthalten den Login-Status und +// würden nach Ablauf der Session eine veraltete, eingeloggte Ansicht zeigen. -const CACHE_NAME = 'tippspiel2027-v1'; +const CACHE_NAME = 'tippspiel2027-v2'; const STATIC_ASSETS = [ - '/', '/css/style.css', '/img/icon-192.png', '/img/icon-512.png', @@ -51,8 +51,7 @@ self.addEventListener('fetch', (event) => { return; } - // Dynamische Seiten: Network-First, Fallback auf Cache (nur wenn offline) - event.respondWith( - fetch(event.request).catch(() => caches.match(event.request)) - ); + // Alle anderen Anfragen (insbesondere HTML) immer direkt ans Netz – + // der Server entscheidet anhand der Session, ob eingeloggt oder nicht. + event.respondWith(fetch(event.request)); }); diff --git a/tippspiel/src/Models/Ranking.php b/tippspiel/src/Models/Ranking.php index 8e3f8af..754c882 100644 --- a/tippspiel/src/Models/Ranking.php +++ b/tippspiel/src/Models/Ranking.php @@ -32,7 +32,8 @@ class Ranking { * @return array [ * 'max_round_id' => int, * 'users' => user_id => Zeile aus `users` (nur bezahlte Spieler), - * 'rounds' => round_id => ['round', 'games', 'completed', 'entries' => user_id => Auswertung], + * 'rounds' => round_id => ['round', 'games', 'completed', 'entries' => user_id => Auswertung, + * 'day_prize' => Info zum Tagessieg-Preisgeld dieser Runde], * 'ranks' => user_id => Rang (sortiert nach Rang), * 'totals' => user_id => Gesamtpunkte, * 'tipps' => user_id => game_id => Tipp (nur für $maxRoundId), @@ -61,6 +62,8 @@ class Ranking { $rounds = []; $dayPrizePot = 0.0; $jackpotAwarded = false; + $lastRound = end($allRounds); + $lastRoundId = $lastRound ? (int)$lastRound['id'] : null; foreach ($allRounds as $round) { $roundId = (int)$round['id']; @@ -92,8 +95,14 @@ class Ranking { } // Tagessieg: Preisgeld sammelt sich, bis es einen Sieger gibt - $dayPrizePot += $payouts['tagessieg']; - $winners = $completed ? self::determineDayWinners($entries) : []; + $carriedIn = $dayPrizePot; + $dayPrizePot += (float)$payouts['tagessieg']; + $availablePot = $dayPrizePot; + + $candidates = $completed ? self::determineDayCandidates($entries) : []; + $winners = self::limitDayWinners($candidates, $entries); + $perWinner = 0.0; + $carriedOut = 0.0; if (!empty($winners)) { $perWinner = round($dayPrizePot / count($winners), 2); $dayPrizePot = 0.0; @@ -101,6 +110,9 @@ class Ranking { $entries[$userId]['is_day_winner'] = true; $entries[$userId]['payout'] = $perWinner; } + } elseif ($completed) { + // Ohne Tagessieg wandert das Preisgeld in die nächste Runde + $carriedOut = $dayPrizePot; } // Jackpot: einmal pro Saison, wenn alle Spiele der Runde exakt getippt wurden @@ -121,13 +133,23 @@ class Ranking { 'games' => $games, 'completed' => $completed, 'entries' => $entries, + 'day_prize' => [ + 'carried_in' => $carriedIn, + 'share' => (float)$payouts['tagessieg'], + 'pot' => $availablePot, + 'winner_candidates' => count($candidates), + 'winner_count' => count($winners), + 'winners_limited' => count($winners) < count($candidates), + 'per_winner' => $perWinner, + 'carried_out' => $carriedOut, + 'is_last_round' => $lastRoundId !== null && $roundId === $lastRoundId, + ], ]; } $ranks = self::computeRanks($totals, $users); - $lastRound = end($allRounds); - $isFinal = $lastRound && (int)$lastRound['id'] === $maxRoundId && isset($rounds[$maxRoundId]); + $isFinal = $lastRoundId !== null && $lastRoundId === $maxRoundId && isset($rounds[$maxRoundId]); return [ 'max_round_id' => $maxRoundId, @@ -230,6 +252,90 @@ class Ranking { return $items; } + /** + * Gewinne und Besonderheiten je Runde für die Startseite. + * Ersetzt die früher manuell im Rundenbericht eingetragenen Gewinner. + * + * @param array $result Ergebnis von compute() + * @return array round_id => [ + * 'winnings' => [['name' => string, 'amount' => float, 'label' => string], ...], + * 'notes' => string[], + * ] + */ + public static function roundSummary(array $result) { + $summary = []; + + foreach ($result['rounds'] as $roundId => $round) { + $winnings = []; + foreach ($round['entries'] as $userId => $entry) { + $name = $result['users'][$userId]['name']; + if ($entry['payout'] > 0) { + $winnings[] = [ + 'name' => $name, + 'amount' => $entry['payout'], + 'label' => 'Tagessieg', + ]; + } + if ($entry['jackpot_payout'] > 0) { + $winnings[] = [ + 'name' => $name, + 'amount' => $entry['jackpot_payout'], + 'label' => 'Jackpot', + ]; + } + } + if (!empty($winnings)) { + usort($winnings, fn($a, $b) => + [$b['amount'], $a['name']] <=> [$a['amount'], $b['name']] + ); + } + + $notes = []; + $day = $round['day_prize'] ?? null; + if ($day && $round['completed'] && !empty($round['entries'])) { + if ($day['per_winner'] > 0 && $day['carried_in'] > 0) { + $notes[] = 'Das Tagessieg-Preisgeld enthält ' + . self::euro($day['carried_in']) . ' aus vorherigen Runden ohne Tagessieg.'; + } + + if ($day['winner_candidates'] === 0) { + if ($day['carried_out'] > 0) { + $notes[] = $day['is_last_round'] + ? 'Kein Tagessieg: Niemand hat ein exaktes Ergebnis getippt. ' + . 'Das Preisgeld von ' . self::euro($day['carried_out']) . ' wird nicht mehr ausgeschüttet.' + : 'Kein Tagessieg: Niemand hat ein exaktes Ergebnis getippt. ' + . 'Das Preisgeld von ' . self::euro($day['carried_out']) + . ' wandert in die nächste Runde mit einem Tagessieg.'; + } else { + $notes[] = 'Kein Tagessieg: Niemand hat ein exaktes Ergebnis getippt.'; + } + } elseif ($day['winner_candidates'] > self::MAX_DAY_WINNERS) { + $notes[] = $day['winners_limited'] + ? 'Mehr als ' . self::MAX_DAY_WINNERS . ' Spieler hatten den besten Tagessieg. ' + . 'Entscheidend waren daher die Rundenpunkte.' + : 'Mehr als ' . self::MAX_DAY_WINNERS . ' Spieler hatten den besten Tagessieg und ' + . 'gleich viele Rundenpunkte. Das Preisgeld wird unter allen aufgeteilt.'; + } + } + + if (!empty($winnings) || !empty($notes)) { + $summary[$roundId] = ['winnings' => $winnings, 'notes' => $notes]; + } + } + + return $summary; + } + + /** + * Betrag im deutschen Format für Hinweistexte. + * + * @param float $amount + * @return string + */ + private static function euro($amount) { + return number_format((float)$amount, 2, ',', '.') . ' €'; + } + /** * Status des Saison-Jackpots: ob er bereits gewonnen wurde und von wem. * Gewonnen ist er, sobald in einer abgeschlossenen Runde mindestens ein Spieler @@ -363,12 +469,12 @@ class Ranking { } /** - * Tagessieger einer Runde. + * Alle Spieler mit dem besten Tagesergebnis (vor der 6er-Begrenzung). * * @param array $entries user_id => Auswertung (Tipp::evaluateRound) * @return array user_ids */ - private static function determineDayWinners(array $entries) { + private static function determineDayCandidates(array $entries) { $best = null; foreach ($entries as $entry) { if ($best === null || Tipp::compareDayScore($entry, $best) < 0) { @@ -379,20 +485,29 @@ class Ranking { return []; } - $winners = array_keys(array_filter( + return array_keys(array_filter( $entries, fn($entry) => Tipp::compareDayScore($entry, $best) === 0 )); + } - if (count($winners) > self::MAX_DAY_WINNERS) { - $maxPoints = max(array_map(fn($userId) => $entries[$userId]['points'], $winners)); - $winners = array_values(array_filter( - $winners, - fn($userId) => $entries[$userId]['points'] === $maxPoints - )); + /** + * Begrenzt mehr als MAX_DAY_WINNERS Tagessieger auf die mit den meisten Rundenpunkten. + * + * @param array $candidates user_ids + * @param array $entries user_id => Auswertung (Tipp::evaluateRound) + * @return array user_ids + */ + private static function limitDayWinners(array $candidates, array $entries) { + if (count($candidates) <= self::MAX_DAY_WINNERS) { + return $candidates; } - return $winners; + $maxPoints = max(array_map(fn($userId) => $entries[$userId]['points'], $candidates)); + return array_values(array_filter( + $candidates, + fn($userId) => $entries[$userId]['points'] === $maxPoints + )); } /** diff --git a/tippspiel/src/Views/home.php b/tippspiel/src/Views/home.php index fd2396a..30f41de 100644 --- a/tippspiel/src/Views/home.php +++ b/tippspiel/src/Views/home.php @@ -16,7 +16,26 @@ require __DIR__ . '/partials/header.php';

Saison:

+ [], 'notes' => []]; + $winnings = $summary['winnings']; + ?>

+ +

Gewinne:

+ + + +

+

diff --git a/tippspiel/src/Views/partials/footer.php b/tippspiel/src/Views/partials/footer.php index 16f81a6..a8b3b4c 100644 --- a/tippspiel/src/Views/partials/footer.php +++ b/tippspiel/src/Views/partials/footer.php @@ -1,7 +1,28 @@