Erster Durchstich mit updates

This commit is contained in:
torsten 2026-10-17 17:21:33 +02:00
parent d3fd60b548
commit 3331f08091
60 changed files with 693 additions and 195 deletions

View file

@ -1,126 +0,0 @@
<?php
namespace App\Models;
use App\Core\Database;
class Round {
/**
* Holt eine Runde anhand der ID
*/
public static function getById($id) {
$db = Database::getConnection();
$stmt = $db->prepare("SELECT * FROM rounds WHERE id = ?");
$stmt->execute([$id]);
return $stmt->fetch();
}
/**
* Holt alle Runden einer Season
*/
public static function getBySeason($seasonId) {
$db = Database::getConnection();
$stmt = $db->prepare("SELECT * FROM rounds WHERE season_id = ? ORDER BY id ASC");
$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]);
}
/**
* Speichert den Rundenbericht. Zeilenumbrüche werden wie im Legacy als <br/> gespeichert.
*
* @param int $id
* @param string $report Klartext mit Zeilenumbrüchen
* @return bool
*/
public static function updateReport($id, $report) {
$report = str_replace(["\r\n", "\r", "\n"], "<br/>", trim($report));
$db = Database::getConnection();
$stmt = $db->prepare("UPDATE rounds SET report = ?, updated_at = NOW() WHERE id = ?");
return $stmt->execute([$report, $id]);
}
/**
* Rundenbericht als Klartext für Formulare (Gegenstück zu updateReport).
*
* @param string|null $report
* @return string
*/
public static function reportToText($report) {
return str_replace(["<br/>", "<br>", "<br />"], "\n", (string)$report);
}
/**
* Sperrzeitpunkt der Runde: 1 Minute vor dem frühesten Anstoß (Legacy Round::getLockTime).
*
* @param array $games Spiele der Runde
* @return \DateTime|null
*/
public static function getLockTime(array $games) {
if (empty($games)) {
return null;
}
$earliest = min(array_column($games, 'kickoff'));
return (new \DateTime($earliest))->modify('-1 minute');
}
/**
* Eine Runde ist abgeschlossen, wenn alle Spiele ein Ergebnis haben (Legacy Round::isCompleted).
*
* @param array $games Spiele der Runde
* @return bool
*/
public static function isCompleted(array $games) {
foreach ($games as $game) {
if ((int)$game['score1'] < 0 || (int)$game['score2'] < 0) {
return false;
}
}
return true;
}
/**
* Eine Runde ist gesperrt, sobald eines ihrer Spiele gesperrt ist (Legacy Round::hasLockedGame).
*
* @param array $games Spiele der Runde
* @return bool
*/
public static function isLocked(array $games) {
foreach ($games as $game) {
if (Game::isLocked($game['kickoff'])) {
return true;
}
}
return false;
}
/**
* Erste Runde der Saison, in der noch kein Spiel gesperrt ist (Legacy Round::getFirstTippableRound).
*
* @param int $seasonId
* @return array|null Runde inkl. 'games'
*/
public static function getFirstTippable($seasonId) {
foreach (self::getBySeason($seasonId) as $round) {
$games = Game::getGamesByRound($round['id']);
if (!self::isLocked($games)) {
$round['games'] = $games;
return $round;
}
}
return null;
}
}