Files
Plenario/templates/Slides/form.php
T
gnilebeinandClaude Opus 5.5 1c509e31c2
CI / Deploy / test (push) Successful in 46s
CI / Deploy / deploy (push) Skipped
Add YouTube video slide type
Admins paste a YouTube link (watch, youtu.be, shorts, live, embed).
The link is checked via oEmbed on save and with a "check link" button
(not found / not embeddable is rejected, unreachable saves with a
warning). Start time can be entered or is taken from the link's
timecode; autoplay is optional. The presenter embeds the video via
youtube-nocookie.com; participants get the link plus a share button
(Web Share API, falls back to copying).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 15:08:12 +01:00

224 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Add / edit form for slides. Type specific fields are rendered per type;
* the type itself cannot be changed after creation.
*
* @var \App\View\AppView $this
* @var \App\Model\Entity\Poll $poll
* @var string $adminToken
* @var \App\Model\Entity\Slide $slide
* @var string $optionsText
* @var list<array{label: string, correct: bool}> $quizOptions
* @var bool|null $hasResponses
*/
use App\Service\YouTubeService;
$isNew = $slide->isNew();
$settings = $slide->getSettings();
$this->assign('title', $isNew ? __('Neue Folie') : __('Folie bearbeiten'));
$this->assign('noindex', '1');
$formUrl = $isNew
? ['_name' => 'slides:add', 'token' => $adminToken, '?' => ['type' => $slide->type]]
: ['_name' => 'slides:edit', 'token' => $adminToken, 'id' => $slide->id];
$optionsError = $slide->getError('options_text');
?>
<p><a href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>">← <?= __('Zurück zu „{0}“', h($poll->title)) ?></a></p>
<section class="card card--form">
<p class="eyebrow"><?= h($slide->typeLabel()) ?></p>
<h1><?= $isNew ? __('Neue Folie') : __('Folie bearbeiten') ?></h1>
<?= $this->Form->create($slide, ['url' => $formUrl]) ?>
<?= $this->Form->hidden('type') ?>
<?php if ($slide->isYouTube()) :
$urlError = $slide->getError('youtube_url');
$startError = $slide->getError('youtube_start');
$linkStart = YouTubeService::parseUrl((string)$settings['url'])['start'] ?? null;
// Leave the field empty when the start comes from the link, so a changed link wins.
$startValue = $this->getRequest()->is(['post', 'put', 'patch'])
? (string)$this->getRequest()->getData('settings.start', '')
: ((int)$settings['start'] > 0 && (int)$settings['start'] !== $linkStart ? YouTubeService::formatTime((int)$settings['start']) : '');
$previewUrl = $settings['video_id'] !== '' && !$urlError
? YouTubeService::embedUrl((string)$settings['video_id'], (int)$settings['start'])
: null;
?>
<div class="youtube-fields" data-youtube-form="<?= h($this->Url->build(['_name' => 'slides:youtube-check', 'token' => $adminToken])) ?>">
<div class="input text required<?= $urlError ? ' error' : '' ?>">
<label for="youtube-url"><?= __('YouTube-Link') ?></label>
<div class="copy-field">
<input type="text" inputmode="url" id="youtube-url" name="settings[url]" maxlength="500" required
autocomplete="off" spellcheck="false" <?= $isNew ? 'autofocus' : '' ?>
value="<?= h((string)$settings['url']) ?>"
placeholder="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
aria-describedby="youtube-url-hint youtube-status<?= $urlError ? ' youtube-url-error' : '' ?>"
<?= $urlError ? 'aria-invalid="true"' : '' ?> data-youtube-url>
<button type="button" class="button" data-youtube-check hidden><?= __('Link prüfen') ?></button>
</div>
<p class="hint" id="youtube-url-hint"><?= __('Links von youtube.com, youtu.be und Shorts funktionieren. Beim Speichern wird geprüft, ob das Video existiert und eingebettet werden darf.') ?></p>
<?php if ($urlError) : ?>
<div class="error-message" id="youtube-url-error"><?= h(implode(' ', (array)$urlError)) ?></div>
<?php endif; ?>
<p class="youtube-status" id="youtube-status" role="status" aria-live="polite" data-youtube-status></p>
</div>
<div class="youtube-preview" data-youtube-preview <?= $previewUrl ? '' : 'hidden' ?>>
<?php if ($previewUrl) : ?>
<iframe src="<?= h($previewUrl) ?>" title="<?= __('Vorschau des Videos') ?>" loading="lazy"
referrerpolicy="strict-origin" allow="encrypted-media; picture-in-picture; fullscreen" allowfullscreen></iframe>
<?php endif; ?>
</div>
<div class="input text<?= $startError ? ' error' : '' ?>">
<label for="youtube-start"><?= __('Start bei (Minute:Sekunde, optional)') ?></label>
<input type="text" id="youtube-start" name="settings[start]" class="input-short" maxlength="10"
inputmode="numeric" autocomplete="off" value="<?= h($startValue) ?>"
placeholder="<?= h($linkStart !== null ? YouTubeService::formatTime($linkStart) : '0:00') ?>"
aria-describedby="youtube-start-hint<?= $startError ? ' youtube-start-error' : '' ?>"
<?= $startError ? 'aria-invalid="true"' : '' ?> data-youtube-start>
<p class="hint" id="youtube-start-hint" data-youtube-start-hint><?= $linkStart !== null
? __('Leer lassen, um beim Zeitpunkt aus dem Link ({0}) zu starten.', YouTubeService::formatTime($linkStart))
: __('Z. B. 1:30 oder nur die Minute (2). Leer lassen, um am Anfang bzw. beim Zeitpunkt aus dem Link (…&t=90s) zu starten.') ?></p>
<?php if ($startError) : ?>
<div class="error-message" id="youtube-start-error"><?= h(implode(' ', (array)$startError)) ?></div>
<?php endif; ?>
</div>
<?= $this->Form->control('settings.autoplay', [
'type' => 'checkbox',
'label' => __('Automatisch abspielen, sobald die Folie in der Präsentation erscheint'),
'checked' => (bool)$settings['autoplay'],
]) ?>
<p class="hint"><?= __('Manche Browser spielen Videos mit Ton erst automatisch ab, nachdem du in der Präsentation einmal geklickt oder eine Taste gedrückt hast.') ?></p>
</div>
<?php endif; ?>
<?= $this->Form->control('question', [
'label' => match ($slide->type) {
'content' => __('Überschrift'),
'youtube' => __('Titel'),
default => __('Frage'),
},
'maxlength' => 500,
'required' => !$slide->isYouTube(),
'autofocus' => $isNew && !$slide->isYouTube(),
'placeholder' => $slide->isYouTube() ? __('Leer lassen, um den Titel des Videos zu übernehmen') : null,
'data-youtube-title' => $slide->isYouTube() ? '' : null,
]) ?>
<?= $this->Form->control('description', [
'type' => 'textarea',
'rows' => $slide->type === 'content' ? 6 : 2,
'label' => $slide->type === 'content' ? __('Text') : __('Beschreibung (optional)'),
]) ?>
<?php if ($slide->type === 'choice') : ?>
<div class="input textarea<?= $optionsError ? ' error' : '' ?>">
<label for="options-text"><?= __('Antwortoptionen (eine pro Zeile, max. 20)') ?></label>
<textarea id="options-text" name="options_text" rows="6" required><?= h($optionsText) ?></textarea>
<?php if ($optionsError) : ?>
<div class="error-message"><?= h(implode(' ', (array)$optionsError)) ?></div>
<?php endif; ?>
<?php if (!empty($hasResponses)) : ?>
<p class="hint"><?= __('Achtung: Entfernte oder umbenannte Optionen verlieren ihre bisherigen Stimmen.') ?></p>
<?php endif; ?>
</div>
<?= $this->Form->control('settings.multiple', [
'type' => 'checkbox',
'label' => __('Mehrfachauswahl erlauben'),
'checked' => (bool)$settings['multiple'],
]) ?>
<?php elseif ($slide->type === 'wordcloud') : ?>
<?= $this->Form->control('settings.allow_upvotes', [
'type' => 'checkbox',
'label' => __('Upvotes erlauben (Teilnehmende sehen die Wortwolke live und können Begriffe per Klick unterstützen)'),
'checked' => (bool)$settings['allow_upvotes'],
]) ?>
<?= $this->Form->control('settings.allow_downvotes', [
'type' => 'checkbox',
'label' => __('Downvotes erlauben (nur zusammen mit Upvotes: Teilnehmende können Begriffe anderer ablehnen)'),
'checked' => (bool)$settings['allow_downvotes'],
]) ?>
<?php elseif ($slide->type === 'scale') : ?>
<div class="grid grid--2 grid--tight">
<?= $this->Form->control('settings.scale_min', [
'type' => 'select', 'options' => [0 => '0', 1 => '1'],
'label' => __('Von'), 'value' => $settings['scale_min'],
]) ?>
<?= $this->Form->control('settings.scale_max', [
'type' => 'select', 'options' => array_combine(range(2, 10), range(2, 10)),
'label' => __('Bis'), 'value' => $settings['scale_max'],
]) ?>
<?= $this->Form->control('settings.min_label', [
'label' => __('Beschriftung links (optional)'), 'maxlength' => 60,
'placeholder' => __('z. B. gar nicht'), 'value' => $settings['min_label'],
]) ?>
<?= $this->Form->control('settings.max_label', [
'label' => __('Beschriftung rechts (optional)'), 'maxlength' => 60,
'placeholder' => __('z. B. sehr'), 'value' => $settings['max_label'],
]) ?>
</div>
<?php elseif ($slide->type === 'quiz') :
$quizError = $slide->getError('quiz_options');
$rows = $quizOptions;
// Always offer a few empty rows (more via "Antwort hinzufügen" with JS).
$rowCount = min(\App\Model\Table\SlidesTable::MAX_QUIZ_OPTIONS, max(4, count($rows) + 1));
$rows = array_pad($rows, $rowCount, ['label' => '', 'correct' => false]);
?>
<fieldset class="quiz-options<?= $quizError ? ' error' : '' ?>" data-quiz-options
data-max="<?= \App\Model\Table\SlidesTable::MAX_QUIZ_OPTIONS ?>"
<?= $quizError ? 'aria-describedby="quiz-options-error"' : '' ?>>
<legend><?= __('Antworten') ?></legend>
<p class="hint" id="quiz-options-hint"><?= __('Mindestens zwei Antworten, maximal {0}. Hake die richtige(n) an – Teilnehmende sehen erst nach dem Ende, was richtig war.', \App\Model\Table\SlidesTable::MAX_QUIZ_OPTIONS) ?></p>
<ol class="quiz-options__list" data-quiz-list>
<?php foreach ($rows as $i => $row) : ?>
<li class="quiz-option" data-quiz-row>
<label class="sr-only" for="quiz-option-<?= $i ?>"><?= __('Antwort {0}', $i + 1) ?></label>
<input type="text" id="quiz-option-<?= $i ?>" name="quiz_options[<?= $i ?>][label]"
value="<?= h($row['label']) ?>" maxlength="255"
placeholder="<?= __('Antwort {0}', $i + 1) ?>" <?= $i < 2 ? 'required' : '' ?>>
<label class="quiz-option__correct">
<input type="checkbox" name="quiz_options[<?= $i ?>][correct]" value="1" <?= $row['correct'] ? 'checked' : '' ?>>
<span><?= __('richtig') ?></span>
</label>
</li>
<?php endforeach; ?>
</ol>
<button type="button" class="button button--small" data-quiz-add hidden>+ <?= __('Antwort hinzufügen') ?></button>
<?php if ($quizError) : ?>
<div class="error-message" id="quiz-options-error"><?= h(implode(' ', (array)$quizError)) ?></div>
<?php endif; ?>
<?php if (!empty($hasResponses)) : ?>
<p class="hint"><?= __('Achtung: Entfernte oder umbenannte Antworten verlieren ihre bisherigen Stimmen.') ?></p>
<?php endif; ?>
</fieldset>
<?php
$limits = [];
foreach (\App\Model\Entity\Slide::QUIZ_TIME_LIMITS as $seconds) {
$limits[$seconds] = match (true) {
$seconds === 0 => __('Kein Zeitlimit – ich beende das Quiz selbst'),
$seconds < 60 => __('{0} Sekunden', $seconds),
$seconds % 60 === 0 => __n('{0} Minute', '{0} Minuten', intdiv($seconds, 60), intdiv($seconds, 60)),
default => __('{0} Minuten', number_format($seconds / 60, 1, ',', '')),
};
}
?>
<?= $this->Form->control('settings.time_limit', [
'type' => 'select',
'options' => $limits,
'label' => __('Zeitlimit'),
'value' => $settings['time_limit'],
]) ?>
<p class="hint"><?= __('Das Quiz startet erst, wenn du es in der Präsentation startest. Du kannst es jederzeit vorzeitig beenden.') ?></p>
<?php endif; ?>
<?php if ($slide->isInteractive() && !$slide->isQuiz()) : ?>
<?= $this->Form->control('is_voting_open', [
'type' => 'checkbox',
'label' => __('Abstimmung geöffnet'),
'checked' => $isNew ? true : $slide->is_voting_open,
]) ?>
<?php endif; ?>
<div class="form-actions">
<?= $this->Form->button($isNew ? __('Folie anlegen') : __('Speichern'), ['class' => 'button button--primary']) ?>
<a class="button button--ghost" href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>"><?= __('Abbrechen') ?></a>
</div>
<?= $this->Form->end() ?>
</section>