Add ordering slide type
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:
1 parent
4eed568a64
commit
918e077734
17 files changed
+922
-95
No files matched your search
@@ -305,6 +305,7 @@ class AdminController extends AdminAppController
|
||||
foreach ($responses as $response) {
|
||||
$texts[$response->id] = (string)$response->text_value;
|
||||
$answer = match (true) {
|
||||
$slide->isOrder() => $this->orderAnswer($slide, $labels, (string)$response->text_value),
|
||||
$response->parent_id !== null => __('Upvote: {0}', $texts[$response->parent_id] ?? ''),
|
||||
$response->slide_option_id !== null => $labels[$response->slide_option_id] ?? '',
|
||||
$response->text_value !== null && $response->numeric_value === VoteService::DOWNVOTE
|
||||
@@ -335,6 +336,26 @@ class AdminController extends AdminAppController
|
||||
->withStringBody($csv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ordering answer for the CSV export, e.g. "A → C → B (falsch)".
|
||||
*
|
||||
* @param \App\Model\Entity\Slide $slide Ordering slide incl. slide_options
|
||||
* @param array<int, string> $labels Option labels by id
|
||||
* @param string $text Stored answer (option ids)
|
||||
* @return string
|
||||
*/
|
||||
protected function orderAnswer(Slide $slide, array $labels, string $text): string
|
||||
{
|
||||
$given = VoteService::parseOrder($text);
|
||||
$correct = array_map(fn($option) => $option->id, array_values($slide->slide_options ?? []));
|
||||
|
||||
return __(
|
||||
'{0} ({1})',
|
||||
implode(' → ', array_map(fn(int $id) => $labels[$id] ?? '?', $given)),
|
||||
$given === $correct ? __('richtig') : __('falsch'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents CSV/formula injection in spreadsheet programs.
|
||||
*
|
||||
|
||||
@@ -85,9 +85,10 @@ class ParticipateController extends AppController
|
||||
$poll = $this->loadPoll($code);
|
||||
$stateService = new PollStateService();
|
||||
$slide = $poll->is_active ? $stateService->currentSlide($poll) : null;
|
||||
$state = $stateService->forParticipant($poll, $this->participantHash($poll));
|
||||
$participantHash = $this->participantHash($poll);
|
||||
$state = $stateService->forParticipant($poll, $participantHash);
|
||||
|
||||
$this->set(compact('poll', 'slide', 'state'));
|
||||
$this->set(compact('poll', 'slide', 'state', 'participantHash'));
|
||||
$this->set('pollIntervalMs', (int)Configure::read('Plenario.pollIntervalMs', 2000));
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user