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

+48
View File
@@ -28,6 +28,8 @@ use Cake\Utility\Security;
* only once per slide. `vote=up|remove` + `question_id` only while voting: upvote
* questions of others, at most `max_upvotes` in total, freely distributed (several
* on one question are allowed); `remove` withdraws one own upvote of the question.
* - ordering: `order` = all option ids, each exactly once, in the participant's order.
* Stored as one row with the ids comma separated in `text_value` (see parseOrder()).
*/
class VoteService
{
@@ -105,6 +107,7 @@ class VoteService
Slide::TYPE_SCALE => $this->scaleRows($slide, $data),
Slide::TYPE_QUIZ => $this->quizRows($slide, $data),
Slide::TYPE_QA => $this->qaRows($slide, $participantHash, $data),
Slide::TYPE_ORDER => $this->orderRows($slide, $data),
default => throw new VoteException(__('Unbekannter Folientyp.')),
};
@@ -159,6 +162,51 @@ class VoteService
return [['slide_option_id' => $id]];
}
/**
* @param \App\Model\Entity\Slide $slide Slide
* @param array<string, mixed> $data Request data
* @return list<array<string, mixed>>
*/
protected function orderRows(Slide $slide, array $data): array
{
$given = [];
foreach ((array)($data['order'] ?? []) as $id) {
$id = is_scalar($id) ? filter_var($id, FILTER_VALIDATE_INT) : false;
if ($id === false) {
$given = [];
break;
}
$given[] = $id;
}
$validIds = array_map(fn($option) => $option->id, $slide->slide_options ?? []);
$sortedGiven = $given;
sort($sortedGiven);
sort($validIds);
if ($validIds === [] || $sortedGiven !== $validIds) {
throw new VoteException(__('Bitte bring alle Einträge in eine Reihenfolge und sende sie erneut.'));
}
return [['text_value' => implode(',', $given)]];
}
/**
* Option ids of a stored ordering answer (`responses.text_value`), in the participant's order.
*
* @param string|null $text Stored answer
* @return list<int>
*/
public static function parseOrder(?string $text): array
{
$ids = [];
foreach (explode(',', (string)$text) as $id) {
if (ctype_digit(trim($id))) {
$ids[] = (int)$id;
}
}
return $ids;
}
/**
* Q&A: a new question while collecting, an upvote (or its withdrawal) while voting.
* Withdrawing deletes one upvote row and returns no new rows.