feat: Implementiere Saison-Logik zur Anzeige aktueller Runden

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-03 16:49:52 +02:00
parent 6a2e8cbb57
commit 7c71a00095
2 changed files with 40 additions and 2 deletions

View file

@ -7,6 +7,7 @@ use App\Core\Database;
use App\Models\Game;
use App\Models\Tipp;
use App\Models\Round;
use App\Models\Season;
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
@ -20,8 +21,14 @@ if ($uri === '/' || $uri === '/index.php') {
echo "<p>Datenbank verbunden! Aktuell <strong>$userCount</strong> User im System.</p>";
echo "<h2>Rundenübersicht</h2>";
// ToDo: Saison-Logik implementieren. Aktuell werden alle Runden angezeigt.
$rounds = $db->query("SELECT * FROM rounds ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
$currentSeason = Season::getCurrent();
if ($currentSeason) {
echo "<p>Saison: <strong>" . htmlspecialchars($currentSeason['name']) . "</strong></p>";
$rounds = Round::getBySeason($currentSeason['id']);
} else {
$rounds = [];
}
if ($rounds) {
echo "<ul>";
foreach ($rounds as $round) {

31
src/Models/Season.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace App\Models;
use App\Core\Database;
class Season {
/**
* Holt die aktuell als "aktiv" markierte Saison.
* Annahme: Es gibt eine Spalte `is_current` (TINYINT) in der `seasons` Tabelle.
* Fallback: Die Saison mit der höchsten ID.
*/
public static function getCurrent() {
$db = Database::getConnection();
// Versuche zuerst, eine explizit als aktuell markierte Saison zu finden
$stmt = $db->prepare("SELECT * FROM seasons WHERE is_current = 1 LIMIT 1");
$stmt->execute();
$season = $stmt->fetch();
if ($season) {
return $season;
}
// Fallback: Wenn keine Saison als aktuell markiert ist, nimm die mit der höchsten ID
$stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC LIMIT 1");
$stmt->execute();
return $stmt->fetch();
}
}