From ecb8f9d31c97d14bed51e0a9ab60d5cc7e835753 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Sun, 8 Nov 2026 19:33:52 +0100 Subject: [PATCH] Make private slides start with hidden results instead of withholding them Anonymous/internal feedback now only presets "hide results" on the stage: presenter and embed get the full results flagged private and can show them on demand. Participants still never get results of private slides, the public PDF export strips them via ResultsService::withoutContents(). Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 20 ++--- src/Service/PollStateService.php | 3 +- src/Service/ReportService.php | 8 +- src/Service/ResultsService.php | 70 ++++++++-------- templates/Admin/index.php | 2 +- templates/Participate/view.php | 4 +- templates/Slides/answers.php | 8 +- templates/Slides/form.php | 6 +- .../Controller/PrivateFeedbackTest.php | 27 ++++--- .../TestCase/Controller/ScaleCommentsTest.php | 9 ++- webroot/js/plenario.js | 81 +++++++++++++------ 11 files changed, 143 insertions(+), 95 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 79e37be..975d772 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -167,23 +167,23 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures ist die Berechtigung, siehe `Application::middleware()`) und erlauben Framing per CSP `frame-ancestors` (`EMBED_FRAME_ANCESTORS`); alle anderen Seiten bleiben `X-Frame-Options: SAMEORIGIN`. -- **Anonymes Feedback** (offene Frage mit Setting `private`, `Slide::isPrivate()`): Antworttexte erscheinen **nie** im - Presenter-/Embed-JSON (`results.answers` leer, nur `participants`) und nie bei Teilnehmenden (keine `results`, - unabhängig von `show_results_to_participants`). Lesen nur in der Verwaltung (`slides:answers`, - `ResultsService::answers()`) und in der vollständigen Fassung des PDF-Exports. -- **Internes Feedback** (Skala mit Setting `private`, ebenfalls `Slide::isPrivate()`): Presenter-/Embed-JSON enthält - `buckets: []` und `average: null` (nur `participants`), Teilnehmende bekommen keine `results`. Verteilung und - Durchschnitt nur in der Verwaltung (`slides:answers` → „Auswertung“, `ResultsService::scaleResults()`) und in der vollständigen Fassung des PDF-Exports. +- **Anonymes / internes Feedback** (offene Frage bzw. Skala mit Setting `private`, `Slide::isPrivate()`): steuert den + Schalter „Ergebnisse verbergen“ (H) im Presenter/Embed. Das JSON enthält die vollständigen Ergebnisse plus + `results.private = true`; `initPresenter` verbirgt sie beim Wechsel auf eine solche Folie und zeigt stattdessen nur die + Anzahl (`Results.privateSummary`). Einblenden gilt nur für diese Folie, die globale Wahl für normale Folien (`hideAll`) + bleibt unberührt. Teilnehmende bekommen bei privaten Folien **nie** `results` (unabhängig von + `show_results_to_participants`). Die Fassung des PDF-Exports ohne interne Inhalte entfernt sie per + `ResultsService::withoutContents()`. Volle Ansicht in der Verwaltung (`slides:answers` → „Auswertung“). - **Skala-Kommentare** (Setting `comments`, `Slide::hasComments()`): optionales Feld `comment`, gespeichert als `text_value` in derselben Zeile wie `numeric_value` (ohne Setting wird es ignoriert). Öffentliche Skalen liefern im Presenter-/Embed-State `results.comments` (Teilnehmende bekommen immer `[]`, `PollStateService::participantResults()`) (älteste zuerst, je `id`, `text`, `value` – `value` nur mit Setting `comment_ratings`, sonst `null`); `Comments` in `plenario.js` blättert sie automatisch durch („Kommentar X von N“, - vor/zurück/Pause, Zustand übersteht das Neu-Rendern beim Polling). Bei internem Feedback bleibt `comments` leer, - lesbar nur in der Auswertung (`ResultsService::comments()`) und in der vollständigen Fassung des PDF-Exports. + vor/zurück/Pause, Zustand übersteht das Neu-Rendern beim Polling). Bei internem Feedback erscheinen sie erst, + wenn der Presenter die Ergebnisse einblendet. - **PDF-Export** (`/admin/{token}/export.pdf`, `admin:export`, `ReportService` + `PdfView`, Dompdf): Ergebnisse aller interaktiven Folien (Inhaltsfolien/YouTube fehlen). Standard ist die Fassung **ohne interne Inhalte**: private Folien - (`Slide::isPrivate()`) erscheinen nur mit Teilnehmerzahl, wie im Presenter. `?internal=1` = vollständige Fassung inkl. + (`Slide::isPrivate()`) erscheinen nur mit Teilnehmerzahl. `?internal=1` = vollständige Fassung inkl. anonymer Antworten, interner Skalen und Kommentar-Bewertungen (Dateiname `…-intern.pdf`, Hinweis „Vertraulich“ auf jeder Seite); ohne private Folien wird der Parameter ignoriert. Quiz/Reihenfolge folgen auch hier den Auflöse-Regeln (vor `finished` bzw. Schließen keine Zählungen/Lösung). Layout `templates/layout/pdf.php` ist eigenständig: keine diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index ed489ee..88f9e5d 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -26,7 +26,8 @@ use Cake\ORM\Locator\LocatorAwareTrait; * counts and the participant's correctness (`order`) only once voting is closed. * * Q&A slides have their own participant view (`qa`, see qaState()), never `results`. - * Private open questions (anonymous feedback) never show results to participants. + * Private slides (anonymous/internal feedback) never show results to participants, + * even though the presenter can show them on stage. */ class PollStateService { diff --git a/src/Service/ReportService.php b/src/Service/ReportService.php index 0fc51ca..251e6eb 100644 --- a/src/Service/ReportService.php +++ b/src/Service/ReportService.php @@ -90,14 +90,16 @@ class ReportService */ protected function resultsFor(Slide $slide, bool $includeInternal): array { - // Public shape first: it never contains private data. $results = $this->results->forSlide($slide); $mayRead = !$slide->isPrivate() || $includeInternal; + if (!$mayRead) { + return ResultsService::withoutContents($results); + } - if ($slide->type === Slide::TYPE_OPEN && $mayRead) { + if ($slide->type === Slide::TYPE_OPEN) { $results['answers'] = $this->results->answers($slide); } - if ($slide->type === Slide::TYPE_SCALE && $mayRead) { + if ($slide->type === Slide::TYPE_SCALE) { // Ratings next to comments: complete version always, public one only with the setting. $showRatings = $includeInternal || (bool)$slide->setting('comment_ratings'); $comments = []; diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index 414334e..0dbee69 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -17,14 +17,14 @@ use Cake\ORM\Locator\LocatorAwareTrait; * (count = participants who named or upvoted the word, down = downvotes, * weight follows count) * - open: 'answers' => [['text', 'created']] newest first, 'private' (bool); - * private (anonymous feedback): 'answers' is always empty, texts only via answers() * - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null, * 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool); * 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else []; * 'value' is null unless the setting comment_ratings is on; * presentation only, emptied for participants in PollStateService); - * private (internal feedback): 'buckets' and 'comments' are always empty and 'average' null, - * ratings and comments only via scaleResults() / comments() + * open/scale with 'private' (anonymous/internal feedback): contents are included for the + * presenter/embed, which start with the results hidden and may show them on demand; + * participants never get results of these slides, the public PDF strips them (withoutContents()) * - quiz: 'phase' (ready|running|finished), 'timeLimit' (s, 0 = manual), 'remaining' (s|null), * 'revealed' (bool), 'options' => [['id', 'label']] while not finished; * once finished additionally per option 'count', 'percent', 'correct' (bool) @@ -277,13 +277,12 @@ class ResultsService { return [ 'private' => $slide->isPrivate(), - 'answers' => $slide->isPrivate() ? [] : $this->answers($slide, self::MAX_ANSWERS), + 'answers' => $this->answers($slide, self::MAX_ANSWERS), ]; } /** - * Texts of an open question, newest first – also of private slides, - * so only for the admin area (never for the presenter screen or participants). + * Texts of an open question, newest first. * * @param \App\Model\Entity\Slide $slide Open question * @param int|null $limit Max. answers, null = all @@ -313,35 +312,43 @@ class ResultsService */ protected function scale(Slide $slide): array { - if (!$slide->isPrivate()) { - $showRatings = (bool)$slide->setting('comment_ratings'); - $comments = []; - foreach ($slide->hasComments() ? $this->comments($slide, self::MAX_ANSWERS) : [] as $comment) { - $comments[] = [ - 'id' => $comment['id'], - 'text' => $comment['text'], - 'value' => $showRatings ? $comment['value'] : null, - ]; - } - - return $this->scaleResults($slide) + ['private' => false, 'comments' => $comments]; + $showRatings = (bool)$slide->setting('comment_ratings'); + $comments = []; + foreach ($slide->hasComments() ? $this->comments($slide, self::MAX_ANSWERS) : [] as $comment) { + $comments[] = [ + 'id' => $comment['id'], + 'text' => $comment['text'], + 'value' => $showRatings ? $comment['value'] : null, + ]; } - return [ - 'buckets' => [], - 'average' => null, - 'min' => (int)$slide->setting('scale_min'), - 'max' => (int)$slide->setting('scale_max'), - 'minLabel' => (string)$slide->setting('min_label'), - 'maxLabel' => (string)$slide->setting('max_label'), - 'private' => true, - 'comments' => [], - ]; + return $this->scaleResults($slide) + ['private' => $slide->isPrivate(), 'comments' => $comments]; } /** - * Comments of a scale with their rating, oldest first – also of private slides, - * so the unfiltered call is only for the admin area. + * Results of a private slide without its contents: only type, participants and the scale range. + * Used where internal feedback must not appear (participants, public PDF export). + * + * @param array $results Result of forSlide() + * @return array + */ + public static function withoutContents(array $results): array + { + if (isset($results['answers'])) { + $results['answers'] = []; + } + if (isset($results['buckets'])) { + $results['buckets'] = []; + $results['average'] = null; + $results['comments'] = []; + } + + return $results; + } + + /** + * Comments of a scale with their rating, oldest first; the unfiltered call + * (ratings regardless of comment_ratings) is only for the admin area. * * @param \App\Model\Entity\Slide $slide Scale slide * @param int|null $limit Max. comments (the newest ones), null = all @@ -371,8 +378,7 @@ class ResultsService } /** - * Distribution and average of a scale – also of private slides, - * so only for the admin area (never for the presenter screen or participants). + * 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} diff --git a/templates/Admin/index.php b/templates/Admin/index.php index 35516a3..8e316bb 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -101,7 +101,7 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s · is_voting_open) : ?>· hasComments()) : ?>💬 - isPrivate()) : ?>🔒 type === 'scale' ? __('intern') : __('anonym') ?> + isPrivate()) : ?>🔒 type === 'scale' ? __('intern') : __('anonym') ?> question) ?> diff --git a/templates/Participate/view.php b/templates/Participate/view.php index 9a9eade..096bc75 100644 --- a/templates/Participate/view.php +++ b/templates/Participate/view.php @@ -234,7 +234,7 @@ $countdown = function (?int $remaining): string { placeholder=""> isPrivate()) : ?>

- 🔒 + 🔒

@@ -258,7 +258,7 @@ $countdown = function (?int $remaining): string { isPrivate()) : ?>

- 🔒 + 🔒

diff --git a/templates/Slides/answers.php b/templates/Slides/answers.php index 2af92fb..7872c34 100644 --- a/templates/Slides/answers.php +++ b/templates/Slides/answers.php @@ -1,7 +1,7 @@ isPrivate()) : ?>

+ ? __('Dieses Ergebnis ist in der Präsentation zunächst verborgen und wird den Teilnehmenden nie angezeigt.') + : __('Diese Antworten sind in der Präsentation zunächst verborgen und werden den Teilnehmenden nie angezeigt.') ?>

diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 3af8e74..3c1fc3f 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -135,7 +135,7 @@ $optionsError = $slide->getError('options_text'); 'label' => __('Anonymes Feedback: Antworten nicht öffentlich anzeigen'), 'checked' => (bool)$settings['private'], ]) ?> -

+

type === 'wordcloud') : ?> Form->control('settings.allow_upvotes', [ 'type' => 'checkbox', @@ -171,7 +171,7 @@ $optionsError = $slide->getError('options_text'); 'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Bewertung optional begründen)'), 'checked' => (bool)$settings['comments'], ]) ?> -

+

Form->control('settings.comment_ratings', [ 'type' => 'checkbox', 'label' => __('Bewertung beim Kommentar in der Präsentation anzeigen'), @@ -182,7 +182,7 @@ $optionsError = $slide->getError('options_text'); 'label' => __('Internes Feedback: Ergebnis nicht öffentlich anzeigen'), 'checked' => (bool)$settings['private'], ]) ?> -

+

type === 'quiz') : $quizError = $slide->getError('quiz_options'); $rows = $quizOptions; diff --git a/tests/TestCase/Controller/PrivateFeedbackTest.php b/tests/TestCase/Controller/PrivateFeedbackTest.php index 607c943..b08ae6a 100644 --- a/tests/TestCase/Controller/PrivateFeedbackTest.php +++ b/tests/TestCase/Controller/PrivateFeedbackTest.php @@ -12,7 +12,8 @@ use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; /** - * Open questions and scales as anonymous/internal feedback: results only in the admin area. + * Open questions and scales as anonymous/internal feedback: the stage starts with hidden results + * (flag `private`, contents included so the presenter can show them), participants never get results. */ class PrivateFeedbackTest extends TestCase { @@ -78,17 +79,17 @@ class PrivateFeedbackTest extends TestCase $this->assertTrue($slide->isPrivate()); } - public function testPresenterSeesOnlyTheCount(): void + public function testPresenterGetsAnswersFlaggedPrivate(): void { [, $token] = $this->privateSlideWithAnswer(); $this->get("/admin/$token/state"); $state = json_decode((string)$this->_response->getBody(), true); + // Flag = the stage starts with hidden results; showing them is the presenter's choice. $this->assertTrue($state['results']['private']); - $this->assertSame([], $state['results']['answers']); + $this->assertSame('Geheimes ', $state['results']['answers'][0]['text']); $this->assertSame(1, $state['results']['participants']); - $this->assertResponseNotContains('Geheimes'); } public function testParticipantsNeverSeeAnswers(): void @@ -107,15 +108,17 @@ class PrivateFeedbackTest extends TestCase $this->assertResponseNotContains('Geheimes'); } - public function testEmbedSeesOnlyTheCount(): void + public function testEmbedGetsAnswersFlaggedPrivate(): void { [$poll, , $slide] = $this->privateSlideWithAnswer(); $key = $this->pollsTable()->ensureEmbedKey($poll); $this->get("/e/$key/{$slide->id}/state"); + $state = json_decode((string)$this->_response->getBody(), true); $this->assertResponseOk(); - $this->assertResponseNotContains('Geheimes'); + $this->assertTrue($state['results']['private']); + $this->assertCount(1, $state['results']['answers']); } public function testAdminReadsAnswers(): void @@ -195,7 +198,7 @@ class PrivateFeedbackTest extends TestCase $this->assertTrue($slide->isPrivate()); } - public function testPresenterSeesOnlyTheScaleCount(): void + public function testPresenterGetsScaleResultsFlaggedPrivate(): void { [, $token] = $this->privateScaleWithRatings(); @@ -203,8 +206,8 @@ class PrivateFeedbackTest extends TestCase $state = json_decode((string)$this->_response->getBody(), true); $this->assertTrue($state['results']['private']); - $this->assertSame([], $state['results']['buckets']); - $this->assertNull($state['results']['average']); + $this->assertCount(5, $state['results']['buckets']); + $this->assertEqualsWithDelta(3.5, $state['results']['average'], 0.001); $this->assertSame(2, $state['results']['participants']); } @@ -221,7 +224,7 @@ class PrivateFeedbackTest extends TestCase $this->assertNull($this->participantState($poll)['results']); } - public function testEmbedSeesOnlyTheScaleCount(): void + public function testEmbedGetsScaleResultsFlaggedPrivate(): void { [$poll, , $slide] = $this->privateScaleWithRatings(); $key = $this->pollsTable()->ensureEmbedKey($poll); @@ -230,8 +233,8 @@ class PrivateFeedbackTest extends TestCase $state = json_decode((string)$this->_response->getBody(), true); $this->assertResponseOk(); - $this->assertSame([], $state['results']['buckets']); - $this->assertNull($state['results']['average']); + $this->assertTrue($state['results']['private']); + $this->assertEqualsWithDelta(3.5, $state['results']['average'], 0.001); } public function testAdminReadsScaleResults(): void diff --git a/tests/TestCase/Controller/ScaleCommentsTest.php b/tests/TestCase/Controller/ScaleCommentsTest.php index ad97c8e..2c2b651 100644 --- a/tests/TestCase/Controller/ScaleCommentsTest.php +++ b/tests/TestCase/Controller/ScaleCommentsTest.php @@ -182,17 +182,18 @@ class ScaleCommentsTest extends TestCase $this->assertCount(2, $state['results']['comments']); } - public function testPrivateScaleNeverShowsComments(): void + public function testPrivateScaleCommentsOnlyForTheStage(): void { [$poll, $token, $slide] = $this->scaleWithComments(['private' => true]); + // The presenter starts hidden but may show them, so the data is there. $results = $this->presenterResults($token); - $this->assertSame([], $results['comments']); - $this->assertResponseNotContains('Sehr'); + $this->assertTrue($results['private']); + $this->assertCount(2, $results['comments']); $key = $this->pollsTable()->ensureEmbedKey($poll); $this->get("/e/$key/{$slide->id}/state"); - $this->assertResponseNotContains('Sehr'); + $this->assertResponseContains('Sehr'); $this->get('/p/' . $poll->join_code . '/state'); $this->assertResponseNotContains('Sehr'); diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 37b44ba..522cbba 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -453,16 +453,25 @@ })); }, + /** + * Placeholder for a private slide (anonymous/internal feedback) while its results + * are hidden on stage: only the count, the presenter can show the rest with H. + */ + privateSummary: function (results) { + var n = results.participants; + var noun = results.type === 'scale' + ? (n === 1 ? 'Bewertung' : 'Bewertungen') + : (n === 1 ? 'anonyme Antwort' : 'anonyme Antworten'); + return el('div', { class: 'private-summary' }, [ + el('p', { class: 'private-summary__count', text: String(n) }), + el('p', { text: noun + ' eingegangen' }), + el('p', { class: 'private-summary__hint', text: results.type === 'scale' + ? '🔒 Internes Feedback – Ergebnis verborgen.' + : '🔒 Anonymes Feedback – Antworten verborgen.' }) + ]); + }, + scale: function (results) { - if (results.private) { - // Internal feedback: the ratings never reach the stage, only the count. - var n = results.participants; - return el('div', { class: 'private-summary' }, [ - el('p', { class: 'private-summary__count', text: String(n) }), - el('p', { text: (n === 1 ? 'Bewertung' : 'Bewertungen') + ' eingegangen' }), - el('p', { class: 'private-summary__hint', text: '🔒 Ergebnis wird nicht öffentlich angezeigt.' }) - ]); - } var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1])); var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0); var hasAverage = results.average !== null; @@ -688,15 +697,6 @@ }, open: function (results) { - if (results.private) { - // Anonymous feedback: the texts never reach the stage, only the count. - var n = results.participants; - return el('div', { class: 'private-summary' }, [ - el('p', { class: 'private-summary__count', text: String(n) }), - el('p', { text: (n === 1 ? 'anonyme Antwort' : 'anonyme Antworten') + ' eingegangen' }), - el('p', { class: 'private-summary__hint', text: '🔒 Antworten werden nicht öffentlich angezeigt.' }) - ]); - } return el('ul', { class: 'answers' }, results.answers.map(function (answer) { return el('li', { class: 'answer', text: answer.text }); })); @@ -968,7 +968,11 @@ } }; var last = ''; + // hideAll: the presenter's choice for normal slides (kept across slides). + // hideResults: what applies to the current slide - private slides start hidden. + var hideAll = false; var hideResults = false; + var hideSlideId = null; var state = null; var mediaKey = ''; @@ -1057,13 +1061,38 @@ ? count + (count === 1 ? ' Frage' : ' Fragen') : count + ' ' + (count === 1 ? 'Antwort' : 'Antworten'))); + if (slide.id !== hideSlideId) { + hideSlideId = slide.id; + hideResults = isPrivate() || hideAll; + hideLabel(); + } + renderResults(); + Countdown.start(); + } + + function isPrivate() { + return !!(state && state.slide && state.slide.isInteractive && state.results && state.results.private); + } + + function renderResults() { var container = q('[data-results]'); - container.classList.toggle('is-hidden', hideResults); - Results.render(container, slide.isInteractive ? state.results : null, { + var slide = state.slide; + // Hidden private slides show how many answered instead of an empty stage. + var summary = hideResults && isPrivate(); + container.classList.toggle('is-hidden', hideResults && !summary); + if (summary) { + container.textContent = ''; + container.appendChild(Results.privateSummary(state.results)); + return; + } + Results.render(container, slide && slide.isInteractive ? state.results : null, { onStage: function (stage) { control('stage', { stage: stage }); }, onQuestion: function (step) { control('question', { step: step }); } }); - Countdown.start(); + } + + function hideLabel() { + setText('[data-hide-results] [data-label]', hideResults ? 'Ergebnisse zeigen' : 'Ergebnisse verbergen'); } function refresh() { @@ -1083,8 +1112,14 @@ function toggleHide() { hideResults = !hideResults; - q('[data-results]').classList.toggle('is-hidden', hideResults); - setText('[data-hide-results] [data-label]', hideResults ? 'Ergebnisse zeigen' : 'Ergebnisse verbergen'); + // Showing a private slide is a decision for this slide only. + if (!isPrivate()) { + hideAll = hideResults; + } + hideLabel(); + if (state) { + renderResults(); + } } q('[data-hide-results]').addEventListener('click', toggleHide); -- 2.54.1