Files
Plenario/templates/Participate/view.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

174 lines
9.6 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
/**
* Participant page. Server rendered; webroot/js/plenario.js (Plenario.participant)
* polls /p/{code}/state, reloads when the slide changes and updates results live.
*
* @var \App\View\AppView $this
* @var \App\Model\Entity\Poll $poll
* @var \App\Model\Entity\Slide|null $slide
* @var array<string, mixed> $state
* @var int $pollIntervalMs
*/
$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
data-state-url="<?= $this->Url->build(['_name' => 'participate:state', 'code' => $poll->join_code]) ?>"
data-version="<?= h($state['version']) ?>"
data-vote-url="<?= $this->Url->build($voteUrl) ?>"
data-interval="<?= (int)$pollIntervalMs ?>">
<p class="eyebrow center"><?= h($poll->title) ?></p>
<?php if (!$poll->is_active) : ?>
<section class="card center">
<h1><?= __('Diese Umfrage ist geschlossen.') ?></h1>
<p class="muted"><?= __('Danke fürs Vorbeischauen!') ?></p>
</section>
<?php elseif ($slide === null) : ?>
<section class="card center waiting">
<div class="pulse" aria-hidden="true"></div>
<h1><?= __('Gleich geht’s los …') ?></h1>
<p class="muted"><?= __('Warte, bis die erste Frage gestartet wird. Die Seite aktualisiert sich automatisch.') ?></p>
</section>
<?php elseif (!$slide->isInteractive()) : ?>
<section class="card">
<h1><?= h($slide->question) ?></h1>
<?php if ($slide->description) : ?>
<div class="prose"><?= nl2br(h($slide->description)) ?></div>
<?php endif; ?>
</section>
<?php else : ?>
<section class="card">
<h1 class="question"><?= h($slide->question) ?></h1>
<?php if ($slide->description) : ?>
<p class="muted"><?= nl2br(h($slide->description)) ?></p>
<?php endif; ?>
<?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>
<div class="word-entry">
<input type="text" name="word" maxlength="40" class="word-input" required autofocus
autocomplete="off" autocapitalize="off" spellcheck="false"
placeholder="<?= __('Begriff eingeben …') ?>"
role="combobox" aria-autocomplete="list" aria-expanded="false"
aria-controls="word-suggestions" data-word-input>
<ul class="suggestions" id="word-suggestions" role="listbox" hidden data-suggestions></ul>
</div>
<p class="word-message" data-word-message aria-live="polite"></p>
<?= $this->Form->button(__('Begriff senden'), ['class' => 'button button--primary button--block']) ?>
<?= $this->Form->end() ?>
<?php elseif ($state['hasResponded']) : ?>
<p class="done">✓ <?= __('Deine Antwort ist angekommen.') ?></p>
<?php elseif (!$slide->is_voting_open) : ?>
<p class="muted"><?= __('Die Abstimmung zu dieser Frage ist geschlossen.') ?></p>
<?php else : ?>
<?= $this->Form->create(null, ['url' => $voteUrl, 'class' => 'vote-form']) ?>
<?= $this->Form->hidden('slide_id', ['value' => $slide->id]) ?>
<?php if ($slide->type === 'choice') :
$multiple = (bool)$slide->setting('multiple'); ?>
<?php if ($multiple) : ?><p class="hint"><?= __('Mehrfachauswahl möglich') ?></p><?php endif; ?>
<div class="choices">
<?php foreach ($slide->slide_options as $option) : ?>
<label class="choice">
<input type="<?= $multiple ? 'checkbox' : 'radio' ?>"
name="<?= $multiple ? 'option_ids[]' : 'option_id' ?>"
value="<?= (int)$option->id ?>" <?= $multiple ? '' : 'required' ?>>
<span><?= h($option->label) ?></span>
</label>
<?php endforeach; ?>
</div>
<?php elseif ($slide->type === 'open') : ?>
<textarea name="text" rows="4" maxlength="500" required
placeholder="<?= __('Deine Antwort …') ?>"></textarea>
<?php elseif ($slide->type === 'scale') : ?>
<div class="scale">
<?php for ($v = (int)$slide->setting('scale_min'); $v <= (int)$slide->setting('scale_max'); $v++) : ?>
<label class="scale__step">
<input type="radio" name="value" value="<?= $v ?>" required>
<span><?= $v ?></span>
</label>
<?php endfor; ?>
</div>
<div class="scale__labels">
<span><?= h((string)$slide->setting('min_label')) ?></span>
<span><?= h((string)$slide->setting('max_label')) ?></span>
</div>
<?php endif; ?>
<?= $this->Form->button(__('Absenden'), ['class' => 'button button--primary button--block']) ?>
<?= $this->Form->end() ?>
<?php endif; ?>
</section>
<section class="card results-card" data-results-card <?= $state['results'] ? '' : 'hidden' ?>>
<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.')
: __('Tippe auf einen Begriff, um ihn zu unterstützen.') ?></p>
<?php endif; ?>
<div data-results></div>
</section>
<script type="application/json" data-initial-state><?= json_encode($state, JSON_HEX_TAG | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE) ?></script>
<?php endif; ?>
</div>