From f852da3570d32b00230b305f081441aa4ccd038a Mon Sep 17 00:00:00 2001 From: torsten Date: Sun, 4 Oct 2026 18:02:53 +0200 Subject: [PATCH] feat: Saisons um Runden-Verwaltung erweitern Co-authored-by: aider (gemini/gemini-2.5-pro) --- public/index.php | 13 +++++++++++++ src/Models/Round.php | 13 +++++++++++++ src/Models/Season.php | 36 ++++++++++++++++++++++++++++-------- src/Views/admin/seasons.php | 20 +++++++++++++++++++- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/public/index.php b/public/index.php index e201160..f85b944 100644 --- a/public/index.php +++ b/public/index.php @@ -132,6 +132,15 @@ if ($page === 'login') { $_SESSION['admin_message'] = "Saison erfolgreich erstellt."; } elseif ($seasonId) { Season::update($seasonId, $data); + + if (isset($_POST['rounds_names']) && is_array($_POST['rounds_names'])) { + foreach ($_POST['rounds_names'] as $roundId => $roundName) { + if (!empty($roundName)) { + Round::updateName($roundId, $roundName); + } + } + } + $_SESSION['admin_message'] = "Saison erfolgreich aktualisiert."; } } elseif ($action === 'set_current' && $seasonId) { @@ -161,8 +170,12 @@ if ($page === 'login') { $seasons = Season::getAll(); $currentSeason = Season::getCurrent(); $editSeason = null; + $roundsOfSeason = []; if (isset($_GET['edit_id'])) { $editSeason = Season::findById((int)$_GET['edit_id']); + if ($editSeason) { + $roundsOfSeason = Round::getBySeason($editSeason['id']); + } } require __DIR__ . '/../src/Views/admin/seasons.php'; diff --git a/src/Models/Round.php b/src/Models/Round.php index 016c4c7..3e2c124 100644 --- a/src/Models/Round.php +++ b/src/Models/Round.php @@ -25,4 +25,17 @@ class Round { $stmt->execute([$seasonId]); return $stmt->fetchAll(); } + + /** + * Aktualisiert den Namen einer Runde. + * + * @param int $id + * @param string $name + * @return bool + */ + public static function updateName($id, $name) { + $db = Database::getConnection(); + $stmt = $db->prepare("UPDATE rounds SET name = ?, updated_at = NOW() WHERE id = ?"); + return $stmt->execute([$name, $id]); + } } diff --git a/src/Models/Season.php b/src/Models/Season.php index 87c2440..aef415e 100644 --- a/src/Models/Season.php +++ b/src/Models/Season.php @@ -64,20 +64,40 @@ class Season { } /** - * Erstellt eine neue Saison. + * Erstellt eine neue Saison und die zugehörigen Runden. * * @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'], - ]); + $db->beginTransaction(); + + try { + $stmt = $db->prepare( + "INSERT INTO seasons (name, rounds, created_at, updated_at) VALUES (:name, :rounds, NOW(), NOW())" + ); + $stmt->execute([ + ':name' => $data['name'], + ':rounds' => $data['rounds'], + ]); + $seasonId = $db->lastInsertId(); + + for ($i = 1; $i <= $data['rounds']; $i++) { + $roundName = $i . ". Spieltag"; + $stmt_round = $db->prepare( + "INSERT INTO rounds (name, season_id, created_at, updated_at) VALUES (?, ?, NOW(), NOW())" + ); + $stmt_round->execute([$roundName, $seasonId]); + } + + $db->commit(); + return true; + + } catch (\Exception $e) { + $db->rollBack(); + return false; + } } /** diff --git a/src/Views/admin/seasons.php b/src/Views/admin/seasons.php index d2ede54..a3c70e7 100644 --- a/src/Views/admin/seasons.php +++ b/src/Views/admin/seasons.php @@ -28,8 +28,26 @@ require __DIR__ . '/../partials/header.php';
- + >
+ + +
+

Runden dieser Saison

+ +
+ + +
+ + +