Display-Seiten: Betriebszeiten, PIN, Gerätesperre, Sprache und Vorschau
All checks were successful
CI / PHP Lint (push) Successful in 34s
CI / PHP Lint-1 (push) Successful in 39s
CI / Unit Tests & Static Analysis (push) Successful in 38s
CI / PHP Lint (pull_request) Successful in 41s
CI / PHP Lint-1 (pull_request) Successful in 49s
CI / Unit Tests & Static Analysis (pull_request) Successful in 41s
All checks were successful
CI / PHP Lint (push) Successful in 34s
CI / PHP Lint-1 (push) Successful in 39s
CI / Unit Tests & Static Analysis (push) Successful in 38s
CI / PHP Lint (pull_request) Successful in 41s
CI / PHP Lint-1 (pull_request) Successful in 49s
CI / Unit Tests & Static Analysis (pull_request) Successful in 41s
Die Display-Seiten hängen an öffentlichen Links, deshalb bekommen sie Regler, mit denen sich der Missbrauch begrenzen lässt, und ein paar Komfortfunktionen für den Betrieb: - Betriebszeiten je Seite (auch über Mitternacht hinweg); außerhalb zeigt die Seite einen Hinweis statt des Buttons - Optionale PIN von der Rezeption, geprüft mit hash_equals - Wartezeit je Gerät über ein Cookie, zusätzlich zum globalen Cooldown - Feste Sprache je Seite, sonst Browsersprache; Gäste können unten umschalten - Reporting zeigt die Ausgabe pro Display-Seite - Vorschau der Seite direkt in der Administration - Backup exportiert und importiert die neuen Felder mit Migration 0007, 16 neue Sprachschlüssel, 7 zusätzliche Tests (69 Tests, 152 Assertions). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
88f40a3d21
commit
dd8e805e27
28 changed files with 478 additions and 26 deletions
|
|
@ -67,14 +67,87 @@ class Kiosk
|
|||
return (int)($row['c'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Liegt der aktuelle Zeitpunkt im Betriebsfenster der Display-Seite?
|
||||
* Ohne gesetzte Zeiten gilt: immer offen. Ein Fenster über Mitternacht
|
||||
* (z. B. 18:00–02:00) wird unterstützt.
|
||||
*/
|
||||
public static function withinSchedule(array $kiosk, ?int $now = null): bool
|
||||
{
|
||||
$from = trim((string)($kiosk['active_from'] ?? ''));
|
||||
$to = trim((string)($kiosk['active_to'] ?? ''));
|
||||
if ($from === '' || $to === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$now = $now ?? time();
|
||||
$minutes = (int)date('G', $now) * 60 + (int)date('i', $now);
|
||||
$start = self::toMinutes($from);
|
||||
$end = self::toMinutes($to);
|
||||
|
||||
if ($start === $end) {
|
||||
return true; // 24 Stunden
|
||||
}
|
||||
if ($start < $end) {
|
||||
return $minutes >= $start && $minutes < $end;
|
||||
}
|
||||
|
||||
return $minutes >= $start || $minutes < $end; // über Mitternacht
|
||||
}
|
||||
|
||||
private static function toMinutes(string $time): int
|
||||
{
|
||||
$parts = explode(':', $time);
|
||||
|
||||
return ((int)($parts[0] ?? 0)) * 60 + ((int)($parts[1] ?? 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wartezeit dieses Geräts: das Display merkt sich den letzten Bezug in
|
||||
* einem Cookie. Verhindert, dass eine Person am Handy im Takt der
|
||||
* globalen Wartezeit das Tageskontingent leerzieht.
|
||||
*
|
||||
* @param int|null $lastSeen Zeitstempel aus dem Cookie
|
||||
* @return int verbleibende Sekunden (0 = frei)
|
||||
*/
|
||||
public static function deviceCooldownLeft(array $kiosk, ?int $lastSeen, ?int $now = null): int
|
||||
{
|
||||
$cooldown = max(0, (int)($kiosk['device_cooldown_seconds'] ?? 0));
|
||||
if ($cooldown === 0 || !$lastSeen) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$elapsed = ($now ?? time()) - $lastSeen;
|
||||
if ($elapsed < 0 || $elapsed >= $cooldown) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $cooldown - $elapsed;
|
||||
}
|
||||
|
||||
/** Stimmt die eingegebene PIN? Ohne hinterlegte PIN entfällt die Prüfung. */
|
||||
public static function pinMatches(array $kiosk, ?string $input): bool
|
||||
{
|
||||
$pin = trim((string)($kiosk['pin'] ?? ''));
|
||||
if ($pin === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return hash_equals($pin, trim((string)$input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Darf gerade ein Code geholt werden?
|
||||
*
|
||||
* @return array{allowed:bool,reason:string,wait:int}
|
||||
* reason: '' | 'cooldown' | 'daily_limit'
|
||||
* reason: '' | 'closed' | 'cooldown' | 'daily_limit'
|
||||
*/
|
||||
public static function checkLimits($db, array $kiosk): array
|
||||
{
|
||||
if (!self::withinSchedule($kiosk)) {
|
||||
return ['allowed' => false, 'reason' => 'closed', 'wait' => 0];
|
||||
}
|
||||
|
||||
$cooldown = max(0, (int)$kiosk['cooldown_seconds']);
|
||||
if ($cooldown > 0 && !empty($kiosk['last_used_at'])) {
|
||||
$elapsed = time() - strtotime((string)$kiosk['last_used_at']);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue