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>
This commit is contained in:
1 parent
04cbc5bcd3
commit
fd8da4c16c
18 files changed
+999
-43
No files matched your search
@@ -19,6 +19,11 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
* - open: 'answers' => [['text', 'created']] newest first
|
||||
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
|
||||
* 'min', 'max', 'minLabel', 'maxLabel'
|
||||
* - quiz: 'phase' (ready|running|finished), 'timeLimit' (s, 0 = manual), 'remaining' (s|null),
|
||||
* 'revealed' (bool), 'options' => [['id', 'label']] while not finished;
|
||||
* once finished additionally per option 'count', 'percent', 'correct' (bool)
|
||||
* and 'correctCount' (participants with a correct answer).
|
||||
* Counts and correct answers are NEVER part of the result before the quiz is finished.
|
||||
*/
|
||||
class ResultsService
|
||||
{
|
||||
@@ -54,6 +59,7 @@ class ResultsService
|
||||
Slide::TYPE_WORDCLOUD => $this->wordcloud($slide),
|
||||
Slide::TYPE_OPEN => $this->open($slide),
|
||||
Slide::TYPE_SCALE => $this->scale($slide),
|
||||
Slide::TYPE_QUIZ => $this->quiz($slide),
|
||||
default => [],
|
||||
};
|
||||
}
|
||||
@@ -88,6 +94,46 @@ class ResultsService
|
||||
return ['options' => $options, 'votes' => $total];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function quiz(Slide $slide): array
|
||||
{
|
||||
$phase = $slide->quizPhase();
|
||||
$result = [
|
||||
'phase' => $phase,
|
||||
'timeLimit' => (int)$slide->setting('time_limit'),
|
||||
'remaining' => $phase === Slide::QUIZ_RUNNING ? $slide->remainingSeconds() : null,
|
||||
'revealed' => $phase === Slide::QUIZ_FINISHED,
|
||||
];
|
||||
if ($phase !== Slide::QUIZ_FINISHED) {
|
||||
$result['options'] = array_map(fn($option) => [
|
||||
'id' => $option->id,
|
||||
'label' => $option->label,
|
||||
], $slide->slide_options ?? []);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$choice = $this->choice($slide);
|
||||
$correctIds = [];
|
||||
foreach ($slide->slide_options ?? [] as $option) {
|
||||
if ($option->is_correct) {
|
||||
$correctIds[] = $option->id;
|
||||
}
|
||||
}
|
||||
$result['options'] = array_map(fn(array $option) => $option + [
|
||||
'correct' => in_array($option['id'], $correctIds, true),
|
||||
], $choice['options']);
|
||||
$result['correctCount'] = $correctIds === [] ? 0 : $this->Responses->find()
|
||||
->where(['slide_id' => $slide->id, 'slide_option_id IN' => $correctIds])
|
||||
->distinct(['participant_hash'])
|
||||
->count();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @return array<string, mixed>
|
||||
|
||||
Reference in new issue
Block a user