feat: Saisons um Runden-Verwaltung erweitern

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-04 18:02:53 +02:00
parent 55e03541ff
commit f852da3570
4 changed files with 73 additions and 9 deletions

View file

@ -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';

View file

@ -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]);
}
}

View file

@ -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;
}
}
/**

View file

@ -28,8 +28,26 @@ require __DIR__ . '/../partials/header.php';
</div>
<div class="form-group">
<label for="rounds">Runden:</label>
<input type="number" id="rounds" name="rounds" value="<?php echo htmlspecialchars($editSeason['rounds'] ?? '34'); ?>" required>
<input type="number" id="rounds" name="rounds" value="<?php echo htmlspecialchars($editSeason['rounds'] ?? '34'); ?>" <?php echo $editSeason ? 'readonly' : 'required' ?>>
</div>
<?php if ($editSeason && !empty($roundsOfSeason)): ?>
<hr style="margin: 2rem 0;">
<h2>Runden dieser Saison</h2>
<?php foreach ($roundsOfSeason as $round): ?>
<div class="form-group">
<label for="round_<?php echo $round['id']; ?>">
Runde <?php echo htmlspecialchars(preg_replace('/[^0-9]/', '', $round['name'])); ?>:
</label>
<input type="text"
id="round_<?php echo $round['id']; ?>"
name="rounds_names[<?php echo $round['id']; ?>]"
value="<?php echo htmlspecialchars($round['name']); ?>"
required>
</div>
<?php endforeach; ?>
<?php endif; ?>
<div class="form-group">
<button type="submit"><?php echo $editSeason ? 'Speichern' : 'Anlegen'; ?></button>
<?php if ($editSeason): ?>