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

+26 -2
View File
@@ -21,6 +21,8 @@ use Cake\Utility\Security;
* exists in the cloud is an upvote – both are stored as the same row.
* `vote=down` stores a downvote (numeric_value = DOWNVOTE) for an existing
* word of someone else. Each participant rates a word only once (up or down).
* - quiz: exactly one option, only while the quiz runs (Slide::isVotingOpen()
* includes the deadline of a timed quiz).
*/
class VoteService
{
@@ -78,8 +80,12 @@ class VoteService
if (!$slide->isInteractive()) {
throw new VoteException(__('Auf dieser Folie kann nicht abgestimmt werden.'));
}
if (!$slide->is_voting_open) {
throw new VoteException(__('Die Abstimmung zu dieser Frage ist geschlossen.'));
if (!$slide->isVotingOpen()) {
throw new VoteException(match (true) {
$slide->isQuiz() && $slide->voting_started_at === null => __('Das Quiz hat noch nicht begonnen.'),
$slide->isQuiz() => __('Die Zeit für dieses Quiz ist abgelaufen.'),
default => __('Die Abstimmung zu dieser Frage ist geschlossen.'),
});
}
if ($slide->type !== Slide::TYPE_WORDCLOUD && $this->Responses->hasResponded($slide->id, $participantHash)) {
throw new VoteException(__('Du hast bereits abgestimmt.'));
@@ -90,6 +96,7 @@ class VoteService
Slide::TYPE_WORDCLOUD => $this->wordRows($slide, $participantHash, $data),
Slide::TYPE_OPEN => $this->openRows($data),
Slide::TYPE_SCALE => $this->scaleRows($slide, $data),
Slide::TYPE_QUIZ => $this->quizRows($slide, $data),
default => throw new VoteException(__('Unbekannter Folientyp.')),
};
@@ -125,6 +132,23 @@ class VoteService
return array_map(fn(int $id) => ['slide_option_id' => $id], $selected);
}
/**
* @param \App\Model\Entity\Slide $slide Slide
* @param array<string, mixed> $data Request data
* @return list<array<string, mixed>>
*/
protected function quizRows(Slide $slide, array $data): array
{
$selected = $data['option_id'] ?? null;
$id = is_scalar($selected) ? filter_var($selected, FILTER_VALIDATE_INT) : false;
$validIds = array_map(fn($option) => $option->id, $slide->slide_options ?? []);
if ($id === false || !in_array($id, $validIds, true)) {
throw new VoteException(__('Bitte wähle eine Antwort aus.'));
}
return [['slide_option_id' => $id]];
}
/**
* Normalized key of a word cloud term: whitespace collapsed, trimmed, cut to
* MAX_WORD_LENGTH. Use wordKey() for case-insensitive comparison.