This commit is contained in:
torsten 2026-10-20 17:56:44 +02:00
parent 565c5c43f9
commit ab2311587c
12 changed files with 241 additions and 27 deletions

View file

@ -9,6 +9,9 @@ class Season {
/** Legacy-Default für seasons.max_identical_jokertipps */
const DEFAULT_MAX_IDENTICAL_JOKERTIPPS = 6;
/** Default für seasons.jackpot (in Euro) */
const DEFAULT_JACKPOT = 0;
/** Jede Runde besteht aus 4 Spielen (Legacy-Konvention) */
const GAMES_PER_ROUND = 4;
@ -67,25 +70,29 @@ class Season {
*
* Tipps werden NICHT vorab angelegt - sie entstehen beim ersten Tippen (siehe Tipp::saveRound).
*
* @param array $data ['name', 'rounds', optional 'max_identical_jokertipps']
* @param array $data ['name', 'rounds', optional 'max_identical_jokertipps', 'jackpot']
* @return int|false Die ID der neuen Saison oder false bei einem Fehler.
*/
public static function create($data) {
$db = Database::getConnection();
$roundCount = (int)$data['rounds'];
$maxJoker = (int)($data['max_identical_jokertipps'] ?? self::DEFAULT_MAX_IDENTICAL_JOKERTIPPS);
$jackpot = isset($data['jackpot']) && is_numeric($data['jackpot'])
? (float)$data['jackpot']
: self::DEFAULT_JACKPOT;
$db->beginTransaction();
try {
$stmt = $db->prepare(
"INSERT INTO seasons (name, rounds, max_identical_jokertipps, created_at, updated_at)
VALUES (:name, :rounds, :max_joker, NOW(), NOW())"
"INSERT INTO seasons (name, rounds, max_identical_jokertipps, jackpot, created_at, updated_at)
VALUES (:name, :rounds, :max_joker, :jackpot, NOW(), NOW())"
);
$stmt->execute([
':name' => $data['name'],
':rounds' => $roundCount,
':max_joker' => $maxJoker,
':jackpot' => $jackpot,
]);
$seasonId = (int)$db->lastInsertId();
@ -128,7 +135,7 @@ class Season {
* Hinweis: Eine Änderung von 'rounds' legt keine Runden an oder löscht welche.
*
* @param int $id
* @param array $data ['name', 'rounds', optional 'max_identical_jokertipps']
* @param array $data ['name', 'rounds', optional 'max_identical_jokertipps', 'jackpot']
* @return bool
*/
public static function update($id, $data) {
@ -146,6 +153,11 @@ class Season {
$params[':max_joker'] = (int)$data['max_identical_jokertipps'];
}
if (isset($data['jackpot'])) {
$sql .= ", jackpot = :jackpot";
$params[':jackpot'] = (float)$data['jackpot'];
}
$sql .= " WHERE id = :id";
$stmt = $db->prepare($sql);
return $stmt->execute($params);
@ -153,7 +165,7 @@ class Season {
/**
* Löscht eine Saison mit allen abhängigen Daten (Tipps, Spiele, Runden,
* Quoten, Zahlungen, manuelle Ausschüttungen). Die aktive Saison kann nicht gelöscht werden.
* Quoten, Zahlungen, manuelle Ausschüttungen, Rundmails). Die aktive Saison kann nicht gelöscht werden.
*
* @param int $id
* @throws \Exception wenn die Saison aktiv ist oder nicht existiert
@ -178,6 +190,7 @@ class Season {
"DELETE FROM quotas WHERE season_id = ?",
"DELETE FROM payments WHERE season_id = ?",
"DELETE FROM manual_payouts WHERE season_id = ?",
"DELETE FROM roundmails WHERE season_id = ?",
"DELETE FROM seasons WHERE id = ?",
];
foreach ($statements as $sql) {