feat: Implementiere Quoten- und Einsatzverwaltung für Saisons

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-04 18:14:46 +02:00
parent d571121200
commit 362966e0cd
4 changed files with 77 additions and 28 deletions

View file

@ -15,6 +15,7 @@ use App\Models\Round;
use App\Models\Season;
use App\Models\Ranking;
use App\Models\Payment;
use App\Models\Quota;
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$page = $_GET['page'] ?? null;
@ -122,14 +123,18 @@ if ($page === 'login') {
$data = [
'name' => $_POST['name'],
'rounds' => $_POST['rounds'],
'stake' => $_POST['stake'],
];
if (empty($data['name']) || !is_numeric($data['rounds'])) {
throw new \Exception('Name und Anzahl der Runden sind erforderlich.');
if (empty($data['name']) || !is_numeric($data['rounds']) || !is_numeric($data['stake'])) {
throw new \Exception('Name, Runden und Einsatz sind erforderlich.');
}
if ($action === 'create') {
$newSeasonId = Season::create($data);
if ($newSeasonId) {
if (isset($_POST['quotas'])) {
Quota::updateForSeason($newSeasonId, $_POST['quotas']);
}
Season::setCurrent($newSeasonId);
$_SESSION['admin_message'] = "Saison erfolgreich erstellt und als aktiv gesetzt.";
} else {
@ -138,12 +143,8 @@ if ($page === 'login') {
} 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);
}
}
if (isset($_POST['quotas'])) {
Quota::updateForSeason($seasonId, $_POST['quotas']);
}
$_SESSION['admin_message'] = "Saison erfolgreich aktualisiert.";
@ -175,11 +176,11 @@ if ($page === 'login') {
$seasons = Season::getAll();
$currentSeason = Season::getCurrent();
$editSeason = null;
$roundsOfSeason = [];
$quotasOfSeason = [];
if (isset($_GET['edit_id'])) {
$editSeason = Season::findById((int)$_GET['edit_id']);
if ($editSeason) {
$roundsOfSeason = Round::getBySeason($editSeason['id']);
$quotasOfSeason = Quota::getBySeason($editSeason['id']);
}
}

View file

@ -63,6 +63,7 @@ CREATE TABLE `seasons` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
`rounds` int(11) NOT NULL DEFAULT '36',
`stake` decimal(8,2) NOT NULL DEFAULT '25.00',
`active` tinyint(1) NOT NULL DEFAULT '1',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,

View file

@ -75,11 +75,12 @@ class Season {
try {
$stmt = $db->prepare(
"INSERT INTO seasons (name, rounds, created_at, updated_at) VALUES (:name, :rounds, NOW(), NOW())"
"INSERT INTO seasons (name, rounds, stake, created_at, updated_at) VALUES (:name, :rounds, :stake, NOW(), NOW())"
);
$stmt->execute([
':name' => $data['name'],
':rounds' => $data['rounds'],
':stake' => $data['stake'],
]);
$seasonId = $db->lastInsertId();
@ -110,12 +111,13 @@ class Season {
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"
"UPDATE seasons SET name = :name, rounds = :rounds, stake = :stake, updated_at = NOW() WHERE id = :id"
);
return $stmt->execute([
':id' => $id,
':name' => $data['name'],
':rounds' => $data['rounds'],
':stake' => $data['stake'],
]);
}

View file

@ -28,26 +28,39 @@ 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'); ?>" <?php echo $editSeason ? 'readonly' : 'required' ?>>
<input type="number" id="rounds" name="rounds" value="<?php echo htmlspecialchars($editSeason['rounds'] ?? '34'); ?>" required>
</div>
<div class="form-group">
<label for="stake">Einsatz (€):</label>
<input type="number" step="0.01" id="stake" name="stake" value="<?php echo htmlspecialchars($editSeason['stake'] ?? '25.00'); ?>" 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; ?>
<h2>Quoten</h2>
<div id="quotas-container">
<?php
$quotas = $quotasOfSeason ?? [];
if ($editSeason === null && empty($quotasOfSeason)) {
$quotas = [
['name' => '1. Platz', 'prc' => '50'],
['name' => '2. Platz', 'prc' => '30'],
['name' => '3. Platz', 'prc' => '20'],
];
}
foreach ($quotas as $index => $quota): ?>
<div class="form-group quota-item">
<label>Quote <?php echo $index + 1; ?>:</label>
<input type="text" name="quotas[<?php echo $index; ?>][name]" value="<?php echo htmlspecialchars($quota['name'] ?? ''); ?>" placeholder="z.B. 1. Platz" style="width: 200px; margin-right: 10px;">
<input type="number" step="0.01" name="quotas[<?php echo $index; ?>][prc]" value="<?php echo htmlspecialchars($quota['prc'] ?? ''); ?>" placeholder="Anteil in %" style="width: 120px;">
<button type="button" class="remove-quota" style="margin-left: 10px;">Entfernen</button>
</div>
<?php endforeach; ?>
</div>
<div class="form-group">
<button type="button" id="add-quota">Quote hinzufügen</button>
</div>
<div class="form-group">
<button type="submit"><?php echo $editSeason ? 'Speichern' : 'Anlegen'; ?></button>
<?php if ($editSeason): ?>
@ -56,6 +69,38 @@ require __DIR__ . '/../partials/header.php';
</div>
</form>
<script>
document.addEventListener('DOMContentLoaded', function() {
let quotaIndex = <?php echo count($quotas ?? []); ?>;
document.getElementById('add-quota').addEventListener('click', function() {
const container = document.getElementById('quotas-container');
const newItem = document.createElement('div');
newItem.className = 'form-group quota-item';
const newIndex = container.getElementsByClassName('quota-item').length;
newItem.innerHTML = `
<label>Quote ${newIndex + 1}:</label>
<input type="text" name="quotas[${newIndex}][name]" placeholder="z.B. Tagessieger" style="width: 200px; margin-right: 10px;">
<input type="number" step="0.01" name="quotas[${newIndex}][prc]" placeholder="Anteil in %" style="width: 120px;">
<button type="button" class="remove-quota" style="margin-left: 10px;">Entfernen</button>
`;
container.appendChild(newItem);
});
document.getElementById('quotas-container').addEventListener('click', function(e) {
if (e.target && e.target.classList.contains('remove-quota')) {
e.target.closest('.quota-item').remove();
const container = document.getElementById('quotas-container');
const items = container.querySelectorAll('.quota-item');
items.forEach((item, index) => {
item.querySelector('label').textContent = `Quote ${index + 1}:`;
});
}
});
});
</script>
<hr>
<!-- Season List -->