diff --git a/docs/slide-types.md b/docs/slide-types.md index 214b97a..5e5a7a3 100644 --- a/docs/slide-types.md +++ b/docs/slide-types.md @@ -15,6 +15,9 @@ geändert wird es nur über die Presenter-Steuerung (`SlideControlService`) bzw. Downvotes (`vote=down`, Setting `allow_downvotes`, nur zusammen mit Upvotes): Zeile mit `numeric_value = VoteService::DOWNVOTE` (-1), nur auf fremde, vorhandene Begriffe, ein Rating pro Begriff und Person. Wortgröße richtet sich nur nach den Upvotes (`count`), Downvotes stehen separat in `down`. + Darstellung: Die Bühne zeigt die Wolke (`Results.wordcloud`); die Schriftgröße wird über `--cloud-scale` mit der Wortanzahl + kleiner, damit viele Begriffe nicht überlaufen. Teilnehmende sehen mit Upvotes stattdessen eine Liste + (`Results.wordList`, Klassen `wc-*`) mit „+“/„−“-Buttons und Gewichtsbalken, ähnlich dem Q&A-Voting. `vote=remove` nimmt den eigenen Eintrag zu einem Begriff zurück (genannt/Upvote oder Downvote, `VoteService::removeWord()`, löscht nur Zeilen mit dem eigenen `participant_hash`); Tippfehler = entfernen und neu eingeben, kein Bearbeiten (die Zeile ist zugleich die Stimme). Teilnehmende bekommen dafür `words.own` (eigene Begriffe wie eingegeben) und sehen sie als Chips mit „ד. @@ -146,14 +149,14 @@ 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. -- **Nur Kommentar ohne Bewertung** (Skala/Sterne, Setting `comment_only` zusätzlich zu `comments`, `Slide::hasCommentOnly()`; im Formular ein Dropdown +- **Nur Kommentar ohne Bewertung/Auswahl** (Skala/Sterne und Auswahlfolien, Setting `comment_only` zusätzlich zu `comments`, `Slide::hasCommentOnly()`; im Formular ein Dropdown `comment_mode`: kein Kommentarfeld | Kommentar optional, Bewertung Pflicht | auch Kommentar ohne Bewertung genügt, `SlidesTable::sanitizeSettings()` übersetzt es in `comments`/`comment_only`): die Bewertung ist dann nicht mehr Pflicht (die Radios sind nicht `required`), ein nicht leerer Kommentar genügt. `VoteService::scaleRows()` speichert eine Zeile **ohne** `numeric_value`: zählt als Teilnahme (einmal pro Person), geht aber nicht in Verteilung und Durchschnitt ein. Weder Bewertung noch Kommentar = Fehler, es gibt keinen leeren „Überspringen“-Knopf. `ResultsService::scaleResults()` liefert die Zahl als `commentOnly` (Bühne: „· N× nur Kommentar“, Auswertung, PDF; private Folien strippen sie mit `withoutContents()`). Der Kommentar läuft wie die anderen durch, `value` ist `null` (mit `comment_ratings` zeigt die Bühne „Ohne Bewertung“, damit - die Box gleich hoch bleibt). Nachträglich bearbeiten geht, aber der Kommentar darf dann nicht leer werden (`editText()`). Bei Auswahlfolien gibt es das - bewusst nicht (der Kommentar hängt an der ersten Optionszeile). Tests: `VoteServiceTest`, `ParticipateControllerTest`. + die Box gleich hoch bleibt). Nachträglich bearbeiten geht, aber der Kommentar darf dann nicht leer werden (`editText()`). + **Auswahlfolien** (Mehrfachauswahl wie Einzelauswahl) verhalten sich genauso: Zeile ohne `slide_option_id` (`ResultsService::choice()` zählt sie nur als `commentOnly`, nicht in Stimmen/Prozenten); `commentSettings()` in `SlidesTable` ist für beide Typen gleich. 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 diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 634e913..cdbe137 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -115,7 +115,7 @@ class Slide extends Entity public const DEFAULT_SETTINGS = [ // comments: optional comment field (stored in text_value of the participant's first row), // comments rotate in the presentation like those of a scale - self::TYPE_CHOICE => ['multiple' => false, 'comments' => false, 'time_limit' => 0], + self::TYPE_CHOICE => ['multiple' => false, 'comments' => false, 'comment_only' => false, 'time_limit' => 0], // allow_downvotes only takes effect together with allow_upvotes self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true, 'time_limit' => 0], // private: anonymous feedback, answers only visible in the admin area (never on the stage) @@ -637,13 +637,14 @@ class Slide extends Entity } /** - * Scale with a comment field where a comment alone is enough (the rating is optional). + * Scale or multiple choice with a comment field where a comment alone is enough + * (the rating or selection is optional). * * @return bool */ public function hasCommentOnly(): bool { - return $this->type === self::TYPE_SCALE && $this->hasComments() && (bool)$this->setting('comment_only'); + return $this->hasComments() && (bool)$this->setting('comment_only'); } /** diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index d725f09..0a7442b 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -155,7 +155,7 @@ class SlidesTable extends Table switch ($type) { case Slide::TYPE_CHOICE: $settings['multiple'] = filter_var($input['multiple'] ?? false, FILTER_VALIDATE_BOOLEAN); - $settings['comments'] = filter_var($input['comments'] ?? false, FILTER_VALIDATE_BOOLEAN); + $settings = array_merge($settings, static::commentSettings($input)); break; case Slide::TYPE_WORDCLOUD: $settings['allow_upvotes'] = filter_var($input['allow_upvotes'] ?? true, FILTER_VALIDATE_BOOLEAN); @@ -175,14 +175,7 @@ class SlidesTable extends Table $settings['min_label'] = mb_substr(trim((string)($input['min_label'] ?? '')), 0, 60); $settings['max_label'] = mb_substr(trim((string)($input['max_label'] ?? '')), 0, 60); $settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN); - // Form: one dropdown (off|rating|only); the plain flags `comments`/`comment_only` stay accepted - $mode = $input['comment_mode'] ?? match (true) { - !filter_var($input['comments'] ?? false, FILTER_VALIDATE_BOOLEAN) => 'off', - filter_var($input['comment_only'] ?? false, FILTER_VALIDATE_BOOLEAN) => 'only', - default => 'rating', - }; - $settings['comments'] = in_array($mode, ['rating', 'only'], true); - $settings['comment_only'] = $mode === 'only'; + $settings = array_merge($settings, static::commentSettings($input)); $settings['comment_ratings'] = filter_var($input['comment_ratings'] ?? false, FILTER_VALIDATE_BOOLEAN); $view = $input['scale_view'] ?? null; $settings['scale_view'] = in_array($view, Slide::SCALE_VIEWS, true) ? $view : Slide::SCALE_VIEW_BOTH; @@ -228,6 +221,25 @@ class SlidesTable extends Table return $settings; } + /** + * Comment settings of choice and scale slides. The form sends one dropdown `comment_mode` + * (off | rating: optional comment | only: a comment alone is enough); the plain flags + * `comments`/`comment_only` stay accepted. + * + * @param array $input Raw settings + * @return array{comments: bool, comment_only: bool} + */ + protected static function commentSettings(array $input): array + { + $mode = $input['comment_mode'] ?? match (true) { + !filter_var($input['comments'] ?? false, FILTER_VALIDATE_BOOLEAN) => 'off', + filter_var($input['comment_only'] ?? false, FILTER_VALIDATE_BOOLEAN) => 'only', + default => 'rating', + }; + + return ['comments' => in_array($mode, ['rating', 'only'], true), 'comment_only' => $mode === 'only']; + } + /** * Parses a textarea (one option per line) into a clean list of labels. * diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index 372ff0b..7441e0b 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -283,7 +283,10 @@ class ResultsService $comments[] = ['id' => $comment['id'], 'text' => $comment['text'], 'value' => null]; } - return ['options' => $options, 'votes' => $total, 'comments' => $comments]; + // Comment only: taking part without a selection, not part of the counts + $commentOnly = $this->Responses->find()->where(['slide_id' => $slide->id, 'slide_option_id IS' => null])->count(); + + return ['options' => $options, 'votes' => $total, 'comments' => $comments, 'commentOnly' => $commentOnly]; } /** @@ -504,15 +507,12 @@ class ResultsService */ public function comments(Slide $slide, ?int $limit = null): array { - // Scale: the rating row carries the comment (no rating = comment only). Choice: the comment - // sits in the first of the participant's rows, which always has an option. + // Scale: the rating row carries the comment. Choice: the comment sits in the first of the + // participant's rows. Without a rating or selection the row holds only the comment. $query = $this->Responses->find() ->select(['id', 'text_value', 'numeric_value', 'created']) ->where(['slide_id' => $slide->id, 'text_value IS NOT' => null]) ->orderBy(['id' => 'DESC']); - if ($slide->type === Slide::TYPE_CHOICE) { - $query->where(['slide_option_id IS NOT' => null]); - } if ($limit !== null) { $query->limit($limit); } diff --git a/src/Service/VoteService.php b/src/Service/VoteService.php index 5a64543..f5ccc24 100644 --- a/src/Service/VoteService.php +++ b/src/Service/VoteService.php @@ -179,9 +179,14 @@ class VoteService default => __('Bitte gib zuerst deine Bewertung ab.'), }); } - if ($slide->type === Slide::TYPE_SCALE && $row->numeric_value === null && $text === null) { - // Without a rating the comment is the whole answer. - throw new VoteException(__('Ohne Bewertung darf der Kommentar nicht leer sein.')); + $withoutAnswer = match ($slide->type) { + Slide::TYPE_SCALE => $row->numeric_value === null, + Slide::TYPE_CHOICE => $row->slide_option_id === null, + default => false, + }; + if ($withoutAnswer && $text === null) { + // Without a rating or selection the comment is the whole answer. + throw new VoteException(__('Ohne Bewertung oder Auswahl darf der Kommentar nicht leer sein.')); } $row->text_value = $text; $this->Responses->saveOrFail($row); @@ -285,6 +290,15 @@ class VoteService $validIds = $slide->optionIds(); $selected = array_values(array_intersect($selected, $validIds)); + if ($selected === [] && $slide->hasCommentOnly()) { + // Comment only: no selection, but a comment is required (this is not a way to skip). + $comment = self::comment($data); + if ($comment === null) { + throw new VoteException(__('Bitte wähle eine Antwort aus oder schreibe einen Kommentar.')); + } + + return [['slide_option_id' => null, 'text_value' => $comment]]; + } if ($selected === []) { throw new VoteException(__('Bitte wähle eine Antwort aus.')); } diff --git a/templates/Admin/export.php b/templates/Admin/export.php index e2404dd..4d30aa0 100644 --- a/templates/Admin/export.php +++ b/templates/Admin/export.php @@ -103,6 +103,9 @@ $bar = function (float $percent, bool $ok = false): string { + +

+ hasComments()) : ?>

