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
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
@@ -17,6 +18,8 @@ use Cake\ORM\Entity;
|
||||
* @property int $position
|
||||
* @property array<string, mixed>|null $settings
|
||||
* @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 \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime $modified
|
||||
* @property \App\Model\Entity\Poll $poll
|
||||
@@ -30,6 +33,21 @@ class Slide extends Entity
|
||||
public const TYPE_OPEN = 'open';
|
||||
public const TYPE_SCALE = 'scale';
|
||||
public const TYPE_CONTENT = 'content';
|
||||
public const TYPE_QUIZ = 'quiz';
|
||||
|
||||
/**
|
||||
* Quiz phases, see quizPhase().
|
||||
*/
|
||||
public const QUIZ_READY = 'ready';
|
||||
public const QUIZ_RUNNING = 'running';
|
||||
public const QUIZ_FINISHED = 'finished';
|
||||
|
||||
/**
|
||||
* Selectable quiz time limits in seconds (0 = presenter ends the quiz manually).
|
||||
*
|
||||
* @var list<int>
|
||||
*/
|
||||
public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300];
|
||||
|
||||
/**
|
||||
* Default settings per type. Unknown keys are dropped on save.
|
||||
@@ -43,6 +61,8 @@ class Slide extends Entity
|
||||
self::TYPE_OPEN => [],
|
||||
self::TYPE_SCALE => ['scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => ''],
|
||||
self::TYPE_CONTENT => [],
|
||||
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
|
||||
self::TYPE_QUIZ => ['time_limit' => 30],
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -66,6 +86,7 @@ class Slide extends Entity
|
||||
self::TYPE_WORDCLOUD => __('Wortwolke'),
|
||||
self::TYPE_OPEN => __('Offene Frage'),
|
||||
self::TYPE_SCALE => __('Skala'),
|
||||
self::TYPE_QUIZ => __('Quiz'),
|
||||
self::TYPE_CONTENT => __('Inhaltsfolie'),
|
||||
];
|
||||
}
|
||||
@@ -80,6 +101,7 @@ class Slide extends Entity
|
||||
self::TYPE_WORDCLOUD => __('Teilnehmende geben Begriffe ein oder unterstützen vorhandene, häufige werden größer.'),
|
||||
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_CONTENT => __('Nur Text anzeigen, ohne Abstimmung.'),
|
||||
];
|
||||
}
|
||||
@@ -102,6 +124,95 @@ class Slide extends Entity
|
||||
return $this->type !== self::TYPE_CONTENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether answers are accepted right now: voting is open and the deadline
|
||||
* of a timed quiz has not passed.
|
||||
*
|
||||
* @param \Cake\I18n\DateTime|null $now Reference time (default: now)
|
||||
* @return bool
|
||||
*/
|
||||
public function isVotingOpen(?DateTime $now = null): bool
|
||||
{
|
||||
if (!$this->is_voting_open) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->voting_ends_at === null || ($now ?? DateTime::now())->lessThan($this->voting_ends_at);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a timed quiz is still flagged open although its deadline has passed.
|
||||
*
|
||||
* @param \Cake\I18n\DateTime|null $now Reference time (default: now)
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired(?DateTime $now = null): bool
|
||||
{
|
||||
return $this->is_voting_open && !$this->isVotingOpen($now);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isQuiz(): bool
|
||||
{
|
||||
return $this->type === self::TYPE_QUIZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase of a quiz: ready (not started yet), running, finished (time up or
|
||||
* closed by the presenter). Results and correct answers are only revealed
|
||||
* when finished.
|
||||
*
|
||||
* @param \Cake\I18n\DateTime|null $now Reference time (default: now)
|
||||
* @return string One of the QUIZ_* constants
|
||||
*/
|
||||
public function quizPhase(?DateTime $now = null): string
|
||||
{
|
||||
if ($this->isVotingOpen($now)) {
|
||||
return self::QUIZ_RUNNING;
|
||||
}
|
||||
|
||||
return $this->voting_started_at === null ? self::QUIZ_READY : self::QUIZ_FINISHED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seconds left of a running timed quiz, null without time limit.
|
||||
*
|
||||
* @param \Cake\I18n\DateTime|null $now Reference time (default: now)
|
||||
* @return int|null
|
||||
*/
|
||||
public function remainingSeconds(?DateTime $now = null): ?int
|
||||
{
|
||||
if ($this->voting_ends_at === null) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isVotingOpen($now)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return max(0, $this->voting_ends_at->getTimestamp() - ($now ?? DateTime::now())->getTimestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens or closes voting. Opening a quiz that is not running (re)starts its
|
||||
* voting window and timer; opening a running quiz changes nothing.
|
||||
*
|
||||
* @param bool $open Open or close
|
||||
* @param \Cake\I18n\DateTime|null $now Reference time (default: now)
|
||||
* @return void
|
||||
*/
|
||||
public function setVotingOpen(bool $open, ?DateTime $now = null): void
|
||||
{
|
||||
$now ??= DateTime::now();
|
||||
if ($open && $this->isQuiz() && !$this->isVotingOpen($now)) {
|
||||
$limit = (int)$this->setting('time_limit');
|
||||
$this->voting_started_at = $now;
|
||||
$this->voting_ends_at = $limit > 0 ? $now->addSeconds($limit) : null;
|
||||
}
|
||||
$this->is_voting_open = $open;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings merged with the type defaults.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,7 @@ use Cake\ORM\Entity;
|
||||
* @property int $slide_id
|
||||
* @property string $label
|
||||
* @property int $position
|
||||
* @property bool $is_correct Quiz: correct answer (never expose before the quiz is finished)
|
||||
*/
|
||||
class SlideOption extends Entity
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user