From 0aac113f303ddfc44b91e8bcce734816b0e68e74 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Tue, 17 Nov 2026 09:15:49 +0100 Subject: [PATCH 1/2] Add personal ranking mode to order slides and show image placement only with an image 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 --- docs/images.md | 2 +- docs/slide-types.md | 5 ++ src/Model/Entity/Slide.php | 16 ++++- src/Model/Table/SlidesTable.php | 5 +- src/Service/PollStateService.php | 3 +- src/Service/ResultsService.php | 65 ++++++++++++++++++++ templates/Admin/export.php | 21 ++++++- templates/Admin/index.php | 4 +- templates/Participate/view.php | 10 ++- templates/Slides/form.php | 11 +++- templates/element/slide_image_fields.php | 4 +- tests/TestCase/Controller/OrderSlideTest.php | 44 +++++++++++++ tests/TestCase/Controller/SlideImageTest.php | 15 +++++ tests/TestCase/Service/OrderTest.php | 2 +- webroot/js/plenario.js | 47 ++++++++++++++ 15 files changed, 239 insertions(+), 15 deletions(-) diff --git a/docs/images.md b/docs/images.md index d0427bb..8f43460 100644 --- a/docs/images.md +++ b/docs/images.md @@ -9,7 +9,7 @@ Ein Bild pro Folie: Upload, Verarbeitung, Auslieferung und Löschregeln. Ablage `{Plenario.images.path}/{poll_id}/{24 Hex}.webp` (Standard `data/uploads`, Docker `/data/uploads`) **außerhalb von `webroot/`**, ausgeliefert über `participate:image` (`/p/{code}/img/{file}`, auch für Presenter und Einbettung; nur Dateien dieser Umfrage, `immutable` gecacht, kein Cookie). Jedes neue Bild bekommt einen neuen Namen → neue URL, ersetzte Bilder sind sofort 404. - Eine Bildbeschreibung wird bewusst nicht abgefragt (`image_alt` bleibt `""`, die Spalte ist ungenutzt): Bilder sind Beamer-Dekoration. Nie Pflichtfelder zum Bild einführen, die den Upload verwerfen: das Dateifeld lässt sich nach einem Fehler nicht neu füllen. Layout `image_layout` (`top`|`side`|`full`, `full` nur + Eine Bildbeschreibung wird bewusst nicht abgefragt (`image_alt` bleibt `""`, die Spalte ist ungenutzt): Bilder sind Beamer-Dekoration. Nie Pflichtfelder zum Bild einführen, die den Upload verwerfen: das Dateifeld lässt sich nach einem Fehler nicht neu füllen. Die Frage nach der Platzierung (`data-image-layout`) blendet `initImageFields()` nur ein, wenn ein Bild vorhanden (und nicht zum Entfernen markiert) oder eine Datei gewählt ist; ohne JavaScript bleibt sie sichtbar. Layout `image_layout` (`top`|`side`|`full`, `full` nur Inhaltsfolien, `null` = Standard je Typ: Inhaltsfolie `side`, sonst `top`; `Slide::imageLayout()`); `side` gilt nur für die Bühne (CSS `stage--img-*`), Teilnehmende sehen das Bild immer oben (`element/slide_image`). Kontingent `Plenario.images.maxPerPoll` Folien mit Bild. Im State steht `slide.image` = `{url, alt, layout, width, height}` (`PollStateService::slidePayload()`). diff --git a/docs/slide-types.md b/docs/slide-types.md index 049111b..98ebd21 100644 --- a/docs/slide-types.md +++ b/docs/slide-types.md @@ -80,6 +80,11 @@ Details zu den einzelnen Folientypen. Übersicht und zentrale Regeln stehen in [ Vorher landen weder richtige Reihenfolge noch Zählungen im JSON (Presenter sieht die Einträge gemischt mit Seed `slide:{id}`); danach sieht der Presenter die Lösung inkl. „X von N komplett richtig“ und je Eintrag, wie oft er an der richtigen Stelle lag; Teilnehmende nur die Lösung mit eigenen Platzierungen und `order.isCorrect`. Tests: `OrderTest.php`, `OrderSlideTest.php`. +- **Persönliche Rangfolge** (Setting `ranking`, `Slide::isRanking()`): keine richtige Lösung („Sortiere nach deiner Wichtigkeit“). + Gespeichert wird wie sonst (`order[]`), die Reihenfolge der Einträge im Editor zählt nicht. `isOrderRevealed()` ist dann nie wahr: + Teilnehmende bekommen weder `results` noch Urteil (`order.ranking` steuert die Texte), nur die Bestätigung. Der Presenter sieht live + (auch bei offener Abstimmung, es gibt nichts zu verbergen) `ResultsService::ranking()`: Einträge nach durchschnittlichem Platz + (`average`, `score` 0–100 für den Balken, `position`); ohne Antworten gemischt. Export/Admin-Liste haben eigene Zweige. ## Skala, Sterne und Kommentare diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 078d811..5cc90ce 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -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'); } /** diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index b0408b1..a0c49e8 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -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; } diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index 53ec116..e7323cc 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -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|null, isCorrect: bool|null} + * @return array{ranking: bool, revealed: bool, answer: list|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, diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index e978c71..81a0b10 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -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 + */ + 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 diff --git a/templates/Admin/export.php b/templates/Admin/export.php index ec5d516..3bed113 100644 --- a/templates/Admin/export.php +++ b/templates/Admin/export.php @@ -137,7 +137,26 @@ $bar = function (float $percent, bool $ok = false): string { type === 'order') : ?> - + + +

+ +

+ + + + + + + + + + + + +
.
+ +

diff --git a/templates/Admin/index.php b/templates/Admin/index.php index beeb226..e55ce73 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -118,6 +118,8 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide- $perQuestion = (int)$slide->setting('max_upvotes_per_question'); ?> setting('upvote_share')) ?> 0 ? ' · ' . __n('{0} pro Frage', '{0} pro Frage', $perQuestion, $perQuestion) : '' ?>setting('allow_self_upvote') ? ' · ' . __('auch für eigene Fragen') : '' ?> + isRanking()) : ?> + · is_voting_open ? __('Persönliche Rangfolge') : __('Persönliche Rangfolge, Abstimmung geschlossen') ?> isOrder() && !$slide->is_voting_open) : ?> · is_voting_open) : ?>· @@ -134,7 +136,7 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide- $slide->slide_options, ))) ?>

isOrder() && $slide->slide_options) : ?> -

isRanking() ? ' · ' : ' → ', array_map( fn($o) => $o->label, $slide->slide_options, ))) ?>

diff --git a/templates/Participate/view.php b/templates/Participate/view.php index 155b15b..9743379 100644 --- a/templates/Participate/view.php +++ b/templates/Participate/view.php @@ -161,14 +161,20 @@ $countdown = function (?int $remaining): string {

+ isVotingOpen()) : ?> +

✓

-

+ +

+ shuffledOptions($participantHash); ?> Form->create(null, ['url' => $voteUrl, 'class' => 'vote-form order-form', 'data-order-form' => true]) ?> Form->hidden('slide_id', ['value' => $slide->id]) ?> -

+

    $option) : ?> diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 9d89d10..8d3663b 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -278,8 +278,8 @@ $optionsError = $slide->getError('options_text'); ?>
    - -

    + +

      $label) : ?> @@ -303,7 +303,12 @@ $optionsError = $slide->getError('options_text');

    -

    + Form->control('settings.ranking', [ + 'type' => 'checkbox', + 'label' => __('Persönliche Rangfolge: keine richtige Lösung (z. B. „Sortiere nach deiner Wichtigkeit“)'), + 'checked' => (bool)$settings['ranking'], + ]) ?> +

    type === 'qa') : $upvoteOptions = []; foreach (range(1, \App\Model\Entity\Slide::QA_MAX_UPVOTES) as $n) { diff --git a/templates/element/slide_image_fields.php b/templates/element/slide_image_fields.php index cec8ebf..4731cb4 100644 --- a/templates/element/slide_image_fields.php +++ b/templates/element/slide_image_fields.php @@ -32,7 +32,7 @@ if ($slide->type === Slide::TYPE_CONTENT) { $imageError = $slide->getError('image'); $maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024); ?> -
    +
    >

    @@ -71,7 +71,7 @@ $maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 *
    -
    +
    Form->radio('image_layout', array_map( fn($value, $text) => ['value' => $value, 'text' => $text], diff --git a/tests/TestCase/Controller/OrderSlideTest.php b/tests/TestCase/Controller/OrderSlideTest.php index 2b406fb..3a25036 100644 --- a/tests/TestCase/Controller/OrderSlideTest.php +++ b/tests/TestCase/Controller/OrderSlideTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace App\Test\TestCase\Controller; use App\Model\Entity\Slide; +use App\Service\PollStateService; +use App\Service\ResultsService; use App\Test\TestCase\PlenarioTestTrait; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; @@ -90,4 +92,46 @@ class OrderSlideTest extends TestCase $this->assertStringContainsString('1 von 1', $html); $this->assertStringContainsString('komplett richtig sortiert', $html); } + + public function testRankingHasNoSolutionAndShowsAverageOrder(): void + { + [$poll, $token] = $this->createPoll(); + $this->post("/admin/$token/slides/add?type=order", [ + 'type' => 'order', 'question' => 'Was ist dir wichtig?', 'is_voting_open' => '1', + 'settings' => ['ranking' => '1'], 'order_options' => ['Eins', 'Zwei', 'Drei'], + ]); + $slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->contain(['SlideOptions'])->firstOrFail(); + $this->assertTrue($slide->isRanking()); + $this->goLive($poll, $slide); + [$a, $b, $c] = array_map(fn($o) => $o->id, $slide->slide_options); + + // Two people rank Drei first; the stored order of the entries has no meaning. + foreach (['c' => [$c, $a, $b], 'd' => [$c, $b, $a]] as $pid => $order) { + $this->cookie('plenario_pid', str_repeat($pid, 32)); + $this->post('/p/' . $poll->join_code . '/vote', ['slide_id' => $slide->id, 'order' => $order]); + } + + // Participant: confirmation only, no results, no verdict - even after closing. + $this->get('/p/' . $poll->join_code); + $this->assertResponseContains('Deine Reihenfolge ist angekommen.'); + $this->assertResponseNotContains('Auflösung gibt es'); + $this->post("/admin/$token/control", ['action' => 'toggle']); + $this->get('/p/' . $poll->join_code); + $this->assertResponseNotContains('deine Reihenfolge stimmt'); + $this->assertResponseNotContains('Leider'); + $state = (new PollStateService())->forParticipant($this->pollsTable()->get($poll->id), str_repeat('c', 32)); + $this->assertNull($state['results']); + $this->assertFalse($state['order']['revealed']); + + // Presenter/export: items by average position, Drei first. + $results = (new ResultsService())->forSlide($this->slidesTable()->get($slide->id, contain: ['SlideOptions'])); + $this->assertTrue($results['ranking']); + // Eins and Zwei tie at 2.5 and keep the order of the entries. + $this->assertSame(['Drei', 'Eins', 'Zwei'], array_column($results['items'], 'label')); + $this->assertSame(1.0, (float)$results['items'][0]['average']); + $this->assertSame(100.0, (float)$results['items'][0]['score']); + + $html = $this->exportHtml($token); + $this->assertStringContainsString('persönliche Rangfolgen', $html); + } } diff --git a/tests/TestCase/Controller/SlideImageTest.php b/tests/TestCase/Controller/SlideImageTest.php index 81adbb7..a14a466 100644 --- a/tests/TestCase/Controller/SlideImageTest.php +++ b/tests/TestCase/Controller/SlideImageTest.php @@ -66,6 +66,21 @@ class SlideImageTest extends TestCase $this->assertSame([$slide->image], $this->storedImages($poll->id)); } + public function testPlacementIsOnlyOfferedWithAnImage(): void + { + [$poll, $token, $slide] = $this->slideWithImage(); + $empty = $this->createSlide($poll, Slide::TYPE_CONTENT, ['question' => 'Ohne Bild']); + + // The placement fieldset is always rendered (usable without JavaScript); the script shows it only + // for an existing image or a chosen file, marked by data-has-image. + $this->get("/admin/$token/slides/{$slide->id}/edit"); + $this->assertResponseContains('data-image-layout'); + $this->assertResponseContains('data-has-image'); + $this->get("/admin/$token/slides/{$empty->id}/edit"); + $this->assertResponseContains('data-image-layout'); + $this->assertResponseNotContains('data-has-image'); + } + public function testLayoutDefaultsByType(): void { [$poll, , $content] = $this->slideWithImage(); diff --git a/tests/TestCase/Service/OrderTest.php b/tests/TestCase/Service/OrderTest.php index 1dbb004..5472624 100644 --- a/tests/TestCase/Service/OrderTest.php +++ b/tests/TestCase/Service/OrderTest.php @@ -129,7 +129,7 @@ class OrderTest extends TestCase $state = $this->participantState($poll, 'p1'); $this->assertTrue($state['hasResponded']); $this->assertNull($state['results']); - $this->assertSame(['revealed' => false, 'answer' => null, 'isCorrect' => null], $state['order']); + $this->assertSame(['ranking' => false, 'revealed' => false, 'answer' => null, 'isCorrect' => null], $state['order']); } public function testClosingRevealsResultsToEveryone(): void diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 501bdbc..e2579e0 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -947,6 +947,31 @@ */ order: function (results, options) { var answer = options && options.order ? options.order.answer : null; + if (results.ranking) { + // Personal ranking: no solution, the average of all submitted orders (live, stage only). + if (results.participants === 0) { + return el('div', { class: 'order-results' }, [ + el('p', { class: 'quiz-status', text: 'Die Teilnehmenden sortieren nach ihrer persönlichen Einschätzung' }), + el('ul', { class: 'quiz-grid' }, results.items.map(function (item, index) { + return el('li', { class: 'quiz-tile quiz-tile--c' + (index % 6), text: item.label }); + })) + ]); + } + return el('div', { class: 'order-results order-results--ranking' }, [ + el('ol', { class: 'order-solution' }, results.items.map(function (item) { + return el('li', { class: 'bar order-solution__item' }, [ + el('div', { class: 'bar__label' }, [ + el('span', { class: 'order-solution__pos', text: item.position + '.' }), + document.createTextNode(' ' + item.label) + ]), + el('div', { class: 'bar__track' }, [ + el('div', { class: 'bar__fill', style: 'width:' + item.score + '%' }) + ]), + el('div', { class: 'bar__value', text: 'Ø Platz ' + formatNumber(item.average) }) + ]); + })) + ]); + } if (!results.revealed) { return el('div', { class: 'order-results' }, [ el('p', { class: 'quiz-status', text: 'Die Teilnehmenden sortieren – aufgelöst wird beim Schließen der Abstimmung' }), @@ -2281,6 +2306,27 @@ }); } + /** + * Slide image: the placement question only makes sense with an image, i.e. an existing one that is not + * marked for removal, or a newly selected file. Without JavaScript it stays visible. + */ + function initImageFields(box) { + var layout = box.querySelector('[data-image-layout]'); + var file = box.querySelector('input[type="file"]'); + var remove = box.querySelector('input[name="remove_image"]'); + if (!layout || !file) { + return; + } + var hasImage = box.hasAttribute('data-has-image'); + function update() { + var removed = !!remove && remove.checked; + layout.hidden = !(file.files && file.files.length > 0) && !(hasImage && !removed); + } + box.addEventListener('change', update); + box.addEventListener('click', update); + update(); + } + /** Quiz slide form: add further answer rows (the server renders a few already). */ function initQuizOptions(fieldset) { var list = fieldset.querySelector('[data-quiz-list]'); @@ -2922,6 +2968,7 @@ root.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm); root.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions); root.querySelectorAll('[data-image-remove]').forEach(initImageRemove); + root.querySelectorAll('[data-image-fields]').forEach(initImageFields); root.querySelectorAll('[data-sortable]').forEach(initSortable); root.querySelectorAll('[data-order-options]').forEach(initOrderOptions); root.querySelectorAll('[data-scale-style]').forEach(initScaleStyle); From 4dcddd15e78242ff4a2c7bc5ea890dfbec6780c4 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Tue, 17 Nov 2026 09:18:47 +0100 Subject: [PATCH 2/2] Fix coding standard in SlidesTable::sanitizeSettings Co-Authored-By: Claude Sonnet 5.5 --- src/Model/Table/SlidesTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index a0c49e8..074f980 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -184,7 +184,7 @@ class SlidesTable extends Table $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; }