Store Display: Bilddauer mit Nachkommastelle (1,5 Sekunden)

Das Feld „Dauer (Sekunden)“ im b2in-Display nimmt Komma und Punkt an,
erlaubt 0,5 bis 120 Sekunden und speichert eine Zahl; der Player rechnet
unverändert mal 1000. Anzeige in der Liste mit Komma. Nachtrag 14.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-09-17 09:52:33 +00:00
parent 90aa079cf7
commit 3211569fee
9 changed files with 354 additions and 8 deletions

View file

@ -53,7 +53,8 @@ class DisplayVersionEditor extends Component
public string $mediaSubline = '';
public int $mediaDuration = 10;
/** Anzeigedauer eines Bildes in Sekunden als Eingabetext, Komma oder Punkt erlaubt („1,5“). */
public string $mediaDuration = '10';
public bool $mediaIsActive = true;
@ -247,6 +248,12 @@ class DisplayVersionEditor extends Component
public function saveItem(): void
{
if ($this->itemType === 'media' && $this->mediaType === 'image' && self::parseDuration($this->mediaDuration) === null) {
$this->addError('mediaDuration', 'Bitte eine Dauer zwischen 0,5 und 120 Sekunden angeben, z. B. 1,5.');
return;
}
$content = $this->buildItemContent();
$isActive = $this->getActiveFlag();
@ -279,6 +286,41 @@ class DisplayVersionEditor extends Component
$this->refreshModulePreview();
}
/**
* Sekunden aus der Eingabe lesen: „1,5“, „1.5“ und „10“ sind gültig, gerundet auf Zehntel.
* Erlaubt sind 0,5 bis 120 Sekunden; alles andere ergibt null.
*/
public static function parseDuration(string|int|float $input): ?float
{
$normalized = str_replace(',', '.', trim((string) $input));
if ($normalized === '' || ! is_numeric($normalized)) {
return null;
}
$seconds = round((float) $normalized, 1);
if ($seconds < 0.5 || $seconds > 120) {
return null;
}
return $seconds;
}
/**
* Sekunden für die Anzeige: ganze Zahlen ohne Nachkommastelle, sonst mit Komma („1,5“).
*/
public static function formatDuration(int|float|string|null $seconds): string
{
$seconds = (float) str_replace(',', '.', (string) ($seconds ?? 10));
if (floor($seconds) === $seconds) {
return (string) (int) $seconds;
}
return str_replace('.', ',', (string) round($seconds, 1));
}
public function deleteItem(int $id): void
{
DisplayVersionItem::findOrFail($id)->delete();
@ -437,7 +479,7 @@ class DisplayVersionEditor extends Component
$this->mediaUrl = $content['media_url'] ?? '';
$this->mediaHeadline = $content['headline'] ?? '';
$this->mediaSubline = $content['subline'] ?? '';
$this->mediaDuration = $content['duration_seconds'] ?? 10;
$this->mediaDuration = self::formatDuration($content['duration_seconds'] ?? 10);
$this->mediaIsActive = $isActive;
}
@ -501,7 +543,7 @@ class DisplayVersionEditor extends Component
'media_url' => $this->mediaUrl,
'headline' => $this->mediaHeadline,
'subline' => $this->mediaSubline,
'duration_seconds' => $this->mediaDuration,
'duration_seconds' => self::parseDuration($this->mediaDuration) ?? 10,
],
'slide' => [
'type' => 'detail',
@ -663,7 +705,7 @@ class DisplayVersionEditor extends Component
$this->mediaUrl = '';
$this->mediaHeadline = '';
$this->mediaSubline = '';
$this->mediaDuration = 10;
$this->mediaDuration = '10';
$this->mediaIsActive = true;
$this->slideShowLogo = true;
$this->slideLogoUrl = '';