Add quiz slide type
CI / Deploy / test (push) Successful in 41s
CI / Deploy / deploy (push) Skipped

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>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 14:39:21 +01:00
1 parent 04cbc5bcd3
commit fd8da4c16c
18 files changed
+999 -43

No files matched your search

+54 -9
View File
@@ -17,6 +17,11 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* the participant has answered (or voting is closed). Exception: word clouds
* with upvotes enabled show the live cloud while voting is open, because
* participants upvote by clicking words in it.
*
* Quiz slides reveal results (and the participant's own correctness) only
* once the quiz is finished – then always, independent of
* `show_results_to_participants`. Timed quizzes are closed lazily here
* when their deadline has passed.
*/
class PollStateService
{
@@ -58,7 +63,7 @@ class PollStateService
->contain(['SlideOptions'])
->first();
return $slide;
return $slide ? $this->Slides->closeIfExpired($slide) : null;
}
/**
@@ -72,7 +77,7 @@ class PollStateService
$index = null;
foreach ($slides as $i => $slide) {
if ($slide->id === $poll->current_slide_id) {
$current = $slide;
$current = $this->Slides->closeIfExpired($slide);
$index = $i;
}
}
@@ -105,27 +110,29 @@ class PollStateService
{
$slide = $poll->is_active ? $this->currentSlide($poll) : null;
$words = $slide?->type === Slide::TYPE_WORDCLOUD ? $this->wordState($slide, $participantHash) : null;
$quiz = $slide?->isQuiz() ? $this->quizState($slide, $participantHash) : null;
$hasResponded = $words !== null
? $words['mine'] !== [] || $words['down'] !== []
: $slide && $slide->isInteractive() && $this->Responses->hasResponded($slide->id, $participantHash);
$isVotingOpen = $slide?->isVotingOpen() ?? false;
$showResults = $slide !== null
&& $slide->isInteractive()
&& (
($poll->show_results_to_participants && ($hasResponded || !$slide->is_voting_open))
|| ($words !== null && $words['allowUpvotes'] && $slide->is_voting_open)
);
&& ($quiz !== null
? $quiz['phase'] === Slide::QUIZ_FINISHED
: ($poll->show_results_to_participants && ($hasResponded || !$isVotingOpen))
|| ($words !== null && $words['allowUpvotes'] && $isVotingOpen));
return [
'isActive' => $poll->is_active,
'slideId' => $slide?->id,
'isVotingOpen' => $slide?->is_voting_open ?? false,
'isVotingOpen' => $isVotingOpen,
'hasResponded' => $hasResponded,
// Changes whenever the participant page must re-render.
'version' => implode(':', [
(int)$poll->is_active,
$slide?->id ?? 0,
(int)($slide?->is_voting_open ?? 0),
(int)$isVotingOpen,
// Word clouds are answered word by word without reload.
$words !== null ? 0 : (int)$hasResponded,
$slide?->modified?->toUnixString() ?? 0,
@@ -133,6 +140,44 @@ class PollStateService
'slide' => $showResults ? $this->slidePayload($slide) : null,
'results' => $showResults ? $this->results->forSlide($slide) : null,
'words' => $words,
'quiz' => $quiz,
];
}
/**
* Quiz progress of one participant. The own answer and its correctness are
* only included once the quiz is finished.
*
* @param \App\Model\Entity\Slide $slide Quiz slide incl. slide_options
* @param string $participantHash Participant hash
* @return array{phase: string, remaining: int|null, answerId: int|null, isCorrect: bool|null}
*/
public function quizState(Slide $slide, string $participantHash): array
{
$phase = $slide->quizPhase();
$answerId = null;
$isCorrect = null;
if ($phase === Slide::QUIZ_FINISHED) {
$response = $this->Responses->find()
->select(['slide_option_id'])
->where(['slide_id' => $slide->id, 'participant_hash' => $participantHash])
->first();
$answerId = $response?->slide_option_id;
if ($answerId !== null) {
$isCorrect = false;
foreach ($slide->slide_options ?? [] as $option) {
if ($option->id === $answerId) {
$isCorrect = $option->is_correct;
}
}
}
}
return [
'phase' => $phase,
'remaining' => $phase === Slide::QUIZ_RUNNING ? $slide->remainingSeconds() : null,
'answerId' => $answerId,
'isCorrect' => $isCorrect,
];
}
@@ -171,7 +216,7 @@ class PollStateService
'typeLabel' => $slide->typeLabel(),
'question' => $slide->question,
'description' => (string)$slide->description,
'isVotingOpen' => $slide->is_voting_open,
'isVotingOpen' => $slide->isVotingOpen(),
'isInteractive' => $slide->isInteractive(),
'settings' => $slide->getSettings(),
];