Files
Plenario/templates/Slides/form.php
T
gnilebein c6567b5e28
CI / Deploy / test (push) Successful in 55s
CI / Deploy / deploy (push) Successful in 7s
Merge pull request 'Drop the comment interval setting' (#40) from feature/comment-auto-interval into main
Reviewed-on: #40
2026-11-09 14:25:07 +01:00

317 lines
21 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 list<string> $orderOptions Ordering slide: labels in the correct order
* @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'),
'qa' => __('Überschrift'),
default => __('Frage'),
},
'maxlength' => 500,
'required' => !$slide->isYouTube(),
'autofocus' => $isNew && !$slide->isYouTube(),
'placeholder' => match (true) {
$slide->isYouTube() => __('Leer lassen, um den Titel des Videos zu übernehmen'),
$slide->isQa() => __('z. B. Eure Fragen an den Vorstand'),
default => 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 === 'open') : ?>
<?= $this->Form->control('settings.private', [
'type' => 'checkbox',
'label' => __('Anonymes Feedback: Antworten nicht öffentlich anzeigen'),
'checked' => (bool)$settings['private'],
]) ?>
<p class="hint"><?= __('Die Präsentation zeigt zunächst nur, wie viele Antworten eingegangen sind. Mit „Ergebnisse zeigen“ (Taste H) kannst du die Texte bei Bedarf einblenden. Teilnehmende sehen sie nie, im PDF-Export stehen sie nur in der vollständigen Fassung.') ?></p>
<?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>
<?= $this->Form->control('settings.comments', [
'type' => 'checkbox',
'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Bewertung optional begründen)'),
'checked' => (bool)$settings['comments'],
]) ?>
<p class="hint"><?= __('Die Kommentare laufen in der Präsentation nacheinander durch (nicht bei den Teilnehmenden), jeder so lange, wie man zum Lesen braucht: kurze etwa 5 Sekunden, lange bis zu 30 Sekunden. Bei internem Feedback erst, wenn du die Ergebnisse einblendest.') ?></p>
<?= $this->Form->control('settings.comment_ratings', [
'type' => 'checkbox',
'label' => __('Bewertung beim Kommentar in der Präsentation anzeigen'),
'checked' => (bool)$settings['comment_ratings'],
]) ?>
<?= $this->Form->control('settings.private', [
'type' => 'checkbox',
'label' => __('Internes Feedback: Ergebnis nicht öffentlich anzeigen'),
'checked' => (bool)$settings['private'],
]) ?>
<p class="hint"><?= __('Die Präsentation zeigt zunächst nur, wie viele Bewertungen eingegangen sind. Mit „Ergebnisse zeigen“ (Taste H) kannst du Verteilung, Durchschnitt und Kommentare bei Bedarf einblenden. Teilnehmende sehen sie nie, im PDF-Export stehen sie nur in der vollständigen Fassung.') ?></p>
<?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 elseif ($slide->isOrder()) :
$orderError = $slide->getError('order_options');
$max = \App\Model\Table\SlidesTable::MAX_ORDER_OPTIONS;
$rows = array_pad($orderOptions, min($max, max(4, count($orderOptions) + 1)), '');
?>
<fieldset class="order-options<?= $orderError ? ' error' : '' ?>" data-order-options data-max="<?= $max ?>"
aria-describedby="order-options-hint<?= $orderError ? ' order-options-error' : '' ?>">
<legend><?= __('Einträge in der richtigen Reihenfolge') ?></legend>
<p class="hint" id="order-options-hint"><?= __('Mindestens zwei, maximal {0} Einträge – von oben (zuerst) nach unten. Teilnehmende bekommen sie gemischt und müssen sie sortieren. Leere Zeilen werden ignoriert.', $max) ?></p>
<p class="hint" data-order-hint hidden><?= __('Zum Umsortieren den Griff ⠿ ziehen, oder Griff fokussieren und Pfeiltasten nutzen.') ?></p>
<ol class="order-options__list" data-order-list>
<?php foreach ($rows as $i => $label) : ?>
<li class="order-option" data-order-row>
<button type="button" class="drag-handle" data-drag-handle hidden
aria-label="<?= __('Eintrag verschieben (Pfeiltasten)') ?>" title="<?= __('Ziehen zum Sortieren') ?>">⠿</button>
<span class="order-option__pos" data-position aria-hidden="true"><?= $i + 1 ?>.</span>
<label class="sr-only" for="order-option-<?= $i ?>" data-row-label><?= __('Platz {0}', $i + 1) ?></label>
<input type="text" id="order-option-<?= $i ?>" name="order_options[]"
value="<?= h($label) ?>" maxlength="255" <?= $i < 2 ? 'required' : '' ?>
placeholder="<?= __('Eintrag {0}', $i + 1) ?>">
</li>
<?php endforeach; ?>
</ol>
<p class="sr-only" role="status" aria-live="polite" data-order-status></p>
<button type="button" class="button button--small" data-order-add hidden>+ <?= __('Eintrag hinzufügen') ?></button>
<?php if ($orderError) : ?>
<div class="error-message" id="order-options-error"><?= h(implode(' ', (array)$orderError)) ?></div>
<?php endif; ?>
<?php if (!empty($hasResponses)) : ?>
<p class="hint"><?= __('Achtung: Umbenannte oder entfernte Einträge zählen bei bisherigen Antworten als falsch. Eine neue Reihenfolge gilt sofort für die Auswertung.') ?></p>
<?php endif; ?>
</fieldset>
<p class="hint"><?= __('Aufgelöst wird, sobald du die Abstimmung schließt: Dann siehst du, wie viele richtig lagen, und jede Person sieht, ob ihre Reihenfolge stimmt.') ?></p>
<?php elseif ($slide->type === 'qa') :
$upvoteOptions = [];
foreach (range(1, \App\Model\Entity\Slide::QA_MAX_UPVOTES) as $n) {
$upvoteOptions[$n] = __n('{0} Stimme', '{0} Stimmen', $n, $n);
}
?>
<?= $this->Form->control('settings.max_upvotes', [
'type' => 'select',
'options' => [0 => __('keine – ohne Abstimmung')] + $upvoteOptions,
'label' => __('Upvotes (Stimmen) pro Person'),
'value' => $settings['max_upvotes'],
'aria-describedby' => 'qa-upvotes-hint',
]) ?>
<p class="hint" id="qa-upvotes-hint"><?= __('So viele Stimmen hat jede Person beim Abstimmen. Sie lassen sich auf Fragen anderer verteilen. Mit „keine“ entfällt die Abstimmung: Nach dem Sammeln werden die Fragen in der Reihenfolge besprochen, in der sie eingegangen sind.') ?></p>
<?= $this->Form->control('settings.max_upvotes_per_question', [
'type' => 'select',
'options' => [0 => __('unbegrenzt (bis alle Stimmen vergeben sind)')] + $upvoteOptions,
'label' => __('Höchstens pro Frage'),
'value' => $settings['max_upvotes_per_question'],
'aria-describedby' => 'qa-per-question-hint',
]) ?>
<p class="hint" id="qa-per-question-hint"><?= __('So viele Stimmen darf eine Person derselben Frage geben. „1 Stimme“ heißt: jede Frage höchstens einmal unterstützen. Mehrere Stimmen auf eine Frage geben ihr mehr Gewicht.') ?></p>
<?= $this->Form->control('settings.allow_self_upvote', [
'type' => 'checkbox',
'label' => __('Stimmen für eigene Fragen erlauben'),
'checked' => (bool)$settings['allow_self_upvote'],
'aria-describedby' => 'qa-self-upvote-hint',
]) ?>
<p class="hint" id="qa-self-upvote-hint"><?= __('Sinnvoll, wenn ihr Themen priorisiert („Was besprechen wir heute?“). Bei normalen Fragerunden lieber aus: Sonst landen oft die Fragen derjenigen vorn, die alle Stimmen sich selbst geben.') ?></p>
<p class="hint"><?= __('Ablauf in der Präsentation: 1. Fragen sammeln, 2. abstimmen, 3. besprechen – die Frage mit den meisten Upvotes zuerst. Ohne Upvotes entfällt Schritt 2. Du schaltest die Schritte selbst weiter.') ?></p>
<?php endif; ?>
<?php if ($slide->isInteractive() && !$slide->isQuiz() && !$slide->isQa()) : ?>
<?= $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>