feat: Nutze Einstellungen für aktuelle Saison-ID
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
bbf8723554
commit
6d703b3deb
1 changed files with 17 additions and 8 deletions
|
|
@ -7,23 +7,32 @@ 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.
|
||||
* Holt die aktuell selektierte Saison aus den `settings`.
|
||||
* Annahme: Es gibt eine Tabelle `settings` mit dem Feld `current_season_id`.
|
||||
* 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");
|
||||
// Lese die current_season_id aus der settings Tabelle
|
||||
$stmt = $db->prepare("SELECT current_season_id FROM settings LIMIT 1");
|
||||
$stmt->execute();
|
||||
$season = $stmt->fetch();
|
||||
$setting = $stmt->fetch();
|
||||
|
||||
if ($season) {
|
||||
return $season;
|
||||
if ($setting && !empty($setting['current_season_id'])) {
|
||||
$seasonId = $setting['current_season_id'];
|
||||
|
||||
// Hole die Saison mit der entsprechenden ID
|
||||
$stmt = $db->prepare("SELECT * FROM seasons WHERE id = ?");
|
||||
$stmt->execute([$seasonId]);
|
||||
$season = $stmt->fetch();
|
||||
|
||||
if ($season) {
|
||||
return $season;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Wenn keine Saison als aktuell markiert ist, nimm die mit der höchsten ID
|
||||
// Fallback: Wenn keine Saison in den Settings gefunden wird oder die ID ungültig 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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue