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
@@ -25,6 +25,11 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
* once finished additionally per option 'count', 'percent', 'correct' (bool)
|
||||
* and 'correctCount' (participants with a correct answer).
|
||||
* Counts and correct answers are NEVER part of the result before the quiz is finished.
|
||||
* - order: 'revealed' (bool, = voting closed); while not revealed 'items' => [['id', 'label']]
|
||||
* in a fixed shuffled order (never the solution); once revealed 'items' in the correct
|
||||
* order with 'position' (1-based), 'placed' (participants who put the item at its position),
|
||||
* 'percent', plus 'correctCount' (participants with the completely correct order).
|
||||
* Neither the correct order nor counts are part of the result before it is revealed.
|
||||
* - qa: 'stage' (collect|vote|discuss), 'maxUpvotes', 'upvotes' (total),
|
||||
* 'questions' => [['id', 'text', 'votes']] most upvoted first (ties: oldest first),
|
||||
* 'focusId' (question being discussed|null), 'focusIndex' (0-based position in questions|null).
|
||||
@@ -66,10 +71,61 @@ class ResultsService
|
||||
Slide::TYPE_SCALE => $this->scale($slide),
|
||||
Slide::TYPE_QUIZ => $this->quiz($slide),
|
||||
Slide::TYPE_QA => $this->qa($slide),
|
||||
Slide::TYPE_ORDER => $this->order($slide),
|
||||
default => [],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function order(Slide $slide): array
|
||||
{
|
||||
if (!$slide->isOrderRevealed()) {
|
||||
return [
|
||||
'revealed' => false,
|
||||
'items' => array_map(fn($option) => [
|
||||
'id' => $option->id,
|
||||
'label' => $option->label,
|
||||
], $slide->shuffledOptions('slide:' . $slide->id)),
|
||||
];
|
||||
}
|
||||
|
||||
$correct = array_map(fn($option) => $option->id, array_values($slide->slide_options ?? []));
|
||||
$placed = array_fill_keys($correct, 0);
|
||||
$correctCount = 0;
|
||||
$answers = $this->Responses->find()
|
||||
->select(['text_value'])
|
||||
->where(['slide_id' => $slide->id, 'text_value IS NOT' => null])
|
||||
->disableHydration()
|
||||
->all();
|
||||
foreach ($answers as $row) {
|
||||
$given = VoteService::parseOrder($row['text_value']);
|
||||
if ($given === $correct) {
|
||||
$correctCount++;
|
||||
}
|
||||
foreach ($correct as $index => $id) {
|
||||
if (($given[$index] ?? null) === $id) {
|
||||
$placed[$id]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$total = count($answers);
|
||||
$items = [];
|
||||
foreach (array_values($slide->slide_options ?? []) as $index => $option) {
|
||||
$items[] = [
|
||||
'id' => $option->id,
|
||||
'label' => $option->label,
|
||||
'position' => $index + 1,
|
||||
'placed' => $placed[$option->id],
|
||||
'percent' => $total > 0 ? round($placed[$option->id] / $total * 100, 1) : 0,
|
||||
];
|
||||
}
|
||||
|
||||
return ['revealed' => true, 'items' => $items, 'correctCount' => $correctCount];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @return array<string, mixed>
|
||||
|
||||
Reference in new issue
Block a user