diff --git a/templates/Participate/view.php b/templates/Participate/view.php index 6f26767..4426b77 100644 --- a/templates/Participate/view.php +++ b/templates/Participate/view.php @@ -282,13 +282,16 @@ $countdown = function (?int $remaining): string { hasComments()) : ?> + hasCommentOnly()) : ?> +

+ @@ -359,8 +362,8 @@ $countdown = function (?int $remaining): string { } ?> is_voting_open) : ?>

+ ? __('Tippe auf „+“, um einen Begriff zu unterstützen, oder auf „−“, um ihn abzulehnen.') + : __('Tippe auf „+“, um einen Begriff zu unterstützen.') ?>

diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 20fd66c..0c56711 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -138,10 +138,15 @@ $optionsError = $slide->getError('options_text'); 'label' => __('Mehrfachauswahl erlauben'), 'checked' => (bool)$settings['multiple'], ]) ?> - Form->control('settings.comments', [ - 'type' => 'checkbox', - 'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Auswahl optional begründen)'), - 'checked' => (bool)$settings['comments'], + Form->control('settings.comment_mode', [ + 'type' => 'select', + 'label' => __('Kommentarfeld'), + 'options' => [ + 'off' => __('Kein Kommentarfeld'), + 'rating' => __('Kommentar optional, die Auswahl ist Pflicht'), + 'only' => __('Kommentar optional, auch ein Kommentar ohne Auswahl genügt'), + ], + 'value' => empty($settings['comments']) ? 'off' : (empty($settings['comment_only']) ? 'rating' : 'only'), ]) ?>

type === 'open') : ?> diff --git a/tests/TestCase/Controller/AdminControllerTest.php b/tests/TestCase/Controller/AdminControllerTest.php index 10af497..ae36f73 100644 --- a/tests/TestCase/Controller/AdminControllerTest.php +++ b/tests/TestCase/Controller/AdminControllerTest.php @@ -107,7 +107,7 @@ class AdminControllerTest extends TestCase $slide = $this->slidesTable()->find()->contain(['SlideOptions'])->firstOrFail(); $this->assertSame($poll->id, $slide->poll_id); $this->assertSame(['Pizza', 'Pasta'], array_map(fn($o) => $o->label, $slide->slide_options)); - $this->assertSame(['multiple' => true, 'comments' => false, 'time_limit' => 0], $slide->settings); + $this->assertSame(['multiple' => true, 'comments' => false, 'comment_only' => false, 'time_limit' => 0], $slide->settings); $this->assertSame(1, $slide->position); } diff --git a/tests/TestCase/Controller/ChoiceCommentsTest.php b/tests/TestCase/Controller/ChoiceCommentsTest.php index f9670e0..e62966d 100644 --- a/tests/TestCase/Controller/ChoiceCommentsTest.php +++ b/tests/TestCase/Controller/ChoiceCommentsTest.php @@ -60,7 +60,7 @@ class ChoiceCommentsTest extends TestCase { [, $token] = $this->createPoll(); $this->get("/admin/$token/slides/add?type=choice"); - $this->assertResponseContains('name="settings[comments]"'); + $this->assertResponseContains('name="settings[comment_mode]"'); $this->post("/admin/$token/slides/add?type=choice", [ 'type' => 'choice', diff --git a/tests/TestCase/Service/VoteServiceTest.php b/tests/TestCase/Service/VoteServiceTest.php index 7a4ec51..1c65270 100644 --- a/tests/TestCase/Service/VoteServiceTest.php +++ b/tests/TestCase/Service/VoteServiceTest.php @@ -127,6 +127,37 @@ class VoteServiceTest extends TestCase $service->editText($poll, $slide, 'p1', ['comment' => '']); } + public function testChoiceCommentOnlyIsNotCountedAsVote(): void + { + [$poll] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_CHOICE, ['settings' => ['comments' => true, 'comment_only' => true]], ['A', 'B']); + $poll = $this->goLive($poll, $slide); + $service = new VoteService(); + $service->submit($poll, $slide, 'p1', ['option_id' => $slide->slide_options[0]->id]); + $service->submit($poll, $slide, 'p2', ['comment' => 'Keine passt']); + + $results = (new ResultsService())->forSlide($slide); + $this->assertSame(2, $results['participants']); + $this->assertSame(1, $results['votes']); + $this->assertSame(1, $results['commentOnly']); + $this->assertEquals([100, 0], array_column($results['options'], 'percent')); + $this->assertSame(['Keine passt'], array_column($results['comments'], 'text')); + + $service->editText($poll, $slide, 'p2', ['comment' => 'Keine passt wirklich']); + $this->expectExceptionMessage('nicht leer sein'); + $service->editText($poll, $slide, 'p2', ['comment' => '']); + } + + public function testChoiceWithoutSelectionNeedsCommentOnlySetting(): void + { + [$poll] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_CHOICE, ['settings' => ['comments' => true]], ['A', 'B']); + $poll = $this->goLive($poll, $slide); + + $this->expectExceptionMessage('Bitte wähle eine Antwort aus.'); + (new VoteService())->submit($poll, $slide, 'p1', ['comment' => 'Nur Kommentar']); + } + public function testMultipleChoiceResults(): void { [$poll] = $this->createPoll(); diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 5a8b646..53dfe23 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -690,10 +690,13 @@ el('div', { class: 'bar__value', text: formatNumber(option.percent) + ' % (' + option.count + ')' }) ]); })); + var commentOnly = results.commentOnly + ? el('p', { class: 'choice-results__note', text: results.commentOnly + '× nur Kommentar' }) + : null; if (!results.comments || !results.comments.length) { - return bars; + return commentOnly ? el('div', { class: 'choice-results' }, [bars, commentOnly]) : bars; } - return el('div', { class: 'choice-results' }, [bars, Comments.render(results.comments, String)]); + return el('div', { class: 'choice-results' }, [bars, commentOnly, Comments.render(results.comments, String)]); }, /**