fix: Füge fehlende Quota Model-Klasse hinzu
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
43f97b96f2
commit
44e26eeefd
1 changed files with 54 additions and 0 deletions
54
src/Models/Quota.php
Normal file
54
src/Models/Quota.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Core\Database;
|
||||
|
||||
class Quota {
|
||||
/**
|
||||
* Holt alle Quoten für eine Saison.
|
||||
* @param int $seasonId
|
||||
* @return array
|
||||
*/
|
||||
public static function getBySeason($seasonId) {
|
||||
$db = Database::getConnection();
|
||||
$stmt = $db->prepare("SELECT * FROM quotas WHERE season_id = ? ORDER BY `order` ASC, id ASC");
|
||||
$stmt->execute([$seasonId]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert die Quoten für eine Saison.
|
||||
* Löscht bestehende und fügt die neuen ein.
|
||||
* @param int $seasonId
|
||||
* @param array $quotasData
|
||||
* @return bool
|
||||
*/
|
||||
public static function updateForSeason($seasonId, $quotasData) {
|
||||
$db = Database::getConnection();
|
||||
$db->beginTransaction();
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("DELETE FROM quotas WHERE season_id = ?");
|
||||
$stmt->execute([$seasonId]);
|
||||
|
||||
$order = 0;
|
||||
if (is_array($quotasData)) {
|
||||
foreach ($quotasData as $quota) {
|
||||
if (!empty($quota['name']) && isset($quota['prc']) && is_numeric($quota['prc'])) {
|
||||
$stmt_insert = $db->prepare(
|
||||
"INSERT INTO quotas (season_id, name, `order`, prc, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())"
|
||||
);
|
||||
$stmt_insert->execute([$seasonId, $quota['name'], $order++, (float)$quota['prc']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$db->rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue