...
This commit is contained in:
parent
1c712d0781
commit
a82d14c168
6 changed files with 213 additions and 26 deletions
|
|
@ -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); }
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,26 @@ require __DIR__ . '/partials/header.php';
|
|||
<p>Saison: <strong><?php echo htmlspecialchars($currentSeason['name']); ?></strong></p>
|
||||
<?php if ($rounds): ?>
|
||||
<?php foreach ($rounds as $round): ?>
|
||||
<?php
|
||||
$summary = $roundSummaries[$round['id']] ?? ['winnings' => [], 'notes' => []];
|
||||
$winnings = $summary['winnings'];
|
||||
?>
|
||||
<h3><a href="/index.php?page=ranking&round_id=<?php echo htmlspecialchars($round['id']); ?>"><?php echo htmlspecialchars($round['name']); ?></a></h3>
|
||||
<?php if ($winnings): ?>
|
||||
<p class="round-winnings-title"><strong>Gewinne:</strong></p>
|
||||
<ul class="round-winnings">
|
||||
<?php foreach ($winnings as $win): ?>
|
||||
<li>
|
||||
<strong><?php echo htmlspecialchars($win['name']); ?></strong>:
|
||||
<?php echo number_format($win['amount'], 2, ',', '.'); ?> €
|
||||
<span class="win-type">(<?php echo htmlspecialchars($win['label']); ?>)</span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($summary['notes'] as $note): ?>
|
||||
<p class="round-note"><?php echo htmlspecialchars($note); ?></p>
|
||||
<?php endforeach; ?>
|
||||
<?php if (!empty($round['report'])): ?>
|
||||
<p><?php echo nl2br(htmlspecialchars(Round::reportToText($round['report']))); ?></p>
|
||||
<?php endif; ?>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,28 @@
|
|||
</main>
|
||||
<footer class="site-footer">⚽ Tippspiel 2027</footer>
|
||||
<script>
|
||||
// Veraltete, noch als eingeloggt gerenderte Seiten dürfen nicht stehen
|
||||
// bleiben: Bei Wiederherstellung aus dem Back-Forward-Cache neu laden,
|
||||
// damit der Server den Login-Status erneut prüft.
|
||||
window.addEventListener('pageshow', function (event) {
|
||||
if (event.persisted) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
var hadController = !!navigator.serviceWorker.controller;
|
||||
var reloading = false;
|
||||
|
||||
// Übernimmt ein neuer Service Worker, die Seite einmal neu laden,
|
||||
// damit keine alte App-Shell mehr angezeigt wird.
|
||||
navigator.serviceWorker.addEventListener('controllerchange', function () {
|
||||
if (hadController && !reloading) {
|
||||
reloading = true;
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
navigator.serviceWorker.register('/sw.js');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue