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

+37 -1
View File
@@ -8,6 +8,7 @@ use App\Model\Entity\Slide;
use App\Model\Table\ResponsesTable;
use App\Model\Table\SlidesTable;
use App\Service\PollStateService;
use App\Service\QaService;
use App\Service\VoteService;
use Cake\Core\Configure;
use Cake\Http\Exception\BadRequestException;
@@ -158,7 +159,11 @@ class AdminController extends AdminAppController
/**
* Presenter controls. Field `action`:
* goto (+ slide_id), next, prev, open, close, toggle, stop
* goto (+ slide_id), next, prev, open, close, toggle, stop,
* Q&A: stage (+ stage: collect|vote|discuss), question (+ step: 1|-1)
*
* On a Q&A slide that is being discussed, next/prev step through the questions
* first (like builds in presentation software), toggle switches to the next stage.
*
* Answers with the new state as JSON for XHR requests, otherwise redirects back.
*
@@ -171,8 +176,36 @@ class AdminController extends AdminAppController
$slides = $this->Slides->listForPoll($this->poll->id);
$ids = array_map(fn(Slide $s) => $s->id, $slides);
$index = array_search($this->poll->current_slide_id, $ids, true);
$current = $index === false ? null : $slides[$index];
$qa = new QaService();
if ($current !== null && $current->isQa()) {
if ($action === 'toggle') {
// No-op while discussing (last stage).
$qa->advance($current);
$action = 'none';
} elseif (in_array($action, ['next', 'prev'], true) && $qa->moveFocus($current, $action === 'next' ? 1 : -1)) {
$action = 'none';
}
}
switch ($action) {
case 'none':
break;
case 'stage':
case 'question':
if ($current === null || !$current->isQa()) {
throw new BadRequestException('Not a Q&A slide');
}
if ($action === 'question') {
$qa->moveFocus($current, (int)$this->request->getData('step') < 0 ? -1 : 1);
break;
}
$stage = (string)$this->request->getData('stage');
if (!in_array($stage, Slide::QA_STAGES, true)) {
throw new BadRequestException('Unknown stage');
}
$qa->setStage($current, $stage);
break;
case 'goto':
$target = (int)$this->request->getData('slide_id');
if (!in_array($target, $ids, true)) {
@@ -267,8 +300,11 @@ class AdminController extends AdminAppController
->where(['slide_id' => $slide->id])
->orderBy(['id' => 'ASC'])
->all();
$texts = [];
foreach ($responses as $response) {
$texts[$response->id] = (string)$response->text_value;
$answer = match (true) {
$response->parent_id !== null => __('Upvote: {0}', $texts[$response->parent_id] ?? ''),
$response->slide_option_id !== null => $labels[$response->slide_option_id] ?? '',
$response->text_value !== null && $response->numeric_value === VoteService::DOWNVOTE
=> __('Downvote: {0}', $response->text_value),
+6 -1
View File
@@ -124,7 +124,12 @@ class ParticipateController extends AppController
}
(new VoteService())->submit($poll, $slide, $this->participantHash($poll), (array)$this->request->getData());
$ok = true;
$message = __('Danke für deine Antwort!');
$message = match (true) {
!$slide->isQa() => __('Danke für deine Antwort!'),
$this->request->getData('vote') === 'up' => __('Deine Stimme ist angekommen.'),
$this->request->getData('vote') === 'remove' => __('Deine Stimme wurde zurückgenommen.'),
default => __('Danke, deine Frage ist angekommen!'),
};
} catch (VoteException $e) {
$ok = false;
$message = $e->getMessage();
+8 -2
View File
@@ -5,6 +5,7 @@ namespace App\Controller;
use App\Model\Entity\Slide;
use App\Model\Table\SlidesTable;
use App\Service\QaService;
use App\Service\YouTubeService;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Response;
@@ -43,6 +44,8 @@ class SlidesController extends AdminAppController
$slide->poll_id = $this->poll->id;
// A quiz is started by the presenter (that also starts its timer).
$slide->is_voting_open = $type !== Slide::TYPE_QUIZ;
// Q&A starts by collecting questions.
$slide->stage = $type === Slide::TYPE_QA ? Slide::QA_COLLECT : null;
$optionsText = $type === Slide::TYPE_CHOICE ? "\n" : '';
$quizOptions = [];
@@ -147,6 +150,9 @@ class SlidesController extends AdminAppController
$slide->voting_ends_at = null;
$this->Slides->saveOrFail($slide);
}
if ($slide->isQa()) {
(new QaService())->reset($slide);
}
$this->Flash->success(__('Antworten der Folie „{0}“ wurden gelöscht.', $slide->question));
return $this->redirect($this->adminUrl());
@@ -205,8 +211,8 @@ class SlidesController extends AdminAppController
// The type of an existing slide cannot change (would invalidate responses).
$data['type'] = $slide->type;
$fields = ['type', 'question', 'description', 'settings', 'is_voting_open'];
if ($slide->isQuiz()) {
// Quiz voting is controlled by the presenter only.
if ($slide->isQuiz() || $slide->isQa()) {
// Quiz and Q&A voting is controlled by the presenter only.
$fields = array_values(array_diff($fields, ['is_voting_open']));
}
$youtube = $slide->isYouTube() ? $this->prepareYouTube($data) : ['errors' => [], 'warning' => null];