diff --git a/AGENTS.md b/AGENTS.md index d62c633..ca553c0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -173,7 +173,8 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures `buckets: []` und `average: null` (nur `participants`), Teilnehmende bekommen keine `results`. Verteilung und Durchschnitt nur in der Verwaltung (`slides:answers` → „Auswertung“, `ResultsService::scaleResults()`) und im CSV-Export. - **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 `results.comments` + 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`); `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 im CSV-Export. diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index 262b776..ed489ee 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -187,7 +187,7 @@ class PollStateService $slide?->modified?->toUnixString() ?? 0, ]), 'slide' => $showResults ? $this->slidePayload($slide) : null, - 'results' => $showResults ? $this->results->forSlide($slide) : null, + 'results' => $showResults ? $this->participantResults($slide) : null, 'words' => $words, 'quiz' => $quiz, 'qa' => $qa, @@ -195,6 +195,22 @@ class PollStateService ]; } + /** + * Results as participants see them: scale comments are for the presentation only. + * + * @param \App\Model\Entity\Slide $slide Current slide + * @return array + */ + protected function participantResults(Slide $slide): array + { + $results = $this->results->forSlide($slide); + if (isset($results['comments'])) { + $results['comments'] = []; + } + + return $results; + } + /** * Ordering progress of one participant. Own answer and correctness only once * revealed (voting closed); before that the state must not hint at the solution. diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index 9c5a32e..005a74e 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -20,7 +20,8 @@ use Cake\ORM\Locator\LocatorAwareTrait; * 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']] oldest first (only with the comment field, else []); + * 'comments' => [['id', 'text', 'value']] oldest first (only with the comment field, else []; + * 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() * - quiz: 'phase' (ready|running|finished), 'timeLimit' (s, 0 = manual), 'remaining' (s|null), diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 38a6804..4f7903a 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -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.private', [ 'type' => 'checkbox', 'label' => __('Internes Feedback: Ergebnis nicht öffentlich anzeigen'), diff --git a/tests/TestCase/Controller/ScaleCommentsTest.php b/tests/TestCase/Controller/ScaleCommentsTest.php index d0c1486..c0ec1fa 100644 --- a/tests/TestCase/Controller/ScaleCommentsTest.php +++ b/tests/TestCase/Controller/ScaleCommentsTest.php @@ -13,7 +13,7 @@ use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; /** - * Scale slides with an optional comment field: comments rotate on the results unless the scale is private. + * Scale slides with an optional comment field: comments rotate in the presentation unless the scale is private. */ class ScaleCommentsTest extends TestCase { @@ -144,20 +144,32 @@ class ScaleCommentsTest extends TestCase $this->assertSame([4, 3], array_column($results['comments'], 'value')); } - public function testParticipantsSeeCommentsOnlyWithPublicResults(): void + public function testParticipantsNeverSeeComments(): void { [$poll] = $this->scaleWithComments(); - // Participant "a" has already rated. + $this->assertTrue($poll->show_results_to_participants); + // Participant "a" has already rated and sees the results – but not the comments. $this->cookie('plenario_pid', str_repeat('a', 32)); $this->get('/p/' . $poll->join_code . '/state'); $state = json_decode((string)$this->_response->getBody(), true); - $this->assertCount(2, $state['results']['comments']); + $this->assertNotEmpty($state['results']['buckets']); + $this->assertSame([], $state['results']['comments']); + $this->assertResponseNotContains('Zu lang'); - $poll->show_results_to_participants = false; - $this->pollsTable()->saveOrFail($poll); - $this->get('/p/' . $poll->join_code . '/state'); - $this->assertNull(json_decode((string)$this->_response->getBody(), true)['results']); + $this->get('/p/' . $poll->join_code); + $this->assertResponseNotContains('Zu lang'); + } + + public function testEmbedShowsComments(): void + { + [$poll, , $slide] = $this->scaleWithComments(); + $key = $this->pollsTable()->ensureEmbedKey($poll); + + $this->get("/e/$key/{$slide->id}/state"); + $state = json_decode((string)$this->_response->getBody(), true); + + $this->assertCount(2, $state['results']['comments']); } public function testPrivateScaleNeverShowsComments(): void