diff --git a/src/Models/Season.php b/src/Models/Season.php index 63d2df7..617860d 100644 --- a/src/Models/Season.php +++ b/src/Models/Season.php @@ -14,38 +14,18 @@ class Season { public static function getCurrent() { $db = Database::getConnection(); - try { - // 1. Versuch: explizit markierte Saison - $stmt = $db->prepare("SELECT * FROM seasons WHERE is_current = 1 LIMIT 1"); - $stmt->execute(); - $season = $stmt->fetch(); - if ($season) { - return $season; - } - - // 2. Versuch: Letzte Saison nach ID - $stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC LIMIT 1"); - $stmt->execute(); - - // Gibt die gefundene Saison oder `false` zurück. Die Funktion endet hier, wenn die Abfrage erfolgreich war. - return $stmt->fetch(); - - } catch (\PDOException $e) { - // Fallback: Wird ausgeführt, wenn die 'seasons'-Tabelle nicht existiert. - // Wir ermitteln die höchste season_id aus der 'rounds'-Tabelle. - $stmt = $db->prepare("SELECT season_id FROM rounds ORDER BY season_id DESC LIMIT 1"); - $stmt->execute(); - $row = $stmt->fetch(); - if ($row) { - // Erstelle ein "Dummy" Season-Objekt für die Kompatibilität - return [ - 'id' => $row['season_id'], - 'name' => 'Saison ' . $row['season_id'] - ]; - } + // 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; } - // Wird erreicht, wenn 'seasons' nicht existiert und auch keine Runden gefunden wurden. - return null; + // 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(); } }