2026-10-03 16:49:52 +02:00
|
|
|
<?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();
|
|
|
|
|
|
2026-10-03 16:51:01 +02:00
|
|
|
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']
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-10-03 16:49:52 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-03 16:51:01 +02:00
|
|
|
// Wird erreicht, wenn 'seasons' nicht existiert und auch keine Runden gefunden wurden.
|
|
|
|
|
return null;
|
2026-10-03 16:49:52 +02:00
|
|
|
}
|
|
|
|
|
}
|