Add Q&A slide type
CI / Deploy / test (push) Successful in 48s
CI / Deploy / deploy (push) Skipped

Participants submit questions, upvote them and the presenter discusses
them one by one, most upvoted first.

- Stages collect -> vote -> discuss, switched manually by the presenter
  (V key or stepper, going back is possible)
- Configurable upvote budget per participant, freely distributable
  (several upvotes on one question are allowed), votes can be withdrawn
- Participants see all questions while collecting to avoid duplicates;
  no counts before the discussion
- While discussing, next/prev step through the questions before
  moving to the next slide
- Migration: slides.stage, slides.focus_response_id, responses.parent_id

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 16:09:46 +01:00
1 parent ea944b080f
commit f0c6687100
21 files changed
+1327 -27

No files matched your search

+51 -5
View File
@@ -22,6 +22,8 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* once the quiz is finished – then always, independent of
* `show_results_to_participants`. Timed quizzes are closed lazily here
* when their deadline has passed.
*
* Q&A slides have their own participant view (`qa`, see qaState()), never `results`.
*/
class PollStateService
{
@@ -111,13 +113,17 @@ 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);
$qa = $slide?->isQa() ? $this->qaState($slide, $participantHash) : null;
$hasResponded = match (true) {
$words !== null => $words['mine'] !== [] || $words['down'] !== [],
$qa !== null => $qa['mine'] !== [] || $qa['upvoted'] !== [],
default => $slide && $slide->isInteractive() && $this->Responses->hasResponded($slide->id, $participantHash),
};
$isVotingOpen = $slide?->isVotingOpen() ?? false;
$showResults = $slide !== null
&& $slide->isInteractive()
&& $qa === null
&& ($quiz !== null
? $quiz['phase'] === Slide::QUIZ_FINISHED
: ($poll->show_results_to_participants && ($hasResponded || !$isVotingOpen))
@@ -133,14 +139,15 @@ class PollStateService
(int)$poll->is_active,
$slide?->id ?? 0,
(int)$isVotingOpen,
// Word clouds are answered word by word without reload.
$words !== null ? 0 : (int)$hasResponded,
// Word clouds and Q&A are answered item by item without reload.
$words !== null || $qa !== null ? 0 : (int)$hasResponded,
$slide?->modified?->toUnixString() ?? 0,
]),
'slide' => $showResults ? $this->slidePayload($slide) : null,
'results' => $showResults ? $this->results->forSlide($slide) : null,
'words' => $words,
'quiz' => $quiz,
'qa' => $qa,
];
}
@@ -181,6 +188,45 @@ class PollStateService
];
}
/**
* Q&A view of one participant:
* - collect: all questions so far in submission order (helps to avoid duplicates), `mine` marks own ones
* - vote: all questions in submission order, without counts (no bandwagon effect)
* - discuss: all questions ranked with upvotes, `focusId` = question being discussed
* `upvoted` = own upvotes per question id (several per question are allowed).
*
* @param \App\Model\Entity\Slide $slide Q&A slide
* @param string $participantHash Participant hash
* @return array{stage: string, maxUpvotes: int, votesLeft: int, mine: list<int>, upvoted: array<int, int>,
* questions: list<array{id: int, text: string, votes?: int}>, focusId: int|null}
*/
public function qaState(Slide $slide, string $participantHash): array
{
$stage = $slide->qaStage();
$own = $this->Responses->qaVotesOf($slide->id, $participantHash);
$max = (int)$slide->setting('max_upvotes');
$questions = (new QaService())->rankedQuestions($slide);
if ($stage === Slide::QA_DISCUSS) {
$focusId = in_array($slide->focus_response_id, array_column($questions, 'id'), true)
? $slide->focus_response_id
: null;
} else {
$focusId = null;
usort($questions, fn($a, $b) => $a['id'] <=> $b['id']);
$questions = array_map(fn($q) => ['id' => $q['id'], 'text' => $q['text']], $questions);
}
return [
'stage' => $stage,
'maxUpvotes' => $max,
'votesLeft' => max(0, $max - count($own['upvotes'])),
'mine' => $own['questions'],
'upvoted' => array_count_values($own['upvotes']),
'questions' => array_values($questions),
'focusId' => $focusId,
];
}
/**
* Word cloud progress of one participant.
*