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

+34 -3
View File
@@ -49,10 +49,12 @@ class SlidesController extends AdminAppController
$slide->stage = $type === Slide::TYPE_QA ? Slide::QA_COLLECT : null;
$optionsText = $type === Slide::TYPE_CHOICE ? "\n" : '';
$quizOptions = [];
$orderOptions = [];
if ($this->request->is('post')) {
$optionsText = (string)$this->request->getData('options_text', '');
$quizOptions = $this->postedQuizOptions();
$orderOptions = $this->postedOrderOptions();
if ($this->saveSlide($slide, $optionsText)) {
$this->Flash->success(__('Folie angelegt.'));
@@ -60,7 +62,7 @@ class SlidesController extends AdminAppController
}
}
$this->set(compact('slide', 'optionsText', 'quizOptions'));
$this->set(compact('slide', 'optionsText', 'quizOptions', 'orderOptions'));
$this->render('form');
return null;
@@ -75,10 +77,12 @@ class SlidesController extends AdminAppController
$slide = $this->loadSlide($id);
$optionsText = implode("\n", array_map(fn($o) => $o->label, $slide->slide_options ?? []));
$quizOptions = array_map(fn($o) => ['label' => $o->label, 'correct' => $o->is_correct], $slide->slide_options ?? []);
$orderOptions = array_map(fn($o) => $o->label, $slide->slide_options ?? []);
if ($this->request->is(['post', 'put', 'patch'])) {
$optionsText = (string)$this->request->getData('options_text', '');
$quizOptions = $this->postedQuizOptions();
$orderOptions = $this->postedOrderOptions();
if ($this->saveSlide($slide, $optionsText)) {
$this->Flash->success(__('Folie gespeichert.'));
@@ -87,7 +91,7 @@ class SlidesController extends AdminAppController
}
$hasResponses = $this->Slides->Responses->exists(['slide_id' => $slide->id]);
$this->set(compact('slide', 'optionsText', 'quizOptions', 'hasResponses'));
$this->set(compact('slide', 'optionsText', 'quizOptions', 'orderOptions', 'hasResponses'));
$this->render('form');
return null;
@@ -215,6 +219,23 @@ class SlidesController extends AdminAppController
return $rows;
}
/**
* Item rows of an ordering slide as posted by the form (for re-rendering after errors).
*
* @return list<string>
*/
protected function postedOrderOptions(): array
{
$rows = [];
foreach ((array)$this->request->getData('order_options', []) as $label) {
if (is_scalar($label)) {
$rows[] = (string)$label;
}
}
return $rows;
}
/**
* Patches and saves a slide incl. its options.
*
@@ -253,6 +274,16 @@ class SlidesController extends AdminAppController
$slide->setError('quiz_options', __('Bitte markiere mindestens eine Antwort als richtig.'));
}
}
if ($slide->isOrder()) {
['labels' => $labels, 'duplicate' => $duplicate] = SlidesTable::parseOrderOptions(
(array)$this->request->getData('order_options', []),
);
if ($duplicate) {
$slide->setError('order_options', __('Jeder Eintrag darf nur einmal vorkommen, sonst ist die Reihenfolge nicht eindeutig.'));
} elseif (count($labels) < 2) {
$slide->setError('order_options', __('Bitte gib mindestens zwei Einträge an.'));
}
}
if ($slide->hasErrors()) {
$this->Flash->error(__('Bitte prüfe deine Eingaben.'));
@@ -263,7 +294,7 @@ class SlidesController extends AdminAppController
if (!$this->Slides->save($slide)) {
return false;
}
if ($slide->type === Slide::TYPE_CHOICE || $slide->isQuiz()) {
if ($slide->type === Slide::TYPE_CHOICE || $slide->isQuiz() || $slide->isOrder()) {
$this->Slides->syncOptions($slide, $labels, $correct);
}
if ($youtube['warning'] !== null) {