From d6432911ede01502375a6b8b9c682bad8a0f98c5 Mon Sep 17 00:00:00 2001
From: Patrick Niebeling
Date: Sat, 21 Nov 2026 12:39:44 +0100
Subject: [PATCH] Add "Keine Angabe" to scales and an "Enthaltung" shortcut for
choice slides
Scales and star ratings get an optional "Keine Angabe" answer (setting
allow_skip). It counts as taking part but stays out of the average and
the distribution; the number is shown separately on stage, in the
evaluation and in the PDF. The choice form gets a button that appends an
"Enthaltung" option.
Co-Authored-By: Claude Sonnet 5.5
---
docs/slide-types.md | 7 +++
src/Controller/ParticipateController.php | 7 ++-
src/Model/Entity/Slide.php | 3 +-
src/Model/Table/SlidesTable.php | 1 +
src/Service/ResultsService.php | 10 +++-
src/Service/VoteService.php | 27 +++++++++
templates/Admin/export.php | 3 +
templates/Participate/view.php | 9 ++-
templates/Slides/answers.php | 2 +-
templates/Slides/form.php | 10 ++++
.../Controller/ParticipateControllerTest.php | 26 +++++++++
tests/TestCase/Service/VoteServiceTest.php | 45 +++++++++++++++
webroot/css/plenario.css | 1 +
webroot/js/plenario.js | 55 +++++++++++++++++--
14 files changed, 195 insertions(+), 11 deletions(-)
diff --git a/docs/slide-types.md b/docs/slide-types.md
index e2c47bc..bbadc75 100644
--- a/docs/slide-types.md
+++ b/docs/slide-types.md
@@ -146,6 +146,13 @@ geändert wird es nur über die Presenter-Steuerung (`SlideControlService`) bzw.
(`Results.scaleLayout()` / `Results.donut()`). Setting `scale_view` (`Slide::SCALE_VIEWS`: `both` | `average` | `chart`,
Dropdown im Formular) zeigt nur einen Teil, dann zentriert; im JSON `results.view`, die Daten bleiben vollständig.
Gilt nur für Presenter/Embed, Auswertung und PDF zeigen immer beides.
+- **Keine Angabe** (Setting `allow_skip`, Standard aus): zweiter Button neben „Absenden“ (`skip=1`, `formnovalidate`). `VoteService::scaleRows()`
+ speichert eine Zeile **ohne** `numeric_value` und ohne Kommentar: zählt als Teilnahme (einmal pro Person, `countParticipants`), geht aber nicht in
+ Verteilung und Durchschnitt ein. `ResultsService::scaleResults()` liefert die Zahl separat als `skipped` (Bühne: „· N× keine Angabe“ unter der
+ Bewertungszahl, Auswertung, PDF); private Folien strippen sie wie den Rest (`withoutContents()`). Ein Kommentar nachträglich geht nicht
+ (`editText()` lehnt ab, `VoteService::hasSkipped()` blendet das Formular aus). Tests: `VoteServiceTest`, `ParticipateControllerTest`.
+- **Enthaltung bei Auswahlfolien:** kein eigenes Feature, sondern eine normale Option (zählt in Prozenten mit, wie bei Vereinsabstimmungen üblich).
+ Im Folienformular fügt der Button „Option ‚Enthaltung‘ hinzufügen“ (`data-add-option`, `initAddOption()` in `plenario.js`, idempotent, nur mit JS sichtbar) die Zeile ein.
- **Antwort nachträglich bearbeiten** (gegen Tippfehler, `VoteService::hasEditableText()`): Antwort einer offenen Frage
(darf nicht leer werden) bzw. Kommentar einer Skala (ändern, ergänzen, leeren; die Bewertung bleibt unveränderlich),
nur solange die Abstimmung offen ist. `participate:edit` → `VoteService::editText()`, gleiche Vorbedingungen wie
diff --git a/src/Controller/ParticipateController.php b/src/Controller/ParticipateController.php
index 458ee28..8eb2739 100644
--- a/src/Controller/ParticipateController.php
+++ b/src/Controller/ParticipateController.php
@@ -93,11 +93,14 @@ class ParticipateController extends AppController
$slide = $poll->is_active ? $stateService->currentSlide($poll) : null;
$participantHash = $this->participantHash($poll);
$state = $stateService->forParticipant($poll, $participantHash, $slide);
+ $voteService = new VoteService();
$ownText = $slide !== null && VoteService::hasEditableText($slide) && $state['hasResponded']
- ? (new VoteService())->ownText($slide, $participantHash)
+ ? $voteService->ownText($slide, $participantHash)
: null;
+ // "Keine Angabe" has no rating to comment on
+ $skipped = $slide !== null && $state['hasResponded'] && $voteService->hasSkipped($slide, $participantHash);
- $this->set(compact('poll', 'slide', 'state', 'participantHash', 'ownText'));
+ $this->set(compact('poll', 'slide', 'state', 'participantHash', 'ownText', 'skipped'));
$this->setPollInterval();
}
diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php
index f766eb2..515e338 100644
--- a/src/Model/Entity/Slide.php
+++ b/src/Model/Entity/Slide.php
@@ -123,6 +123,7 @@ class Slide extends Entity
// private: internal feedback, ratings only visible in the admin area (never on the stage)
// comments: optional comment field, comments rotate in the presentation (unless private)
// comment_ratings: show the rating next to each comment in the presentation
+ // allow_skip: participants may answer "Keine Angabe" (row without numeric_value, not part of the average)
// (time per comment depends on its length, see Comments.delay() in plenario.js)
// style: numbers or stars (SCALE_*), stars always start at scale_min = 1
// scale_view: parts of the result shown in the presentation (presenter/embed, SCALE_VIEWS);
@@ -130,7 +131,7 @@ class Slide extends Entity
self::TYPE_SCALE => [
'style' => self::SCALE_NUMBERS,
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
- 'comments' => false, 'comment_ratings' => false,
+ 'comments' => false, 'comment_ratings' => false, 'allow_skip' => false,
'scale_view' => self::SCALE_VIEW_BOTH,
'time_limit' => 0,
],
diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php
index c45bc25..9038681 100644
--- a/src/Model/Table/SlidesTable.php
+++ b/src/Model/Table/SlidesTable.php
@@ -177,6 +177,7 @@ class SlidesTable extends Table
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
$settings['comments'] = filter_var($input['comments'] ?? false, FILTER_VALIDATE_BOOLEAN);
$settings['comment_ratings'] = filter_var($input['comment_ratings'] ?? false, FILTER_VALIDATE_BOOLEAN);
+ $settings['allow_skip'] = filter_var($input['allow_skip'] ?? false, FILTER_VALIDATE_BOOLEAN);
$view = $input['scale_view'] ?? null;
$settings['scale_view'] = in_array($view, Slide::SCALE_VIEWS, true) ? $view : Slide::SCALE_VIEW_BOTH;
break;
diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php
index 1737182..27cb9b1 100644
--- a/src/Service/ResultsService.php
+++ b/src/Service/ResultsService.php
@@ -21,6 +21,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool), 'stars' (bool: star rating, min = 1);
+ * 'skipped' (int: answers "Keine Angabe", setting allow_skip; not part of buckets/average);
* 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else [];
* 'value' is null unless the setting comment_ratings is on;
* 'view' (both|average|chart): parts shown in the presentation (setting scale_view,
@@ -486,6 +487,7 @@ class ResultsService
if (isset($results['buckets'])) {
$results['buckets'] = [];
$results['average'] = null;
+ $results['skipped'] = 0;
$results['comments'] = [];
}
@@ -530,7 +532,7 @@ class ResultsService
* Distribution and average of a scale.
*
* @param \App\Model\Entity\Slide $slide Scale slide
- * @return array{buckets: list, average: float|null, min: int, max: int, minLabel: string, maxLabel: string, stars: bool}
+ * @return array{buckets: list, average: float|null, min: int, max: int, minLabel: string, maxLabel: string, stars: bool, skipped: int}
*/
public function scaleResults(Slide $slide): array
{
@@ -545,6 +547,11 @@ class ResultsService
->combine('numeric_value', 'n')
->toArray();
+ // "Keine Angabe": taking part without a rating, never part of the average or the distribution
+ $skipped = $slide->setting('allow_skip')
+ ? $this->Responses->find()->where(['slide_id' => $slide->id, 'numeric_value IS' => null])->count()
+ : 0;
+
$total = 0;
$sum = 0;
foreach ($counts as $value => $count) {
@@ -569,6 +576,7 @@ class ResultsService
'minLabel' => (string)$slide->setting('min_label'),
'maxLabel' => (string)$slide->setting('max_label'),
'stars' => $slide->isStarRating(),
+ 'skipped' => $skipped,
];
}
}
diff --git a/src/Service/VoteService.php b/src/Service/VoteService.php
index 332fdb6..b921be0 100644
--- a/src/Service/VoteService.php
+++ b/src/Service/VoteService.php
@@ -179,6 +179,9 @@ class VoteService
default => __('Bitte gib zuerst deine Bewertung ab.'),
});
}
+ if ($slide->type === Slide::TYPE_SCALE && $row->numeric_value === null) {
+ throw new VoteException(__('Zu „Keine Angabe“ gibt es keinen Kommentar.'));
+ }
$row->text_value = $text;
$this->Responses->saveOrFail($row);
});
@@ -203,6 +206,22 @@ class VoteService
return $row['text_value'] ?? null;
}
+ /**
+ * Whether the participant answered a scale with "Keine Angabe" (a row without rating).
+ *
+ * @param \App\Model\Entity\Slide $slide Slide
+ * @param string $participantHash Participant hash
+ * @return bool
+ */
+ public function hasSkipped(Slide $slide, string $participantHash): bool
+ {
+ return $slide->type === Slide::TYPE_SCALE && $this->Responses->exists([
+ 'slide_id' => $slide->id,
+ 'participant_hash' => $participantHash,
+ 'numeric_value IS' => null,
+ ]);
+ }
+
/**
* Poll active, slide live and interactive, voting open.
*
@@ -682,6 +701,14 @@ class VoteService
*/
protected function scaleRows(Slide $slide, array $data): array
{
+ if (self::stringField($data, 'skip') === '1') {
+ if (!$slide->setting('allow_skip')) {
+ throw new VoteException(__('„Keine Angabe“ ist bei dieser Frage nicht möglich.'));
+ }
+
+ // Counts as taking part, but has no rating and no comment.
+ return [['numeric_value' => null, 'text_value' => null]];
+ }
$value = filter_var($data['value'] ?? null, FILTER_VALIDATE_INT);
$min = (int)$slide->setting('scale_min');
$max = (int)$slide->setting('scale_max');
diff --git a/templates/Admin/export.php b/templates/Admin/export.php
index 474f127..591e93b 100644
--- a/templates/Admin/export.php
+++ b/templates/Admin/export.php
@@ -205,6 +205,9 @@ $bar = function (float $percent, bool $ok = false): string {
= !empty($r['stars'])
? __('von {0} Sternen', (int)$r['max'])
: __('auf einer Skala von {0} bis {1}', (int)$r['min'], (int)$r['max']) ?>
+
+ · = __('{0}× „Keine Angabe“ (nicht im Durchschnitt)', (int)$r['skipped']) ?>
+
| = !empty($r['stars']) ? __('Sterne') : __('Wert') ?> | = __('Anzahl') ?> | = __('Anteil') ?> | |
diff --git a/templates/Participate/view.php b/templates/Participate/view.php
index 8aa0778..60ccca7 100644
--- a/templates/Participate/view.php
+++ b/templates/Participate/view.php
@@ -9,6 +9,7 @@
* @var array $state
* @var string $participantHash Seed for the shuffled items of ordering slides
* @var string|null $ownText Own open answer or scale comment (editable while voting is open)
+ * @var bool $skipped Whether the participant answered the scale with "Keine Angabe"
* @var int $pollIntervalMs
*/
use App\Service\VoteService;
@@ -241,7 +242,7 @@ $countdown = function (?int $remaining): string {
✓ = __('Deine Antwort ist angekommen.') ?>
- isVotingOpen()) :
+ isVotingOpen() && !$skipped) :
$isOpen = $slide->type === 'open'; ?>
@@ -342,6 +343,12 @@ $countdown = function (?int $remaining): string {
= $this->Form->button(__('Absenden'), ['class' => 'button button--primary button--block']) ?>
+ type === 'scale' && $slide->setting('allow_skip')) : ?>
+ = $this->Form->button(__('Keine Angabe'), [
+ 'name' => 'skip', 'value' => '1', 'formnovalidate' => true,
+ 'class' => 'button button--block button--skip',
+ ]) ?>
+
= $this->Form->end() ?>
diff --git a/templates/Slides/answers.php b/templates/Slides/answers.php
index 3210b80..e71510e 100644
--- a/templates/Slides/answers.php
+++ b/templates/Slides/answers.php
@@ -31,7 +31,7 @@ $count = match (true) {
= h($slide->question) ?>
- = __n('{0} Bewertung', '{0} Bewertungen', $count, $count) ?>
+ = __n('{0} Bewertung', '{0} Bewertungen', $count, $count) ?> · = __('{0}× „Keine Angabe“', (int)$scale['skipped']) ?>
= __n('{0} Kommentar, neueste zuerst', '{0} Kommentare, neueste zuerst', $count, $count) ?>
diff --git a/templates/Slides/form.php b/templates/Slides/form.php
index ef69db1..5023a0c 100644
--- a/templates/Slides/form.php
+++ b/templates/Slides/form.php
@@ -122,6 +122,10 @@ $optionsError = $slide->getError('options_text');
+
+
= h(implode(' ', (array)$optionsError)) ?>
@@ -191,6 +195,12 @@ $optionsError = $slide->getError('options_text');
'placeholder' => __('z. B. sehr'), 'value' => $settings['max_label'],
]) ?>
+ = $this->Form->control('settings.allow_skip', [
+ 'type' => 'checkbox',
+ 'label' => __('„Keine Angabe“ erlauben (Teilnehmende können die Frage überspringen)'),
+ 'checked' => (bool)$settings['allow_skip'],
+ ]) ?>
+ = __('Wer „Keine Angabe“ wählt, zählt als Teilnehmer/in, geht aber nicht in Durchschnitt und Verteilung ein. Die Zahl steht separat dabei.') ?>
= $this->Form->control('settings.scale_view', [
'type' => 'select',
'label' => __('In der Präsentation zeigen'),
diff --git a/tests/TestCase/Controller/ParticipateControllerTest.php b/tests/TestCase/Controller/ParticipateControllerTest.php
index 6608179..c5efd8f 100644
--- a/tests/TestCase/Controller/ParticipateControllerTest.php
+++ b/tests/TestCase/Controller/ParticipateControllerTest.php
@@ -238,4 +238,30 @@ class ParticipateControllerTest extends TestCase
$this->assertFlashMessage('Diese Antwort kann nicht mehr geändert werden.');
$this->assertFalse(TableRegistry::getTableLocator()->get('Responses')->exists(['text_value' => 'Hack']));
}
+
+ public function testScaleSkipButtonOnlyWithSetting(): void
+ {
+ [$poll] = $this->createPoll();
+ $slide = $this->createSlide($poll, Slide::TYPE_SCALE);
+ $this->goLive($poll, $slide);
+ $this->cookie('plenario_pid', self::PID);
+ $this->get('/p/' . $poll->join_code);
+ $this->assertResponseNotContains('Keine Angabe');
+
+ $slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['allow_skip' => true, 'comments' => true]]);
+ $this->goLive($poll, $slide);
+ $this->cookie('plenario_pid', self::PID);
+ $this->get('/p/' . $poll->join_code);
+ $this->assertResponseContains('name="skip"');
+
+ $this->cookie('plenario_pid', self::PID);
+ $this->post("/p/{$poll->join_code}/vote", ['slide_id' => $slide->id, 'skip' => '1']);
+ $this->assertFlashMessage('Danke für deine Antwort!');
+
+ // No rating, so no comment to add afterwards.
+ $this->cookie('plenario_pid', self::PID);
+ $this->get('/p/' . $poll->join_code);
+ $this->assertResponseContains('Deine Antwort ist angekommen.');
+ $this->assertResponseNotContains('Kommentar hinzufügen');
+ }
}
diff --git a/tests/TestCase/Service/VoteServiceTest.php b/tests/TestCase/Service/VoteServiceTest.php
index dfea7b8..29aac28 100644
--- a/tests/TestCase/Service/VoteServiceTest.php
+++ b/tests/TestCase/Service/VoteServiceTest.php
@@ -71,6 +71,51 @@ class VoteServiceTest extends TestCase
(new VoteService())->submit($poll, $slide, 'p1', ['value' => '4']);
}
+ public function testScaleSkipCountsAsParticipantButNotInAverage(): void
+ {
+ [$poll] = $this->createPoll();
+ $slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5, 'allow_skip' => true]]);
+ $poll = $this->goLive($poll, $slide);
+ $service = new VoteService();
+ $service->submit($poll, $slide, 'p1', ['value' => '4']);
+ $service->submit($poll, $slide, 'p2', ['skip' => '1']);
+
+ $results = (new ResultsService())->forSlide($slide);
+ $this->assertSame(2, $results['participants']);
+ $this->assertSame(1, $results['skipped']);
+ $this->assertSame(4.0, (float)$results['average']);
+ $this->assertSame(1, array_sum(array_column($results['buckets'], 'count')));
+ $this->assertTrue($service->hasSkipped($slide, 'p2'));
+ $this->assertFalse($service->hasSkipped($slide, 'p1'));
+
+ // Only once per person, like any answer.
+ $this->expectExceptionMessage('bereits abgestimmt');
+ $service->submit($poll, $slide, 'p2', ['value' => '2']);
+ }
+
+ public function testScaleSkipNeedsTheSetting(): void
+ {
+ [$poll] = $this->createPoll();
+ $slide = $this->createSlide($poll, Slide::TYPE_SCALE);
+ $poll = $this->goLive($poll, $slide);
+
+ $this->expectExceptionMessage('nicht möglich');
+ (new VoteService())->submit($poll, $slide, 'p1', ['skip' => '1']);
+ }
+
+ public function testScaleSkipHasNoComment(): void
+ {
+ [$poll] = $this->createPoll();
+ $slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['allow_skip' => true, 'comments' => true]]);
+ $poll = $this->goLive($poll, $slide);
+ $service = new VoteService();
+ $service->submit($poll, $slide, 'p1', ['skip' => '1', 'comment' => 'Ignoriert']);
+
+ $this->assertNull($service->ownText($slide, 'p1'));
+ $this->expectExceptionMessage('keinen Kommentar');
+ $service->editText($poll, $slide, 'p1', ['comment' => 'Nachtrag']);
+ }
+
public function testMultipleChoiceResults(): void
{
[$poll] = $this->createPoll();
diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css
index b509921..35d1d78 100644
--- a/webroot/css/plenario.css
+++ b/webroot/css/plenario.css
@@ -225,6 +225,7 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
.button--danger { color: var(--danger); }
.button--danger:hover { border-color: var(--danger); }
.button--ghost { border-color: transparent; background: transparent; }
+.button--skip { margin-top: 8px; }
.button--small { padding: 6px 10px; font-size: .85rem; }
.header-tools { display: flex; align-items: center; gap: 8px; }
.button--block { width: 100%; padding: 14px; font-size: 1.05rem; }
diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js
index ef59b72..1e53e2d 100644
--- a/webroot/js/plenario.js
+++ b/webroot/js/plenario.js
@@ -794,7 +794,11 @@
el('span', { class: 'average__of', text: ofText })
]),
visual,
- el('span', { class: 'average__count', text: total + (total === 1 ? ' Bewertung' : ' Bewertungen') })
+ el('span', {
+ class: 'average__count',
+ text: total + (total === 1 ? ' Bewertung' : ' Bewertungen')
+ + (results.skipped ? ' · ' + results.skipped + '× keine Angabe' : '')
+ })
]);
},
@@ -2841,6 +2845,45 @@
update();
}
+ // ------------------------------------------------------------------ quick option (choice form)
+
+ /**
+ * Button that appends a ready-made option (e.g. "Enthaltung") to the option textarea.
+ * Idempotent: an existing line with the same text is not added again; the maximum is respected.
+ */
+ function initAddOption(button) {
+ var area = document.getElementById(button.getAttribute('data-add-option-target'));
+ if (!area) {
+ return;
+ }
+ var label = button.getAttribute('data-add-option');
+ var max = parseInt(button.getAttribute('data-add-option-max'), 10) || 20;
+
+ function lines() {
+ return area.value.split(/\r?\n/).map(function (line) { return line.trim(); }).filter(Boolean);
+ }
+
+ function update() {
+ var current = lines();
+ var present = current.some(function (line) { return line.toLowerCase() === label.toLowerCase(); });
+ button.disabled = present || current.length >= max;
+ }
+
+ button.hidden = false;
+ button.addEventListener('click', function () {
+ var current = lines();
+ if (button.disabled) {
+ return;
+ }
+ current.push(label);
+ area.value = current.join('\n');
+ update();
+ area.focus();
+ });
+ area.addEventListener('input', update);
+ update();
+ }
+
// ------------------------------------------------------------------ theme switch
var THEME_ICONS = { auto: '◐', light: '☀', dark: '☾' };
@@ -3163,6 +3206,7 @@
root.querySelectorAll('[data-sortable]').forEach(initSortable);
root.querySelectorAll('[data-order-options]').forEach(initOrderOptions);
root.querySelectorAll('[data-scale-style]').forEach(initScaleStyle);
+ root.querySelectorAll('[data-add-option]').forEach(initAddOption);
}
// Flash messages: click hides them (delegated, no inline handlers because of the CSP).
@@ -3290,10 +3334,11 @@
if (event.defaultPrevented) {
return; // handled via fetch (word cloud)
}
- var button = form.querySelector('button[type=submit], button:not([type])');
- if (button) {
- setTimeout(function () { button.disabled = true; }, 0);
- }
+ // All buttons (e.g. "Absenden" and "Keine Angabe"); the pressed one is already part of the request.
+ var buttons = form.querySelectorAll('button[type=submit], button:not([type])');
+ setTimeout(function () {
+ buttons.forEach(function (button) { button.disabled = true; });
+ }, 0);
});
});
});