Add an optional countdown to every slide that collects answers
CI / Deploy / PHP 8.4 (push) Successful in 1m18s
CI / Deploy / PHP 8.5 (push) Successful in 1m29s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

Choice, word cloud, open question, scale and ordering slides get a time
limit like the quiz. With a limit the slide waits ("ready") showing only
the question; next starts the countdown, the next one ends it, the third
moves on. Stage results and the ordering solution are withheld until the
countdown has started. The countdown music plays during any countdown.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-21 12:18:33 +01:00
1 parent 722e845cff
commit 27771e7470
19 files changed
+480 -34

No files matched your search

+6 -5
View File
@@ -323,7 +323,7 @@ class AdminController extends AdminAppController
* SlideControlService (open, close, toggle, stage, question).
*
* On a Q&A slide that is being discussed, next/prev step through the questions
* first (like builds in presentation software); on a quiz, next starts it and then ends it
* first (like builds in presentation software); on a slide with a countdown (quiz, or any slide with a time limit), next starts it and then ends it
* before moving on, on an open ordering slide next closes it (reveals the solution),
* prev always goes to the previous slide. While paused, next/prev resume
* the slide that was live before.
@@ -349,9 +349,10 @@ class AdminController extends AdminAppController
) {
$action = 'none';
}
// Forward on a quiz is a build step too: start it, then end it, only then the next slide.
// Back never touches the quiz, so a clicker can page through the slides afterwards.
if ($current !== null && $current->isQuiz() && $action === 'next') {
// Forward on a slide with a countdown (every quiz, any other slide with a time limit) is a build step too:
// start it, then end it, only then the next slide.
// Back never touches it, so a clicker can page through the slides afterwards.
if ($current !== null && $current->usesPhases() && $action === 'next') {
$phase = $current->quizPhase();
if ($phase !== Slide::QUIZ_FINISHED) {
(new SlideControlService())->apply($current, $phase === Slide::QUIZ_READY ? 'open' : 'close');
@@ -359,7 +360,7 @@ class AdminController extends AdminAppController
}
}
// Same for an ordering slide: forward first closes the voting (reveals the solution).
// An ordering slide without countdown: forward first closes the voting (reveals the solution).
if ($current !== null && $current->isOrder() && $action === 'next' && $current->isVotingOpen()) {
(new SlideControlService())->apply($current, 'close');
$action = 'none';
+6
View File
@@ -302,7 +302,13 @@ class SlidesController extends AdminAppController
// is_voting_open is presenter state (SlideControlService), never editable via the form.
$fields = ['type', 'question', 'description', 'settings'];
$youtube = $slide->isYouTube() ? $this->prepareYouTube($data) : ['errors' => [], 'warning' => null];
// A slide that has not been presented yet starts again after the (possibly changed) time limit is known:
// with a countdown it waits for the presenter, without it is open.
$fresh = $slide->isNew() || $slide->isFresh();
$this->Slides->patchEntity($slide, $data, ['fields' => $fields, 'associated' => []]);
if ($fresh) {
$slide->startFresh();
}
foreach ($youtube['errors'] as $field => $message) {
$slide->setError($field, $message);
}
+59 -11
View File
@@ -61,6 +61,13 @@ class Slide extends Entity
*/
public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300];
/**
* Selectable time limits of every slide with a countdown (same list as for quizzes).
*
* @var list<int>
*/
public const TIME_LIMITS = self::QUIZ_TIME_LIMITS;
/**
* Display styles of a scale: numbered steps or a star rating (always starts at 1 star).
*/
@@ -108,11 +115,11 @@ class Slide extends Entity
public const DEFAULT_SETTINGS = [
// comments: optional comment field (stored in text_value of the participant's first row),
// comments rotate in the presentation like those of a scale
self::TYPE_CHOICE => ['multiple' => false, 'comments' => false],
self::TYPE_CHOICE => ['multiple' => false, 'comments' => false, 'time_limit' => 0],
// allow_downvotes only takes effect together with allow_upvotes
self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true],
self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true, 'time_limit' => 0],
// private: anonymous feedback, answers only visible in the admin area (never on the stage)
self::TYPE_OPEN => ['private' => false],
self::TYPE_OPEN => ['private' => false, 'time_limit' => 0],
// private: internal feedback, ratings only visible in the admin area (never on the stage)
// comments: optional comment field, comments rotate in the presentation (unless private)
// comment_ratings: show the rating next to each comment in the presentation
@@ -125,6 +132,7 @@ class Slide extends Entity
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
'comments' => false, 'comment_ratings' => false,
'scale_view' => self::SCALE_VIEW_BOTH,
'time_limit' => 0,
],
self::TYPE_CONTENT => [],
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
@@ -136,10 +144,12 @@ class Slide extends Entity
// max_upvotes_per_question: own upvotes per question (0 = no limit besides the budget);
// allow_self_upvote: upvotes on own questions (for prioritizing topics, off by default)
self::TYPE_QA => ['upvote_share' => 25, 'max_upvotes_per_question' => 0, 'allow_self_upvote' => false],
// time_limit (all slides with answers but Q&A): seconds, 0 = no countdown. With a countdown the slide waits
// ("ready") until the presenter starts it, like a quiz (see usesPhases()).
// The correct order is the order of the slide_options (position), revealed when voting closes.
// ranking: no correct order, everyone sorts by personal preference; the presenter sees the
// average ranking live (nothing to hide), participants never get results
self::TYPE_ORDER => ['ranking' => false],
self::TYPE_ORDER => ['ranking' => false, 'time_limit' => 0],
];
/**
@@ -173,6 +183,20 @@ class Slide extends Entity
return $type !== self::TYPE_YOUTUBE;
}
/**
* Whether slides of this type can have a countdown: every type that collects answers except Q&A (its three
* stages take as long as the discussion needs). A quiz always has the ready/running/finished phases.
*
* @param string $type Slide type
* @return bool
*/
public static function supportsTimer(string $type): bool
{
return in_array($type, [
self::TYPE_CHOICE, self::TYPE_WORDCLOUD, self::TYPE_OPEN, self::TYPE_SCALE, self::TYPE_QUIZ, self::TYPE_ORDER,
], true);
}
/**
* @return bool
*/
@@ -344,7 +368,8 @@ class Slide extends Entity
*/
public function isOrderRevealed(): bool
{
return $this->isOrder() && !$this->isRanking() && !$this->isVotingOpen();
// Not yet started (phase "ready") is closed too, but nothing may be resolved before the countdown ran.
return $this->isOrder() && !$this->isRanking() && !$this->isVotingOpen() && $this->phase() !== self::QUIZ_READY;
}
/**
@@ -461,6 +486,28 @@ class Slide extends Entity
return in_array($this->type, [self::TYPE_WORDCLOUD, self::TYPE_QA], true);
}
/**
* Whether the slide goes through the phases ready (shows only the question), running (countdown, answers
* accepted) and finished: every quiz, and any other slide with a time limit.
*
* @return bool
*/
public function usesPhases(): bool
{
return $this->isQuiz() || (self::supportsTimer($this->type) && (int)$this->setting('time_limit') > 0);
}
/**
* Phase of a slide with a countdown (one of the QUIZ_* constants), null for slides without.
*
* @param \Cake\I18n\DateTime|null $now Reference time (default: now)
* @return string|null
*/
public function phase(?DateTime $now = null): ?string
{
return $this->usesPhases() ? $this->quizPhase($now) : null;
}
/**
* Phase of a quiz: ready (not started yet), running, finished (time up or
* closed by the presenter). Results and correct answers are only revealed
@@ -498,13 +545,14 @@ class Slide extends Entity
/**
* Sets the state of a slide that has not been presented yet (new slide, copy):
* a quiz waits for the presenter to start it, Q&A collects questions, others are open.
* a quiz or a slide with a countdown waits for the presenter to start it, Q&A collects questions,
* others are open.
*
* @return void
*/
public function startFresh(): void
{
$this->is_voting_open = !$this->isQuiz();
$this->is_voting_open = !$this->usesPhases();
$this->voting_started_at = null;
$this->voting_ends_at = null;
$this->stage = $this->isQa() ? self::QA_COLLECT : null;
@@ -519,7 +567,7 @@ class Slide extends Entity
*/
public function isFresh(): bool
{
return $this->is_voting_open === !$this->isQuiz()
return $this->is_voting_open === !$this->usesPhases()
&& $this->voting_started_at === null
&& $this->voting_ends_at === null
&& $this->stage === ($this->isQa() ? self::QA_COLLECT : null)
@@ -527,8 +575,8 @@ class Slide extends Entity
}
/**
* Opens or closes voting. Opening a quiz that is not running (re)starts its
* voting window and timer; opening a running quiz changes nothing.
* Opens or closes voting. Opening a slide with a countdown that is not running (re)starts its
* voting window and timer; opening a running one changes nothing.
*
* @param bool $open Open or close
* @param \Cake\I18n\DateTime|null $now Reference time (default: now)
@@ -537,7 +585,7 @@ class Slide extends Entity
public function setVotingOpen(bool $open, ?DateTime $now = null): void
{
$now ??= DateTime::now();
if ($open && $this->isQuiz() && !$this->isVotingOpen($now)) {
if ($open && $this->usesPhases() && !$this->isVotingOpen($now)) {
$limit = (int)$this->setting('time_limit');
$this->voting_started_at = $now;
$this->voting_ends_at = $limit > 0 ? $now->addSeconds($limit) : null;
+7 -4
View File
@@ -184,10 +184,7 @@ class SlidesTable extends Table
$settings['ranking'] = filter_var($input['ranking'] ?? false, FILTER_VALIDATE_BOOLEAN);
break;
case Slide::TYPE_QUIZ:
$limit = (int)($input['time_limit'] ?? $settings['time_limit']);
if (in_array($limit, Slide::QUIZ_TIME_LIMITS, true)) {
$settings['time_limit'] = $limit;
}
// The time limit is validated for every slide with a countdown below.
break;
case Slide::TYPE_QA:
$share = (int)($input['upvote_share'] ?? $settings['upvote_share']);
@@ -214,6 +211,12 @@ class SlidesTable extends Table
$settings['autoplay'] = filter_var($input['autoplay'] ?? false, FILTER_VALIDATE_BOOLEAN);
break;
}
if (Slide::supportsTimer($type)) {
$limit = (int)($input['time_limit'] ?? $settings['time_limit']);
$settings['time_limit'] = in_array($limit, Slide::TIME_LIMITS, true)
? $limit
: Slide::DEFAULT_SETTINGS[$type]['time_limit'];
}
return $settings;
}
+4 -2
View File
@@ -134,7 +134,7 @@ class PollStateService
'next' => $this->nextPreview($poll, $slides, $index),
'hiddenCount' => $this->Slides->find()->where(['poll_id' => $poll->id, 'is_hidden' => true])->count(),
'slide' => $current ? $this->slidePayload($current, $poll) : null,
'results' => $current ? $this->results->forSlide($current) : null,
'results' => $current ? $this->results->forStage($current) : null,
];
}
@@ -196,7 +196,7 @@ class PollStateService
'index' => null,
'count' => null,
'slide' => $this->slidePayload($slide, $poll),
'results' => $this->results->forSlide($slide),
'results' => $this->results->forStage($slide),
];
}
@@ -250,6 +250,8 @@ class PollStateService
]),
'slide' => $showResults ? $this->slidePayload($slide, $poll) : null,
'results' => $showResults ? $this->participantResults($slide) : null,
// Countdown of a slide that is not a quiz (a quiz has its own state below)
'timer' => $slide !== null && !$slide->isQuiz() && $slide->usesPhases() ? $this->results->timer($slide) : null,
'words' => $words,
'quiz' => $quiz,
'qa' => $qa,
+42
View File
@@ -78,6 +78,9 @@ class ResultsService
'type' => $slide->type,
'participants' => $slide->isInteractive() ? $this->Responses->countParticipants($slide->id) : 0,
];
if ($slide->usesPhases()) {
$result['timer'] = $this->timer($slide);
}
return $result + match ($slide->type) {
Slide::TYPE_CHOICE => $this->choice($slide, $limit),
@@ -91,6 +94,45 @@ class ResultsService
};
}
/**
* Results for the stage (presenter view and embed). A slide with a countdown that has not been started yet
* shows only its question: no answers, no counts, no solution (`ready`), whatever is stored for it.
* The evaluation (admin, PDF) uses forSlide(), which is never gated.
*
* @param \App\Model\Entity\Slide $slide Slide
* @return array<string, mixed>
*/
public function forStage(Slide $slide): array
{
if ($slide->phase() === Slide::QUIZ_READY && !$slide->isQuiz()) {
return [
'type' => $slide->type,
'participants' => 0,
'ready' => true,
'timer' => $this->timer($slide),
];
}
return $this->forSlide($slide);
}
/**
* Countdown of a slide: phase (ready|running|finished), the limit and the seconds left while running.
*
* @param \App\Model\Entity\Slide $slide Slide with a countdown
* @return array{phase: string|null, timeLimit: int, remaining: int|null}
*/
public function timer(Slide $slide): array
{
$phase = $slide->phase();
return [
'phase' => $phase,
'timeLimit' => (int)$slide->setting('time_limit'),
'remaining' => $phase === Slide::QUIZ_RUNNING ? $slide->remainingSeconds() : null,
];
}
/**
* @param \App\Model\Entity\Slide $slide Slide
* @return array<string, mixed>
+2
View File
@@ -226,6 +226,8 @@ class VoteService
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.'),
$slide->usesPhases() && $slide->voting_started_at === null => __('Die Abstimmung hat noch nicht begonnen.'),
$slide->usesPhases() => __('Die Zeit für diese Frage ist abgelaufen.'),
$slide->isQa() => __('Die Fragerunde läuft – Fragen und Stimmen sind nicht mehr möglich.'),
default => __('Die Abstimmung zu dieser Frage ist geschlossen.'),
});