feat: Saisons-Verwaltung im Admin-Bereich implementieren und Menü anpassen
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
374b8fed6e
commit
55e03541ff
4 changed files with 245 additions and 1 deletions
|
|
@ -37,4 +37,86 @@ class Season {
|
|||
$stmt->execute();
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Saisons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAll() {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC");
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt eine Saison anhand der ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|false
|
||||
*/
|
||||
public static function findById($id) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM seasons WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt eine neue Saison.
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public static function create($data) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO seasons (name, rounds, created_at, updated_at) VALUES (:name, :rounds, NOW(), NOW())"
|
||||
);
|
||||
return $stmt->execute([
|
||||
':name' => $data['name'],
|
||||
':rounds' => $data['rounds'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert eine Saison.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public static function update($id, $data) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE seasons SET name = :name, rounds = :rounds, updated_at = NOW() WHERE id = :id"
|
||||
);
|
||||
return $stmt->execute([
|
||||
':id' => $id,
|
||||
':name' => $data['name'],
|
||||
':rounds' => $data['rounds'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die aktive Saison in der `settings`-Tabelle.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function setCurrent($id) {
|
||||
$db = Database::getConnection();
|
||||
// Annahme: Es gibt immer genau einen Eintrag in settings
|
||||
$stmt = $db->prepare("UPDATE settings SET current_season_id = ? WHERE id = 1");
|
||||
if (!$stmt->execute([$id])) {
|
||||
return false;
|
||||
}
|
||||
// Wenn die Zeile nicht existiert, füge sie ein.
|
||||
if ($stmt->rowCount() === 0) {
|
||||
$stmt = $db->prepare("INSERT INTO settings (id, current_season_id) VALUES (1, ?)");
|
||||
return $stmt->execute([$id]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue