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

+3
View File
@@ -8,6 +8,7 @@ use Cake\ORM\Entity;
/**
* One answer row of a participant. A multi-select vote or a word cloud entry
* with several words results in several rows with the same participant_hash.
* Q&A: a question is a row with text_value, an upvote a row with parent_id = question id.
*
* @property int $id
* @property int $slide_id
@@ -15,6 +16,7 @@ use Cake\ORM\Entity;
* @property int|null $slide_option_id
* @property string|null $text_value
* @property int|null $numeric_value
* @property int|null $parent_id Q&A upvote: id of the supported question
* @property \Cake\I18n\DateTime $created
*/
class Response extends Entity
@@ -30,6 +32,7 @@ class Response extends Entity
'slide_option_id' => true,
'text_value' => true,
'numeric_value' => true,
'parent_id' => true,
];
/**
+54
View File
@@ -21,6 +21,8 @@ use Cake\ORM\Entity;
* @property bool $is_voting_open
* @property \Cake\I18n\DateTime|null $voting_started_at Quiz: start of the voting window
* @property \Cake\I18n\DateTime|null $voting_ends_at Quiz: deadline (null = closed manually)
* @property string|null $stage Q&A: collect|vote|discuss (null = collect), see qaStage()
* @property int|null $focus_response_id Q&A: question currently being discussed
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime $modified
* @property \App\Model\Entity\Poll $poll
@@ -36,6 +38,7 @@ class Slide extends Entity
public const TYPE_CONTENT = 'content';
public const TYPE_QUIZ = 'quiz';
public const TYPE_YOUTUBE = 'youtube';
public const TYPE_QA = 'qa';
/**
* Quiz phases, see quizPhase().
@@ -51,6 +54,24 @@ class Slide extends Entity
*/
public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300];
/**
* Q&A stages, see qaStage(): participants submit questions, then upvote
* them, then the presenter discusses them one by one (most upvoted first).
*/
public const QA_COLLECT = 'collect';
public const QA_VOTE = 'vote';
public const QA_DISCUSS = 'discuss';
/**
* @var list<string>
*/
public const QA_STAGES = [self::QA_COLLECT, self::QA_VOTE, self::QA_DISCUSS];
/**
* Highest selectable number of upvotes per participant on a Q&A slide.
*/
public const QA_MAX_UPVOTES = 10;
/**
* Default settings per type. Unknown keys are dropped on save.
*
@@ -67,6 +88,8 @@ class Slide extends Entity
self::TYPE_QUIZ => ['time_limit' => 30],
// url as entered, video_id parsed from it, start in seconds
self::TYPE_YOUTUBE => ['url' => '', 'video_id' => '', 'start' => 0, 'autoplay' => false],
// upvotes per participant in the voting stage (1..QA_MAX_UPVOTES)
self::TYPE_QA => ['max_upvotes' => 3],
];
/**
@@ -91,6 +114,7 @@ class Slide extends Entity
self::TYPE_OPEN => __('Offene Frage'),
self::TYPE_SCALE => __('Skala'),
self::TYPE_QUIZ => __('Quiz'),
self::TYPE_QA => __('Fragen & Antworten'),
self::TYPE_CONTENT => __('Inhaltsfolie'),
self::TYPE_YOUTUBE => __('YouTube-Video'),
];
@@ -107,6 +131,7 @@ class Slide extends Entity
self::TYPE_OPEN => __('Freitext-Antworten, live als Liste.'),
self::TYPE_SCALE => __('Bewertung auf einer Skala, z. B. 1 bis 5.'),
self::TYPE_QUIZ => __('Frage mit richtiger Antwort und Zeitlimit, aufgelöst wird erst am Ende.'),
self::TYPE_QA => __('Teilnehmende reichen Fragen ein und wählen per Upvote, welche zuerst beantwortet werden.'),
self::TYPE_CONTENT => __('Nur Text anzeigen, ohne Abstimmung.'),
self::TYPE_YOUTUBE => __('Video in der Präsentation abspielen, Teilnehmende bekommen den Link zum Teilen.'),
];
@@ -199,6 +224,35 @@ class Slide extends Entity
return $this->type === self::TYPE_QUIZ;
}
/**
* @return bool
*/
public function isQa(): bool
{
return $this->type === self::TYPE_QA;
}
/**
* Stage of a Q&A slide (one of the QA_* constants), see QaService.
*
* @return string
*/
public function qaStage(): string
{
return in_array($this->stage, self::QA_STAGES, true) ? (string)$this->stage : self::QA_COLLECT;
}
/**
* Whether a participant may answer the slide several times (word cloud: one
* row per word, Q&A: questions and upvotes).
*
* @return bool
*/
public function allowsMultipleResponses(): bool
{
return in_array($this->type, [self::TYPE_WORDCLOUD, self::TYPE_QA], true);
}
/**
* Phase of a quiz: ready (not started yet), running, finished (time up or
* closed by the presenter). Results and correct answers are only revealed
+62
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Model\Table;
use App\Service\VoteService;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\Table;
/**
@@ -32,6 +33,67 @@ class ResponsesTable extends Table
$this->belongsTo('SlideOptions', ['foreignKey' => 'slide_option_id']);
}
/**
* Q&A questions of a slide (rows with text, without parent).
*
* @param int $slideId Slide id
* @return \Cake\ORM\Query\SelectQuery
*/
public function questionsOf(int $slideId): SelectQuery
{
return $this->find()->where([
'Responses.slide_id' => $slideId,
'Responses.parent_id IS' => null,
'Responses.text_value IS NOT' => null,
]);
}
/**
* Q&A progress of one participant on a slide.
*
* @param int $slideId Slide id
* @param string $participantHash Participant hash
* @return array{questions: list<int>, upvotes: list<int>} ids of own questions / question id of each own upvote (repeated per upvote)
*/
public function qaVotesOf(int $slideId, string $participantHash): array
{
$rows = $this->find()
->select(['id', 'parent_id'])
->where(['slide_id' => $slideId, 'participant_hash' => $participantHash])
->orderBy(['id' => 'ASC'])
->disableHydration()
->all();
$result = ['questions' => [], 'upvotes' => []];
foreach ($rows as $row) {
if ($row['parent_id'] === null) {
$result['questions'][] = (int)$row['id'];
} else {
$result['upvotes'][] = (int)$row['parent_id'];
}
}
return $result;
}
/**
* Upvotes per Q&A question of a slide.
*
* @param int $slideId Slide id
* @return array<int, int> question id => upvotes
*/
public function upvotesPerQuestion(int $slideId): array
{
return $this->find()
->select(['parent_id', 'n' => $this->find()->func()->count('*')])
->where(['slide_id' => $slideId, 'parent_id IS NOT' => null])
->groupBy(['parent_id'])
->disableHydration()
->all()
->combine(fn($row) => (int)$row['parent_id'], fn($row) => (int)$row['n'])
->toArray();
}
/**
* @param int $slideId Slide id
* @param string $participantHash Participant hash
+4
View File
@@ -159,6 +159,10 @@ class SlidesTable extends Table
$settings['time_limit'] = $limit;
}
break;
case Slide::TYPE_QA:
$max = (int)($input['max_upvotes'] ?? $settings['max_upvotes']);
$settings['max_upvotes'] = max(1, min(Slide::QA_MAX_UPVOTES, $max));
break;
case Slide::TYPE_YOUTUBE:
$url = mb_substr(trim((string)($input['url'] ?? '')), 0, 500);
$parsed = YouTubeService::parseUrl($url);