Add ordering slide type
CI / Deploy / test (push) Successful in 50s
CI / Deploy / deploy (push) Skipped

Participants bring shuffled items into the correct order and submit it
once. The admin enters the items in the correct order and can reorder
them by drag & drop or arrow keys. Closing the voting reveals the
solution: how many got it completely right and how often each item was
placed correctly; participants see whether their order was right.

The drag & drop mechanics of the slide list are extracted into a
reusable makeSortable() helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 16:47:37 +01:00
1 parent 4eed568a64
commit 918e077734
17 files changed
+922 -95

No files matched your search

+47
View File
@@ -39,6 +39,7 @@ class Slide extends Entity
public const TYPE_QUIZ = 'quiz';
public const TYPE_YOUTUBE = 'youtube';
public const TYPE_QA = 'qa';
public const TYPE_ORDER = 'order';
/**
* Quiz phases, see quizPhase().
@@ -91,6 +92,8 @@ class Slide extends Entity
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],
// The correct order is the order of the slide_options (position), revealed when voting closes.
self::TYPE_ORDER => [],
];
/**
@@ -115,6 +118,7 @@ class Slide extends Entity
self::TYPE_OPEN => __('Offene Frage'),
self::TYPE_SCALE => __('Skala'),
self::TYPE_QUIZ => __('Quiz'),
self::TYPE_ORDER => __('Reihenfolge'),
self::TYPE_QA => __('Fragen & Antworten'),
self::TYPE_CONTENT => __('Inhaltsfolie'),
self::TYPE_YOUTUBE => __('YouTube-Video'),
@@ -132,6 +136,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_ORDER => __('Einträge in die richtige Reihenfolge bringen, aufgelöst wird beim Schließen der Abstimmung.'),
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.'),
@@ -233,6 +238,48 @@ class Slide extends Entity
return $this->type === self::TYPE_QA;
}
/**
* @return bool
*/
public function isOrder(): bool
{
return $this->type === self::TYPE_ORDER;
}
/**
* Ordering slide whose solution may be shown: voting is closed. While voting
* is open, neither the correct order nor any counts may leave the server.
*
* @return bool
*/
public function isOrderRevealed(): bool
{
return $this->isOrder() && !$this->isVotingOpen();
}
/**
* Options of an ordering slide in a stable pseudo-random order (same seed =
* same order, e.g. per participant across reloads). With two or more options
* the result never equals the correct order.
*
* @param string $seed Seed, e.g. participant hash or "slide:{id}"
* @return list<\App\Model\Entity\SlideOption>
*/
public function shuffledOptions(string $seed): array
{
$options = array_values($this->slide_options ?? []);
$correct = array_map(fn($option) => $option->id, $options);
usort($options, fn($a, $b) => strcmp(
hash('sha256', $seed . '|' . $a->id),
hash('sha256', $seed . '|' . $b->id),
));
if (count($options) > 1 && array_map(fn($option) => $option->id, $options) === $correct) {
$options[] = array_shift($options);
}
return $options;
}
/**
* Stage of a Q&A slide (one of the QA_* constants), see QaService.
*
+27
View File
@@ -23,6 +23,7 @@ class SlidesTable extends Table
{
public const MAX_OPTIONS = 20;
public const MAX_QUIZ_OPTIONS = 10;
public const MAX_ORDER_OPTIONS = 10;
/**
* @param array<string, mixed> $config The configuration for the Table.
@@ -233,6 +234,32 @@ class SlidesTable extends Table
return ['labels' => $labels, 'correct' => $correct];
}
/**
* Parses the item rows of an ordering slide (`order_options[]`, in the correct order).
* Empty rows are skipped; a repeated label is reported, because it would make the order ambiguous.
*
* @param array<mixed> $rows Raw form rows (labels)
* @return array{labels: list<string>, duplicate: bool}
*/
public static function parseOrderOptions(array $rows): array
{
$labels = [];
$duplicate = false;
foreach ($rows as $row) {
$label = is_scalar($row) ? mb_substr(trim((string)$row), 0, 255) : '';
if ($label === '' || count($labels) >= self::MAX_ORDER_OPTIONS) {
continue;
}
if (in_array($label, $labels, true)) {
$duplicate = true;
continue;
}
$labels[] = $label;
}
return ['labels' => $labels, 'duplicate' => $duplicate];
}
/**
* Persists the end of a timed quiz once its deadline has passed. Safe to
* call repeatedly (no-op unless the slide is still flagged open).