Add personal ranking mode to order slides and show image placement only with an image
CI / Deploy / PHP 8.4 (push) Failing after 1m28s
CI / Deploy / PHP 8.5 (push) Failing after 1m31s
CI / Deploy / test (push) Failing after 2s
CI / Deploy / deploy (push) Skipped

Order slides get a "ranking" setting without a correct solution: the stage shows
the live average ranking, participants only get a confirmation. The image
placement question in the slide form is only shown for an existing image or a
chosen file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-17 09:15:49 +01:00
1 parent 85627b364d
commit 0aac113f30
15 files changed
+239 -15

No files matched your search

+14 -2
View File
@@ -137,7 +137,9 @@ class Slide extends Entity
// allow_self_upvote: upvotes on own questions (for prioritizing topics, off by default)
self::TYPE_QA => ['upvote_share' => 25, 'max_upvotes_per_question' => 0, 'allow_self_upvote' => false],
// The correct order is the order of the slide_options (position), revealed when voting closes.
self::TYPE_ORDER => [],
// ranking: no correct order, everyone sorts by personal preference; the presenter sees the
// average ranking live (nothing to hide), participants never get results
self::TYPE_ORDER => ['ranking' => false],
];
/**
@@ -342,7 +344,17 @@ class Slide extends Entity
*/
public function isOrderRevealed(): bool
{
return $this->isOrder() && !$this->isVotingOpen();
return $this->isOrder() && !$this->isRanking() && !$this->isVotingOpen();
}
/**
* Ordering slide without a correct order (personal ranking, e.g. "sort by your importance").
*
* @return bool
*/
public function isRanking(): bool
{
return $this->isOrder() && (bool)$this->setting('ranking');
}
/**
+4 -1
View File
@@ -180,8 +180,11 @@ class SlidesTable extends Table
$view = $input['scale_view'] ?? null;
$settings['scale_view'] = in_array($view, Slide::SCALE_VIEWS, true) ? $view : Slide::SCALE_VIEW_BOTH;
break;
case Slide::TYPE_ORDER:
$settings['ranking'] = filter_var($input['ranking'] ?? false, FILTER_VALIDATE_BOOLEAN);
break;
case Slide::TYPE_QUIZ:
$limit = (int)($input['time_limit'] ?? $settings['time_limit']);
$limit =(int)($input['time_limit'] ?? $settings['time_limit']);
if (in_array($limit, Slide::QUIZ_TIME_LIMITS, true)) {
$settings['time_limit'] = $limit;
}
+2 -1
View File
@@ -284,7 +284,7 @@ class PollStateService
*
* @param \App\Model\Entity\Slide $slide Ordering slide incl. slide_options
* @param string $participantHash Participant hash
* @return array{revealed: bool, answer: list<int>|null, isCorrect: bool|null}
* @return array{ranking: bool, revealed: bool, answer: list<int>|null, isCorrect: bool|null}
*/
public function orderState(Slide $slide, string $participantHash): array
{
@@ -300,6 +300,7 @@ class PollStateService
$correct = $slide->optionIds();
return [
'ranking' => $slide->isRanking(),
'revealed' => $revealed,
'answer' => $answer,
'isCorrect' => $answer === null ? null : $answer === $correct,
+65
View File
@@ -97,6 +97,9 @@ class ResultsService
*/
protected function order(Slide $slide): array
{
if ($slide->isRanking()) {
return $this->ranking($slide);
}
if (!$slide->isOrderRevealed()) {
return [
'revealed' => false,
@@ -141,6 +144,68 @@ class ResultsService
return ['revealed' => true, 'items' => $items, 'correctCount' => $correctCount];
}
/**
* Personal ranking (no correct order): items by average position over all submitted orders,
* live while voting is open. `score` is 100 for a unanimous first place and 0 for a unanimous last place.
*
* @param \App\Model\Entity\Slide $slide Ordering slide with ranking setting
* @return array<string, mixed>
*/
protected function ranking(Slide $slide): array
{
$options = array_values($slide->slide_options ?? []);
$sums = array_fill_keys($slide->optionIds(), 0);
$total = 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 (count($given) !== count($sums)) {
continue;
}
$total++;
foreach ($given as $index => $id) {
if (isset($sums[$id])) {
$sums[$id] += $index + 1;
}
}
}
if ($total === 0) {
// Nobody has ranked yet: the entries in a neutral (shuffled) order, so the order of entry says nothing.
$items = array_map(fn($option) => [
'id' => $option->id,
'label' => $option->label,
'average' => null,
'score' => 0,
], $slide->shuffledOptions('slide:' . $slide->id));
return ['ranking' => true, 'revealed' => false, 'items' => $items];
}
$count = count($options);
$items = [];
foreach ($options as $option) {
$average = $sums[$option->id] / $total;
$items[] = [
'id' => $option->id,
'label' => $option->label,
'average' => round($average, 2),
'score' => $count < 2 ? 100 : round(($count - $average) / ($count - 1) * 100, 1),
];
}
// Best average first; usort is stable, so ties keep the order of the entries.
usort($items, fn($a, $b) => $a['average'] <=> $b['average']);
foreach ($items as $i => $item) {
$items[$i]['position'] = $i + 1;
}
return ['ranking' => true, 'revealed' => false, 'items' => $items];
}
/**
* @param \App\Model\Entity\Slide $slide Slide
* @param int|null $limit Max. comments (newest), null = all