Merge pull request 'Add quiz slide type' (#6) from feature/quiz-slide into main
CI / Deploy / test (push) Successful in 46s
CI / Deploy / deploy (push) Successful in 5s

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
gnilebein committed 2026-11-07 14:40:24 +01:00
commit 50010484be
18 files changed
+999 -43

No files matched your search

+12 -1
View File
@@ -65,12 +65,23 @@ $url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $ad
<?php if ($isCurrent) : ?><span class="badge badge--live"><?= __('live') ?></span><?php endif; ?>
<?php if ($slide->isInteractive()) : ?>
<span class="muted"><?= __n('{0} Antwort', '{0} Antworten', $count, $count) ?></span>
<?php if (!$slide->is_voting_open) : ?><span class="muted">· <?= __('Abstimmung geschlossen') ?></span><?php endif; ?>
<?php if ($slide->isQuiz()) : ?>
<span class="muted">· <?= h([
'ready' => __('Quiz noch nicht gestartet'),
'running' => __('Quiz läuft'),
'finished' => __('Quiz beendet'),
][$slide->quizPhase()]) ?></span>
<?php elseif (!$slide->is_voting_open) : ?><span class="muted">· <?= __('Abstimmung geschlossen') ?></span><?php endif; ?>
<?php endif; ?>
</div>
<a class="slide-item__title" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= h($slide->question) ?></a>
<?php if ($slide->type === 'choice' && $slide->slide_options) : ?>
<p class="slide-item__options muted"><?= h(implode(' · ', array_map(fn($o) => $o->label, $slide->slide_options))) ?></p>
<?php elseif ($slide->isQuiz() && $slide->slide_options) : ?>
<p class="slide-item__options muted"><?= h(implode(' · ', array_map(
fn($o) => $o->is_correct ? '✓ ' . $o->label : $o->label,
$slide->slide_options,
))) ?></p>
<?php endif; ?>
</div>
<div class="slide-item__actions">
+49 -2
View File
@@ -13,6 +13,17 @@ $this->assign('title', $poll->title);
$this->assign('bodyClass', 'participant');
$voteUrl = ['_name' => 'participate:vote', 'code' => $poll->join_code];
$words = $state['words'] ?? null;
$quiz = $state['quiz'] ?? null;
$countdown = function (?int $remaining): string {
if ($remaining === null) {
return '';
}
return '<p class="countdown" role="timer" data-countdown data-remaining="' . $remaining . '">'
. '<span class="countdown__label">' . h(__('Noch')) . '</span> '
. '<strong class="countdown__value" data-countdown-value>' . sprintf('%d:%02d', intdiv($remaining, 60), $remaining % 60) . '</strong>'
. '</p>';
};
?>
<div class="participant-view"
data-participant
@@ -51,7 +62,39 @@ $words = $state['words'] ?? null;
<p class="muted"><?= nl2br(h($slide->description)) ?></p>
<?php endif; ?>
<?php if ($words !== null && $slide->is_voting_open) : ?>
<?php if ($quiz !== null) : ?>
<?php if ($quiz['phase'] === 'ready') : ?>
<div class="waiting center">
<div class="pulse" aria-hidden="true"></div>
<p class="muted"><?= __('Das Quiz startet gleich. Die Antworten erscheinen, sobald es losgeht.') ?></p>
</div>
<?php elseif ($quiz['phase'] === 'running' && $state['hasResponded']) : ?>
<?= $countdown($quiz['remaining']) ?>
<p class="done">✓ <?= __('Deine Antwort ist angekommen.') ?></p>
<p class="muted"><?= __('Die Auflösung gibt es, sobald das Quiz beendet ist.') ?></p>
<?php elseif ($quiz['phase'] === 'running') : ?>
<?= $countdown($quiz['remaining']) ?>
<?= $this->Form->create(null, ['url' => $voteUrl, 'class' => 'vote-form', 'data-quiz-form' => true]) ?>
<?= $this->Form->hidden('slide_id', ['value' => $slide->id]) ?>
<fieldset class="choices choices--quiz">
<legend class="sr-only"><?= __('Antworten') ?></legend>
<?php foreach ($slide->slide_options as $index => $option) : ?>
<label class="choice choice--quiz choice--c<?= $index % 6 ?>">
<input type="radio" name="option_id" value="<?= (int)$option->id ?>" required>
<span><?= h($option->label) ?></span>
</label>
<?php endforeach; ?>
</fieldset>
<?= $this->Form->button(__('Antwort abgeben'), ['class' => 'button button--primary button--block']) ?>
<?= $this->Form->end() ?>
<?php elseif ($quiz['isCorrect'] === true) : ?>
<p class="verdict verdict--correct">✓ <?= __('Richtig!') ?></p>
<?php elseif ($quiz['isCorrect'] === false) : ?>
<p class="verdict verdict--wrong">✗ <?= __('Leider falsch.') ?></p>
<?php else : ?>
<p class="muted"><?= __('Das Quiz ist beendet – du hast keine Antwort abgegeben.') ?></p>
<?php endif; ?>
<?php elseif ($words !== null && $slide->is_voting_open) : ?>
<?= $this->Form->create(null, ['url' => $voteUrl, 'class' => 'vote-form word-form', 'data-word-form' => true]) ?>
<?= $this->Form->hidden('slide_id', ['value' => $slide->id]) ?>
<p class="hint"><?= __('Du kannst beliebig viele Begriffe abgeben.') ?></p>
@@ -113,7 +156,11 @@ $words = $state['words'] ?? null;
</section>
<section class="card results-card" data-results-card <?= $state['results'] ? '' : 'hidden' ?>>
<h2><?= $words !== null ? __('Wortwolke') : __('Ergebnisse') ?></h2>
<h2><?= match (true) {
$words !== null => __('Wortwolke'),
$quiz !== null => __('Auflösung'),
default => __('Ergebnisse'),
} ?></h2>
<?php if ($words !== null && $words['allowUpvotes'] && $slide->is_voting_open) : ?>
<p class="hint" data-upvote-hint><?= $words['allowDownvotes']
? __('Tippe auf einen Begriff, um ihn zu unterstützen, oder auf „−“, um ihn abzulehnen.')
+54 -1
View File
@@ -8,6 +8,7 @@
* @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();
@@ -85,9 +86,61 @@ $optionsError = $slide->getError('options_text');
'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()) : ?>
<?php if ($slide->isInteractive() && !$slide->isQuiz()) : ?>
<?= $this->Form->control('is_voting_open', [
'type' => 'checkbox',
'label' => __('Abstimmung geöffnet'),