This commit is contained in:
torsten 2026-10-27 09:38:05 +01:00
parent a82d14c168
commit 0f749fb348
9 changed files with 394 additions and 12 deletions

View file

@ -123,4 +123,57 @@ class Round {
}
return null;
}
/** Ab dieser Restzeit erscheint der Hinweis auf der Startseite (Legacy: 49 Stunden). */
const LOCK_WARNING_HOURS = 49;
/**
* Hinweis für die Startseite: fehlende Tipps/Joker und Sperrzeitpunkt der
* nächsten tippbaren Runde (Legacy: UsersController::main und User::hasMissing*).
*
* @param int $seasonId
* @param int $userId
* @return array|null Null, wenn kein Hinweis angezeigt werden soll
*/
public static function getLockWarning($seasonId, $userId) {
$round = self::getFirstTippable($seasonId);
if (!$round || empty($round['games'])) {
return null;
}
$lockTime = self::getLockTime($round['games']);
if (!$lockTime) {
return null;
}
$secondsLeft = $lockTime->getTimestamp() - time();
if ($secondsLeft <= 0 || $secondsLeft >= self::LOCK_WARNING_HOURS * 3600) {
return null;
}
$missing = Tipp::getMissing((int)$round['id'], [(int)$userId]);
return [
'name' => (string)$round['name'],
'lock_time' => $lockTime,
'remaining' => self::formatRemainingTime($secondsLeft),
'missing_tipps' => in_array((int)$userId, $missing['tipps'], true),
'missing_joker' => in_array((int)$userId, $missing['joker'], true),
];
}
/**
* Formatiert die Restzeit wie im Legacy ("8 Stunden", "12 Minuten").
*
* @param int $seconds
* @return string
*/
private static function formatRemainingTime($seconds) {
if ($seconds >= 3600) {
$hours = (int)floor($seconds / 3600);
return $hours . ' ' . ($hours === 1 ? 'Stunde' : 'Stunden');
}
$minutes = max(1, (int)floor($seconds / 60));
return $minutes . ' ' . ($minutes === 1 ? 'Minute' : 'Minuten');
}
}