feat: Saisons um Runden-Verwaltung erweitern
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
55e03541ff
commit
f852da3570
4 changed files with 73 additions and 9 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue