From 2301f91457f4474dcfbc017e1f048307c043adaa Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Sun, 8 Nov 2026 20:13:49 +0100 Subject: [PATCH] Make the comment rotation interval configurable Scale slides get the setting comment_interval (seconds per comment, one of Slide::COMMENT_INTERVALS, default 8). The presenter state carries it as results.commentInterval and the rotating comments use it. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 3 ++- src/Model/Entity/Slide.php | 10 +++++++- src/Model/Table/SlidesTable.php | 4 ++++ src/Service/ResultsService.php | 7 +++++- templates/Slides/form.php | 9 ++++++++ .../TestCase/Controller/ScaleCommentsTest.php | 23 +++++++++++++++++++ webroot/js/plenario.js | 15 ++++++++++-- 7 files changed, 66 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index af2e1b9..65c6162 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -181,7 +181,8 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures - **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“, + (älteste zuerst, je `id`, `text`, `value` – `value` nur mit Setting `comment_ratings`, sonst `null`); `Comments` in `plenario.js` blättert sie automatisch durch (Sekunden pro Kommentar = Setting `comment_interval`, Auswahl +`Slide::COMMENT_INTERVALS`, Standard 8, im State als `results.commentInterval`; „Kommentar X von N“, vor/zurück/Pause, Zustand übersteht das Neu-Rendern beim Polling). Bei internem Feedback erscheinen sie erst, wenn der Presenter die Ergebnisse einblendet. diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 29a3db8..2112a19 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -55,6 +55,13 @@ class Slide extends Entity */ public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300]; + /** + * Selectable seconds per comment when the comments of a scale rotate in the presentation. + * + * @var list + */ + public const COMMENT_INTERVALS = [3, 5, 8, 10, 15, 20, 30, 45, 60]; + /** * Q&A stages, see qaStage(): participants submit questions, then upvote * them, then the presenter discusses them one by one (most upvoted first). @@ -87,9 +94,10 @@ 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 + // comment_interval: seconds per comment while they rotate (one of COMMENT_INTERVALS) self::TYPE_SCALE => [ 'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false, - 'comments' => false, 'comment_ratings' => false, + 'comments' => false, 'comment_ratings' => false, 'comment_interval' => 8, ], self::TYPE_CONTENT => [], // time_limit in seconds, 0 = no limit (presenter ends the quiz) diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index 756b7f5..2fa07a6 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -159,6 +159,10 @@ 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); + $interval = (int)($input['comment_interval'] ?? $settings['comment_interval']); + if (in_array($interval, Slide::COMMENT_INTERVALS, true)) { + $settings['comment_interval'] = $interval; + } break; case Slide::TYPE_QUIZ: $limit = (int)($input['time_limit'] ?? $settings['time_limit']); diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index 0dbee69..1225646 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -22,6 +22,7 @@ use Cake\ORM\Locator\LocatorAwareTrait; * '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); + * 'commentInterval' => int seconds per comment while they rotate; * 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()) @@ -322,7 +323,11 @@ class ResultsService ]; } - return $this->scaleResults($slide) + ['private' => $slide->isPrivate(), 'comments' => $comments]; + return $this->scaleResults($slide) + [ + 'private' => $slide->isPrivate(), + 'comments' => $comments, + 'commentInterval' => (int)$slide->setting('comment_interval'), + ]; } /** diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 3c1fc3f..267f04c 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -172,6 +172,15 @@ $optionsError = $slide->getError('options_text'); 'checked' => (bool)$settings['comments'], ]) ?>

+ Form->control('settings.comment_interval', [ + 'type' => 'select', + 'options' => array_combine( + \App\Model\Entity\Slide::COMMENT_INTERVALS, + array_map(fn(int $s) => __n('{0} Sekunde', '{0} Sekunden', $s, $s), \App\Model\Entity\Slide::COMMENT_INTERVALS), + ), + 'label' => __('Nächster Kommentar nach'), + 'value' => $settings['comment_interval'], + ]) ?> Form->control('settings.comment_ratings', [ 'type' => 'checkbox', 'label' => __('Bewertung beim Kommentar in der Präsentation anzeigen'), diff --git a/tests/TestCase/Controller/ScaleCommentsTest.php b/tests/TestCase/Controller/ScaleCommentsTest.php index 41a47e7..3ec5421 100644 --- a/tests/TestCase/Controller/ScaleCommentsTest.php +++ b/tests/TestCase/Controller/ScaleCommentsTest.php @@ -154,6 +154,29 @@ class ScaleCommentsTest extends TestCase $this->assertSame([4, 3], array_column($this->presenterResults($token)['comments'], 'value')); } + public function testCommentIntervalIsConfigurable(): void + { + $this->assertSame(8, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['comment_interval']); + $this->assertSame(15, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '15'])['comment_interval']); + $this->assertSame(8, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '7'])['comment_interval']); + $this->assertSame(8, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '-1'])['comment_interval']); + + [, $token] = $this->scaleWithComments(['comment_interval' => 20]); + $this->assertSame(20, $this->presenterResults($token)['commentInterval']); + + $this->get("/admin/$token"); + $this->assertResponseOk(); + } + + public function testFormShowsCommentInterval(): void + { + [, $token] = $this->createPoll(); + $this->get("/admin/$token/slides/add?type=scale"); + + $this->assertResponseContains('name="settings[comment_interval]"'); + $this->assertResponseContains('15 Sekunden'); + } + public function testParticipantsNeverSeeComments(): void { [$poll] = $this->scaleWithComments(); diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index bdb171f..8626d07 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -304,7 +304,11 @@ items: [], node: null, - render: function (items) { + /** + * @param {Array} items comments, oldest first + * @param {number} [seconds] time per comment (slide setting), default 8 + */ + render: function (items, seconds) { // A different first comment means a different slide (or a reset): start over. var key = String(items[0].id); if (key !== Comments.key) { @@ -312,6 +316,13 @@ Comments.index = 0; Comments.paused = false; } + var intervalMs = seconds > 0 ? seconds * 1000 : 8000; + if (intervalMs !== Comments.intervalMs) { + // Setting changed (or another slide): apply it right away. + Comments.intervalMs = intervalMs; + clearInterval(Comments.timer); + Comments.timer = null; + } Comments.items = items; Comments.index = Math.min(Comments.index, items.length - 1); @@ -518,7 +529,7 @@ ]), gauge ]); - var comments = results.comments && results.comments.length ? Comments.render(results.comments) : null; + var comments = results.comments && results.comments.length ? Comments.render(results.comments, results.commentInterval) : null; return el('div', { class: 'scale-results' }, [average, columns, labels, comments]); }, -- 2.54.1