Files
Plenario/templates/Slides/form.php
T
gnilebeinandClaude Opus 5.5 fd8da4c16c
CI / Deploy / test (push) Successful in 41s
CI / Deploy / deploy (push) Skipped
Add quiz slide type
Quiz slides have predefined answers with one or more marked as correct.
The presenter starts the quiz, which then runs until its optional time
limit expires or the presenter ends it. Counts and correct answers are
only revealed once the quiz is finished; participants then see whether
their answer was right.

- migration: slide_options.is_correct, slides.voting_started_at/voting_ends_at
- Slide::isVotingOpen() includes the quiz deadline, expired quizzes are
  closed lazily when the state is read
- presenter countdown, quiz tiles and reveal with correct-answer summary
- CSV export marks quiz answers as right/wrong

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 14:39:21 +01:00

157 lines
8.7 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
*/
$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') ?>
<?= $this->Form->control('question', [
'label' => $slide->type === 'content' ? __('Überschrift') : __('Frage'),
'maxlength' => 500,
'required' => true,
'autofocus' => $isNew,
]) ?>
<?= $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>