Merge pull request 'Feature/choice comment only' (#126) from feature/choice-comment-only into main
CI / Deploy / PHP 8.4 (push) Successful in 1m17s
CI / Deploy / PHP 8.5 (push) Successful in 1m28s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 8s

Reviewed-on: #126
This commit was merged in pull request #126.
This commit is contained in:
gnilebein committed 2026-11-21 13:42:21 +01:00
commit 7475f096ea
13 files changed
+190 -87

No files matched your search

+8 -3
View File
@@ -12,9 +12,14 @@ geändert wird es nur über die Presenter-Steuerung (`SlideControlService`) bzw.
jeder Begriff einmal pro Person, beliebig viele Begriffe. Einen vorhandenen Begriff erneut nennen jeder Begriff einmal pro Person, beliebig viele Begriffe. Einen vorhandenen Begriff erneut nennen
bzw. in der Wolke anklicken = Upvote (gleiche Zeile in `responses`). Mit `allow_upvotes` sehen Teilnehmende bzw. in der Wolke anklicken = Upvote (gleiche Zeile in `responses`). Mit `allow_upvotes` sehen Teilnehmende
die Wolke live; Vorschläge inkl. Kölner Phonetik in `plenario.js` (`Words`). die Wolke live; Vorschläge inkl. Kölner Phonetik in `plenario.js` (`Words`).
Teilnehmende sehen sie als kompakte Liste (`Results.wordList()`: feste Schriftgröße, Gewichtsbalken, große „+“/„−“-Buttons, wie beim Q&A-Voting),
die Bühne als Wolke, deren Schrift mit der Wortzahl kleiner wird (`--cloud-scale`).
Downvotes (`vote=down`, Setting `allow_downvotes`, nur zusammen mit Upvotes): Zeile mit `numeric_value = VoteService::DOWNVOTE` (-1), 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. 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`. 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()`, `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 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 „ד. ist zugleich die Stimme). Teilnehmende bekommen dafür `words.own` (eigene Begriffe wie eingegeben) und sehen sie als Chips mit „ד.
@@ -146,14 +151,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`, (`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. 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. 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 `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), `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. 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 `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 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 die Box gleich hoch bleibt). Nachträglich bearbeiten geht, aber der Kommentar darf dann nicht leer werden (`editText()`).
bewusst nicht (der Kommentar hängt an der ersten Optionszeile). Tests: `VoteServiceTest`, `ParticipateControllerTest`. **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). - **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. 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 - **Antwort nachträglich bearbeiten** (gegen Tippfehler, `VoteService::hasEditableText()`): Antwort einer offenen Frage
+4 -3
View File
@@ -115,7 +115,7 @@ class Slide extends Entity
public const DEFAULT_SETTINGS = [ public const DEFAULT_SETTINGS = [
// comments: optional comment field (stored in text_value of the participant's first row), // comments: optional comment field (stored in text_value of the participant's first row),
// comments rotate in the presentation like those of a scale // 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 // allow_downvotes only takes effect together with allow_upvotes
self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true, 'time_limit' => 0], 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) // 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 * @return bool
*/ */
public function hasCommentOnly(): 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');
} }
/** /**
+21 -9
View File
@@ -155,7 +155,7 @@ class SlidesTable extends Table
switch ($type) { switch ($type) {
case Slide::TYPE_CHOICE: case Slide::TYPE_CHOICE:
$settings['multiple'] = filter_var($input['multiple'] ?? false, FILTER_VALIDATE_BOOLEAN); $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; break;
case Slide::TYPE_WORDCLOUD: case Slide::TYPE_WORDCLOUD:
$settings['allow_upvotes'] = filter_var($input['allow_upvotes'] ?? true, FILTER_VALIDATE_BOOLEAN); $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['min_label'] = mb_substr(trim((string)($input['min_label'] ?? '')), 0, 60);
$settings['max_label'] = mb_substr(trim((string)($input['max_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); $settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
// Form: one dropdown (off|rating|only); the plain flags `comments`/`comment_only` stay accepted $settings = array_merge($settings, static::commentSettings($input));
$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['comment_ratings'] = filter_var($input['comment_ratings'] ?? false, FILTER_VALIDATE_BOOLEAN); $settings['comment_ratings'] = filter_var($input['comment_ratings'] ?? false, FILTER_VALIDATE_BOOLEAN);
$view = $input['scale_view'] ?? null; $view = $input['scale_view'] ?? null;
$settings['scale_view'] = in_array($view, Slide::SCALE_VIEWS, true) ? $view : Slide::SCALE_VIEW_BOTH; $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; 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<string, mixed> $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. * Parses a textarea (one option per line) into a clean list of labels.
* *
+6 -6
View File
@@ -283,7 +283,10 @@ class ResultsService
$comments[] = ['id' => $comment['id'], 'text' => $comment['text'], 'value' => null]; $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 public function comments(Slide $slide, ?int $limit = null): array
{ {
// Scale: the rating row carries the comment (no rating = comment only). Choice: the comment // Scale: the rating row carries the comment. Choice: the comment sits in the first of the
// sits in the first of the participant's rows, which always has an option. // participant's rows. Without a rating or selection the row holds only the comment.
$query = $this->Responses->find() $query = $this->Responses->find()
->select(['id', 'text_value', 'numeric_value', 'created']) ->select(['id', 'text_value', 'numeric_value', 'created'])
->where(['slide_id' => $slide->id, 'text_value IS NOT' => null]) ->where(['slide_id' => $slide->id, 'text_value IS NOT' => null])
->orderBy(['id' => 'DESC']); ->orderBy(['id' => 'DESC']);
if ($slide->type === Slide::TYPE_CHOICE) {
$query->where(['slide_option_id IS NOT' => null]);
}
if ($limit !== null) { if ($limit !== null) {
$query->limit($limit); $query->limit($limit);
} }
+17 -3
View File
@@ -179,9 +179,14 @@ class VoteService
default => __('Bitte gib zuerst deine Bewertung ab.'), default => __('Bitte gib zuerst deine Bewertung ab.'),
}); });
} }
if ($slide->type === Slide::TYPE_SCALE && $row->numeric_value === null && $text === null) { $withoutAnswer = match ($slide->type) {
// Without a rating the comment is the whole answer. Slide::TYPE_SCALE => $row->numeric_value === null,
throw new VoteException(__('Ohne Bewertung darf der Kommentar nicht leer sein.')); 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; $row->text_value = $text;
$this->Responses->saveOrFail($row); $this->Responses->saveOrFail($row);
@@ -285,6 +290,15 @@ class VoteService
$validIds = $slide->optionIds(); $validIds = $slide->optionIds();
$selected = array_values(array_intersect($selected, $validIds)); $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 === []) { if ($selected === []) {
throw new VoteException(__('Bitte wähle eine Antwort aus.')); throw new VoteException(__('Bitte wähle eine Antwort aus.'));
} }
+3
View File
@@ -103,6 +103,9 @@ $bar = function (float $percent, bool $ok = false): string {
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<?php if (!empty($r['commentOnly'])) : ?>
<p class="muted"><?= __('{0}× nur Kommentar (nicht in den Stimmen)', (int)$r['commentOnly']) ?></p>
<?php endif; ?>
<?php if ($slide->hasComments()) : ?> <?php if ($slide->hasComments()) : ?>
<h3><?= __n('{0} Kommentar', '{0} Kommentare', count($r['comments']), count($r['comments'])) ?></h3> <h3><?= __n('{0} Kommentar', '{0} Kommentare', count($r['comments']), count($r['comments'])) ?></h3>
<?php if ($r['comments'] === []) : ?> <?php if ($r['comments'] === []) : ?>
+6 -3
View File
@@ -282,13 +282,16 @@ $countdown = function (?int $remaining): string {
<label class="choice"> <label class="choice">
<input type="<?= $multiple ? 'checkbox' : 'radio' ?>" <input type="<?= $multiple ? 'checkbox' : 'radio' ?>"
name="<?= $multiple ? 'option_ids[]' : 'option_id' ?>" name="<?= $multiple ? 'option_ids[]' : 'option_id' ?>"
value="<?= (int)$option->id ?>" <?= $multiple ? '' : 'required' ?>> value="<?= (int)$option->id ?>" <?= $multiple || $slide->hasCommentOnly() ? '' : 'required' ?>>
<span><?= h($option->label) ?></span> <span><?= h($option->label) ?></span>
</label> </label>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<?php if ($slide->hasComments()) : ?> <?php if ($slide->hasComments()) : ?>
<label class="scale-comment" for="choice-comment"><?= __('Kommentar (optional)') ?></label> <label class="scale-comment" for="choice-comment"><?= __('Kommentar (optional)') ?></label>
<?php if ($slide->hasCommentOnly()) : ?>
<p class="hint"><?= __('Du kannst auch nur einen Kommentar abgeben, ohne etwas auszuwählen.') ?></p>
<?php endif; ?>
<textarea id="choice-comment" name="comment" rows="3" maxlength="500" <textarea id="choice-comment" name="comment" rows="3" maxlength="500"
placeholder="<?= __('Möchtest du deine Auswahl begründen?') ?>"></textarea> placeholder="<?= __('Möchtest du deine Auswahl begründen?') ?>"></textarea>
<?php endif; ?> <?php endif; ?>
@@ -359,8 +362,8 @@ $countdown = function (?int $remaining): string {
} ?></h2> } ?></h2>
<?php if ($words !== null && $words['allowUpvotes'] && $slide->is_voting_open) : ?> <?php if ($words !== null && $words['allowUpvotes'] && $slide->is_voting_open) : ?>
<p class="hint" data-upvote-hint><?= $words['allowDownvotes'] <p class="hint" data-upvote-hint><?= $words['allowDownvotes']
? __('Tippe auf einen Begriff, um ihn zu unterstützen, oder auf „−“, um ihn abzulehnen.') ? __('Tippe auf „+“, um einen Begriff zu unterstützen, oder auf „−“, um ihn abzulehnen.')
: __('Tippe auf einen Begriff, um ihn zu unterstützen.') ?></p> : __('Tippe auf „+“, um einen Begriff zu unterstützen.') ?></p>
<?php endif; ?> <?php endif; ?>
<div data-results></div> <div data-results></div>
</section> </section>
+9 -4
View File
@@ -138,10 +138,15 @@ $optionsError = $slide->getError('options_text');
'label' => __('Mehrfachauswahl erlauben'), 'label' => __('Mehrfachauswahl erlauben'),
'checked' => (bool)$settings['multiple'], 'checked' => (bool)$settings['multiple'],
]) ?> ]) ?>
<?= $this->Form->control('settings.comments', [ <?= $this->Form->control('settings.comment_mode', [
'type' => 'checkbox', 'type' => 'select',
'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Auswahl optional begründen)'), 'label' => __('Kommentarfeld'),
'checked' => (bool)$settings['comments'], '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'),
]) ?> ]) ?>
<p class="hint"><?= __('Die Kommentare laufen in der Präsentation nacheinander unter dem Ergebnis durch (nicht bei den Teilnehmenden). Das Tempo stellst du für die ganze Umfrage in den Einstellungen im Dashboard ein.') ?></p> <p class="hint"><?= __('Die Kommentare laufen in der Präsentation nacheinander unter dem Ergebnis durch (nicht bei den Teilnehmenden). Das Tempo stellst du für die ganze Umfrage in den Einstellungen im Dashboard ein.') ?></p>
<?php elseif ($slide->type === 'open') : ?> <?php elseif ($slide->type === 'open') : ?>
@@ -107,7 +107,7 @@ class AdminControllerTest extends TestCase
$slide = $this->slidesTable()->find()->contain(['SlideOptions'])->firstOrFail(); $slide = $this->slidesTable()->find()->contain(['SlideOptions'])->firstOrFail();
$this->assertSame($poll->id, $slide->poll_id); $this->assertSame($poll->id, $slide->poll_id);
$this->assertSame(['Pizza', 'Pasta'], array_map(fn($o) => $o->label, $slide->slide_options)); $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); $this->assertSame(1, $slide->position);
} }
@@ -60,7 +60,7 @@ class ChoiceCommentsTest extends TestCase
{ {
[, $token] = $this->createPoll(); [, $token] = $this->createPoll();
$this->get("/admin/$token/slides/add?type=choice"); $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", [ $this->post("/admin/$token/slides/add?type=choice", [
'type' => 'choice', 'type' => 'choice',
@@ -127,6 +127,37 @@ class VoteServiceTest extends TestCase
$service->editText($poll, $slide, 'p1', ['comment' => '']); $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 public function testMultipleChoiceResults(): void
{ {
[$poll] = $this->createPoll(); [$poll] = $this->createPoll();
+19 -9
View File
@@ -529,7 +529,7 @@ textarea { resize: vertical; }
.donut__label { font-weight: 600; overflow-wrap: anywhere; } .donut__label { font-weight: 600; overflow-wrap: anywhere; }
.donut__value { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; } .donut__value { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .2em .6em; line-height: 1.15; padding: 8px; } .cloud { font-size: calc(1rem * var(--cloud-scale, 1)); display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .2em .6em; line-height: 1.15; padding: 8px; }
.cloud__word { font-weight: 800; color: var(--c0); transition: font-size .6s ease; } .cloud__word { font-weight: 800; color: var(--c0); transition: font-size .6s ease; }
.cloud__word--c1 { color: var(--c1); } .cloud__word--c1 { color: var(--c1); }
.cloud__word--c2 { color: var(--c2); } .cloud__word--c2 { color: var(--c2); }
@@ -542,13 +542,23 @@ textarea { resize: vertical; }
.cloud__count--down { color: var(--danger); } .cloud__count--down { color: var(--danger); }
.stage .cloud__count { font-size: max(.9rem, .4em); } .stage .cloud__count { font-size: max(.9rem, .4em); }
/* Participant cloud: word (+) and − are separate buttons */ /* Participant cloud: word (+) and − are separate buttons */
.cloud--interactive .cloud__word { gap: .1em; } /* Participant list (replaces the cloud on phones): fixed text size, weight bar, big tap targets */
.cloud__vote { font: inherit; font-weight: inherit; color: inherit; line-height: 1.15; background: none; border: 2px solid transparent; border-radius: 10px; padding: .05em .3em; cursor: pointer; display: inline-flex; align-items: baseline; gap: .25em; } .wc-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.cloud__vote:hover:not(:disabled), .cloud__vote:focus-visible { border-color: currentColor; } .wc-item { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 8px 10px 14px; border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.cloud__vote:disabled { cursor: default; } .wc-item__text { flex: 1; min-width: 0; font-weight: 700; word-break: break-word; }
.cloud__vote--down { padding: .05em .25em; } .wc-item__actions { flex: none; display: inline-flex; gap: 6px; }
.cloud__word.is-mine .cloud__vote--up, .cloud__word.is-down .cloud__vote--down { background: var(--surface-2); } .wc-item__bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--c0); border-radius: 0 4px 4px 0; transition: width .6s ease; }
.cloud__word.is-down .cloud__vote--up { opacity: .55; } .wc-item.is-mine { box-shadow: inset 0 0 0 2px var(--ok); }
.wc-item.is-down { opacity: .7; }
.wc-vote { min-width: 56px; min-height: 40px; padding: 0 10px; border-radius: 999px; border: 2px solid currentColor; background: var(--surface); font: inherit; font-size: .9rem; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; }
.wc-vote--up { color: var(--ok); }
.wc-vote--down { color: var(--danger); }
.wc-vote.is-active { background: currentColor; }
.wc-vote.is-active span { color: var(--surface); }
.wc-vote:disabled { cursor: default; }
.wc-vote:disabled:not(.is-active) { opacity: .5; }
.wc-vote:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.wc-count--down { color: var(--danger); font-weight: 700; }
/* quiz results */ /* quiz results */
.quiz-status { color: var(--muted); font-style: italic; margin: 0 0 1em; } .quiz-status { color: var(--muted); font-style: italic; margin: 0 0 1em; }
@@ -791,7 +801,7 @@ body.present {
.stage .donut__chart { width: clamp(150px, 28vh, 340px); } .stage .donut__chart { width: clamp(150px, 28vh, 340px); }
.stage .donut__count { font-size: clamp(.85rem, 1.3vw, 1.2rem); } .stage .donut__count { font-size: clamp(.85rem, 1.3vw, 1.2rem); }
.stage .donut__legend { font-size: clamp(.9rem, 1.4vw, 1.3rem); } .stage .donut__legend { font-size: clamp(.9rem, 1.4vw, 1.3rem); }
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); } .stage .cloud { font-size: calc(clamp(1.2rem, 2.2vw, 2.2rem) * var(--cloud-scale, 1)); gap: .15em .5em; }
.stage .answers { columns: 340px; } .stage .answers { columns: 340px; }
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); } .stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
.stage__timer:empty { display: none; } .stage__timer:empty { display: none; }
+64 -45
View File
@@ -690,10 +690,13 @@
el('div', { class: 'bar__value', text: formatNumber(option.percent) + ' % (' + option.count + ')' }) 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) { 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)]);
}, },
/** /**
@@ -875,6 +878,55 @@
return el('div', { class: 'scale-results' }, [row, comments]); return el('div', { class: 'scale-results' }, [row, comments]);
}, },
/**
* Participant view of a word cloud: a compact list (like Q&A voting) with fixed text size,
* a bar for the relative weight and "+"/"−" buttons. Scales to any number of words.
*/
wordList: function (results, options) {
var mine = (options && options.mine) || [];
var down = (options && options.down) || [];
var onUpvote = options.onUpvote;
var onDownvote = options.onDownvote;
return el('ul', { class: 'wc-list' }, results.words.map(function (word) {
var isMine = mine.indexOf(word.key) >= 0;
var isDown = down.indexOf(word.key) >= 0;
var rated = isMine || isDown;
var downCount = word.down || 0;
var up = el('button', {
type: 'button',
class: 'wc-vote wc-vote--up' + (isMine ? ' is-active' : ''),
'aria-pressed': isMine ? 'true' : 'false',
'aria-label': word.text + ', ' + word.count + ' Stimmen'
+ (isMine ? ', von dir genannt' : (isDown ? '' : ', unterstützen'))
}, [el('span', { 'aria-hidden': 'true', text: (isMine ? '✓ ' : '+') + word.count })]);
up.disabled = rated;
if (!rated) {
up.addEventListener('click', function () { onUpvote(word); });
}
var downEl = null;
if (onDownvote) {
downEl = el('button', {
type: 'button',
class: 'wc-vote wc-vote--down' + (isDown ? ' is-active' : ''),
'aria-pressed': isDown ? 'true' : 'false',
'aria-label': word.text + ', ' + downCount + ' Ablehnungen'
+ (isDown ? ', von dir abgelehnt' : (isMine ? '' : ', ablehnen'))
}, [el('span', { 'aria-hidden': 'true', text: (isDown ? '✓ ' : '−') + downCount })]);
downEl.disabled = rated;
if (!rated) {
downEl.addEventListener('click', function () { onDownvote(word); });
}
} else if (downCount > 0) {
downEl = el('span', { class: 'wc-count--down', text: '−' + downCount });
}
return el('li', { class: 'wc-item' + (isMine ? ' is-mine' : '') + (isDown ? ' is-down' : '') }, [
el('span', { class: 'wc-item__text', text: word.text }),
el('span', { class: 'wc-item__actions' }, [up, downEl]),
el('span', { class: 'wc-item__bar', 'aria-hidden': 'true', style: 'width:' + Math.max(3, Math.round(word.weight * 100)) + '%' })
]);
}));
},
/** /**
* options: {mine: [keys], down: [keys], onUpvote: fn(word)|null, onDownvote: fn(word)|null} * options: {mine: [keys], down: [keys], onUpvote: fn(word)|null, onDownvote: fn(word)|null}
* Counts are shown as "+up" and "−down" (down only when > 0 or clickable). * Counts are shown as "+up" and "−down" (down only when > 0 or clickable).
@@ -894,8 +946,12 @@
ordered.unshift(word); ordered.unshift(word);
} }
}); });
return el('div', { class: 'cloud' + (onUpvote ? ' cloud--interactive' : '') }, ordered.map(function (word, index) { if (onUpvote) {
var size = 0.9 + word.weight * 2.6; return Results.wordList(results, options);
}
var scale = Math.max(0.45, Math.min(1, 1.1 - ordered.length * 0.035));
return el('div', { class: 'cloud', style: '--cloud-scale:' + scale.toFixed(2) }, ordered.map(function (word, index) {
var size = 0.9 + word.weight * 1.6;
var isMine = mine.indexOf(word.key) >= 0; var isMine = mine.indexOf(word.key) >= 0;
var isDown = down.indexOf(word.key) >= 0; var isDown = down.indexOf(word.key) >= 0;
var rated = isMine || isDown; var rated = isMine || isDown;
@@ -906,49 +962,12 @@
title: '+' + word.count + ' / −' + downCount title: '+' + word.count + ' / −' + downCount
+ (isMine ? ' – von dir genannt' : (isDown ? ' – von dir abgelehnt' : '')) + (isMine ? ' – von dir genannt' : (isDown ? ' – von dir abgelehnt' : ''))
}; };
if (!onUpvote) { // Presenter (and participants without upvotes): show the counts next to the word.
// Presenter (and participants without upvotes): show the counts next to the word. return el('span', attrs, [
return el('span', attrs, [
el('span', { text: word.text }),
el('span', { class: 'cloud__count cloud__count--up', text: '+' + word.count }),
downCount > 0 ? el('span', { class: 'cloud__count cloud__count--down', text: '−' + downCount }) : null
]);
}
var up = el('button', {
type: 'button',
class: 'cloud__vote cloud__vote--up',
'aria-pressed': isMine ? 'true' : 'false',
'aria-label': word.text + ', ' + word.count + ' Stimmen'
+ (isMine ? ', von dir genannt' : (isDown ? '' : ', unterstützen'))
}, [
el('span', { text: word.text }), el('span', { text: word.text }),
el('span', { class: 'cloud__count cloud__count--up', 'aria-hidden': 'true', text: (isMine ? '✓ ' : '+') + word.count }) el('span', { class: 'cloud__count cloud__count--up', text: '+' + word.count }),
downCount > 0 ? el('span', { class: 'cloud__count cloud__count--down', text: '−' + downCount }) : null
]); ]);
up.disabled = rated;
if (!rated) {
up.addEventListener('click', function () { onUpvote(word); });
}
var downEl = null;
if (onDownvote) {
downEl = el('button', {
type: 'button',
class: 'cloud__vote cloud__vote--down',
'aria-pressed': isDown ? 'true' : 'false',
'aria-label': word.text + ', ' + downCount + ' Ablehnungen'
+ (isDown ? ', von dir abgelehnt' : (isMine ? '' : ', ablehnen'))
}, [
el('span', { class: 'cloud__count cloud__count--down', 'aria-hidden': 'true', text: (isDown ? '✓ ' : '') + '−' + downCount })
]);
downEl.disabled = rated;
if (!rated) {
downEl.addEventListener('click', function () { onDownvote(word); });
}
} else if (downCount > 0) {
downEl = el('span', { class: 'cloud__count cloud__count--down', text: '−' + downCount });
}
return el('span', attrs, [up, downEl]);
})); }));
}, },