2026-10-03 16:49:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Core\Database;
|
|
|
|
|
|
|
|
|
|
class Season {
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-03 16:57:45 +02:00
|
|
|
* Holt die aktuell selektierte Saison aus den `settings`.
|
|
|
|
|
* Annahme: Es gibt eine Tabelle `settings` mit dem Feld `current_season_id`.
|
2026-10-03 16:49:52 +02:00
|
|
|
* Fallback: Die Saison mit der höchsten ID.
|
|
|
|
|
*/
|
|
|
|
|
public static function getCurrent() {
|
|
|
|
|
$db = Database::getConnection();
|
|
|
|
|
|
2026-10-03 16:57:45 +02:00
|
|
|
// Lese die current_season_id aus der settings Tabelle
|
|
|
|
|
$stmt = $db->prepare("SELECT current_season_id FROM settings LIMIT 1");
|
2026-10-03 16:51:44 +02:00
|
|
|
$stmt->execute();
|
2026-10-03 16:57:45 +02:00
|
|
|
$setting = $stmt->fetch();
|
2026-10-03 16:51:44 +02:00
|
|
|
|
2026-10-03 16:57:45 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2026-10-03 16:49:52 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-03 16:57:45 +02:00
|
|
|
// Fallback: Wenn keine Saison in den Settings gefunden wird oder die ID ungültig ist, nimm die mit der höchsten ID
|
2026-10-03 16:51:44 +02:00
|
|
|
$stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC LIMIT 1");
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
return $stmt->fetch();
|
2026-10-03 16:49:52 +02:00
|
|
|
}
|
|
|
|
|
}
|