Add optional comment field to multiple choice slides
Participants can justify their choice; the comment is stored once in the first response row, rotates on the stage like scale comments and is listed in the admin area and the PDF export. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
28bfd535f4
commit
61718ed7c6
14 files changed
+330
-29
No files matched your search
@@ -248,6 +248,12 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
|
|||||||
vor/zurück/Pause, Laufbalken bis zum Wechsel (`Comments.progress()`, setzt nach dem Neu-Rendern per negativem
|
vor/zurück/Pause, Laufbalken bis zum Wechsel (`Comments.progress()`, setzt nach dem Neu-Rendern per negativem
|
||||||
`animation-delay` fort, bei Pause unsichtbar), Zustand übersteht das Neu-Rendern beim Polling; die Box ist so hoch wie der längste Kommentar – alle liegen unsichtbar in derselben Grid-Zelle –, damit die zentrierte Bühne beim Wechsel nicht springt; höchstens `--comment-max` ≈ 5 Zeilen, längere Kommentare setzt `Comments.fit()` kleiner statt sie abzuschneiden; die Bewertung steht über dem Text, damit sie an fester Stelle bleibt; der Fortschritt läuft als Rahmen der Box: `Comments.progressBorder()`, SVG-Rechteck mit `pathLength` 100, zwei Linien ab gegenüberliegenden Ecken). Bei internem Feedback erscheinen sie erst,
|
`animation-delay` fort, bei Pause unsichtbar), Zustand übersteht das Neu-Rendern beim Polling; die Box ist so hoch wie der längste Kommentar – alle liegen unsichtbar in derselben Grid-Zelle –, damit die zentrierte Bühne beim Wechsel nicht springt; höchstens `--comment-max` ≈ 5 Zeilen, längere Kommentare setzt `Comments.fit()` kleiner statt sie abzuschneiden; die Bewertung steht über dem Text, damit sie an fester Stelle bleibt; der Fortschritt läuft als Rahmen der Box: `Comments.progressBorder()`, SVG-Rechteck mit `pathLength` 100, zwei Linien ab gegenüberliegenden Ecken). Bei internem Feedback erscheinen sie erst,
|
||||||
wenn der Presenter die Ergebnisse einblendet.
|
wenn der Presenter die Ergebnisse einblendet.
|
||||||
|
- **Kommentare bei Multiple Choice** (Setting `comments`, gleiches `Slide::hasComments()` wie bei Skalen): optionales Feld `comment`,
|
||||||
|
gespeichert als `text_value` **nur in der ersten Zeile** der Person (bei Mehrfachauswahl gibt es mehrere Zeilen; Zählungen
|
||||||
|
gruppieren nach `slide_option_id` und ignorieren `text_value`). Bearbeiten/Anlegen/Leeren wie bei Skalen über `participate:edit`
|
||||||
|
(`editText()` und `ownText()` lesen die Zeile mit der kleinsten id). Presenter/Embed bekommen `results.comments` (`value` immer
|
||||||
|
`null`, keine Zuordnung zur Option), `Results.choice` zeigt sie mit `Comments` unter den Balken; Teilnehmende nie.
|
||||||
|
Volle Liste: `slides:answers` („Kommentare“), PDF-Export unter der Tabelle. Tests: `ChoiceCommentsTest.php`.
|
||||||
- **Sterne-Bewertung** (Skala mit Setting `style = stars`, `Slide::isStarRating()`, Standard `numbers`): immer 1 bis `scale_max`
|
- **Sterne-Bewertung** (Skala mit Setting `style = stars`, `Slide::isStarRating()`, Standard `numbers`): immer 1 bis `scale_max`
|
||||||
Sterne (`SlidesTable::sanitizeSettings()` erzwingt `scale_min = 1`), gespeichert wie jede Skala als `numeric_value`.
|
Sterne (`SlidesTable::sanitizeSettings()` erzwingt `scale_min = 1`), gespeichert wie jede Skala als `numeric_value`.
|
||||||
Teilnehmende wählen Sterne (Radios in DOM-Reihenfolge 1..n, Füllung per CSS `:has()`), der State enthält `results.stars`;
|
Teilnehmende wählen Sterne (Radios in DOM-Reihenfolge 1..n, Füllung per CSS `:has()`), der State enthält `results.stars`;
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class SlidesController extends AdminAppController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All answers of an open question or the ratings of a scale
|
* All answers of an open question, the ratings of a scale or the comments of a choice slide
|
||||||
* (also anonymous/internal feedback, which is never shown on the stage).
|
* (also anonymous/internal feedback, which is never shown on the stage).
|
||||||
*
|
*
|
||||||
* @param string $id Slide id
|
* @param string $id Slide id
|
||||||
@@ -210,7 +210,7 @@ class SlidesController extends AdminAppController
|
|||||||
public function answers(string $id): void
|
public function answers(string $id): void
|
||||||
{
|
{
|
||||||
$slide = $this->loadSlide($id);
|
$slide = $this->loadSlide($id);
|
||||||
if (!in_array($slide->type, [Slide::TYPE_OPEN, Slide::TYPE_SCALE], true)) {
|
if (!in_array($slide->type, [Slide::TYPE_OPEN, Slide::TYPE_SCALE], true) && !$slide->hasComments()) {
|
||||||
throw new NotFoundException(__('Folie nicht gefunden.'));
|
throw new NotFoundException(__('Folie nicht gefunden.'));
|
||||||
}
|
}
|
||||||
$results = new ResultsService();
|
$results = new ResultsService();
|
||||||
|
|||||||
@@ -101,7 +101,9 @@ class Slide extends Entity
|
|||||||
* @var array<string, array<string, mixed>>
|
* @var array<string, array<string, mixed>>
|
||||||
*/
|
*/
|
||||||
public const DEFAULT_SETTINGS = [
|
public const DEFAULT_SETTINGS = [
|
||||||
self::TYPE_CHOICE => ['multiple' => false],
|
// 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],
|
||||||
// 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],
|
self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true],
|
||||||
// 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)
|
||||||
@@ -500,13 +502,13 @@ class Slide extends Entity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scale with an optional comment field for participants.
|
* Multiple choice or scale with an optional comment field for participants.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasComments(): bool
|
public function hasComments(): bool
|
||||||
{
|
{
|
||||||
return $this->type === self::TYPE_SCALE && (bool)$this->setting('comments');
|
return in_array($this->type, [self::TYPE_CHOICE, self::TYPE_SCALE], true) && (bool)$this->setting('comments');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -142,6 +142,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);
|
||||||
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);
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
|||||||
* rendered by webroot/js/plenario.js (presenter + participant views).
|
* rendered by webroot/js/plenario.js (presenter + participant views).
|
||||||
*
|
*
|
||||||
* Shape (always present): ['type' => string, 'participants' => int, ...]
|
* Shape (always present): ['type' => string, 'participants' => int, ...]
|
||||||
* - choice: 'options' => [['id', 'label', 'count', 'percent']]
|
* - choice: 'options' => [['id', 'label', 'count', 'percent']], 'votes' (int),
|
||||||
|
* 'comments' => [['id', 'text', 'value' (always null)]] oldest first (only with the comment
|
||||||
|
* field, else []; presentation only, participants never get results of choice slides)
|
||||||
* - wordcloud: 'words' => [['key' (lower case), 'text', 'count', 'down', 'weight' (0..1)]]
|
* - wordcloud: 'words' => [['key' (lower case), 'text', 'count', 'down', 'weight' (0..1)]]
|
||||||
* (count = participants who named or upvoted the word, down = downvotes,
|
* (count = participants who named or upvoted the word, down = downvotes,
|
||||||
* weight follows count)
|
* weight follows count)
|
||||||
@@ -78,7 +80,7 @@ class ResultsService
|
|||||||
];
|
];
|
||||||
|
|
||||||
return $result + match ($slide->type) {
|
return $result + match ($slide->type) {
|
||||||
Slide::TYPE_CHOICE => $this->choice($slide),
|
Slide::TYPE_CHOICE => $this->choice($slide, $limit),
|
||||||
Slide::TYPE_WORDCLOUD => $this->wordcloud($slide),
|
Slide::TYPE_WORDCLOUD => $this->wordcloud($slide),
|
||||||
Slide::TYPE_OPEN => $this->open($slide, $limit),
|
Slide::TYPE_OPEN => $this->open($slide, $limit),
|
||||||
Slide::TYPE_SCALE => $this->scale($slide, $limit, $withRatings),
|
Slide::TYPE_SCALE => $this->scale($slide, $limit, $withRatings),
|
||||||
@@ -141,9 +143,10 @@ class ResultsService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \App\Model\Entity\Slide $slide Slide
|
* @param \App\Model\Entity\Slide $slide Slide
|
||||||
|
* @param int|null $limit Max. comments (newest), null = all
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
protected function choice(Slide $slide): array
|
protected function choice(Slide $slide, ?int $limit = null): array
|
||||||
{
|
{
|
||||||
$counts = $this->Responses->find()
|
$counts = $this->Responses->find()
|
||||||
->select(['slide_option_id', 'n' => $this->Responses->find()->func()->count('*')])
|
->select(['slide_option_id', 'n' => $this->Responses->find()->func()->count('*')])
|
||||||
@@ -166,7 +169,13 @@ class ResultsService
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['options' => $options, 'votes' => $total];
|
$comments = [];
|
||||||
|
foreach ($slide->hasComments() ? $this->comments($slide, $limit) : [] as $comment) {
|
||||||
|
// No option next to the comment: with several choices it would only be a guess anyway.
|
||||||
|
$comments[] = ['id' => $comment['id'], 'text' => $comment['text'], 'value' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['options' => $options, 'votes' => $total, 'comments' => $comments];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -377,18 +386,21 @@ class ResultsService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comments of a scale with their rating, oldest first; the unfiltered call
|
* Comments of a scale with their rating (choice: without value), oldest first; the unfiltered call
|
||||||
* (ratings regardless of comment_ratings) is only for the admin area.
|
* (ratings regardless of comment_ratings) is only for the admin area.
|
||||||
*
|
*
|
||||||
* @param \App\Model\Entity\Slide $slide Scale slide
|
* @param \App\Model\Entity\Slide $slide Scale or choice slide
|
||||||
* @param int|null $limit Max. comments (the newest ones), null = all
|
* @param int|null $limit Max. comments (the newest ones), null = all
|
||||||
* @return list<array{id: int, text: string, value: int, created: string}>
|
* @return list<array{id: int, text: string, value: int|null, created: string}>
|
||||||
*/
|
*/
|
||||||
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. Choice: the comment sits in the first of the
|
||||||
|
// participant's rows, which always has an option.
|
||||||
|
$answered = $slide->type === Slide::TYPE_CHOICE ? 'slide_option_id IS NOT' : 'numeric_value IS NOT';
|
||||||
$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, 'numeric_value IS NOT' => null])
|
->where(['slide_id' => $slide->id, 'text_value IS NOT' => null, $answered => null])
|
||||||
->orderBy(['id' => 'DESC']);
|
->orderBy(['id' => 'DESC']);
|
||||||
if ($limit !== null) {
|
if ($limit !== null) {
|
||||||
$query->limit($limit);
|
$query->limit($limit);
|
||||||
@@ -399,7 +411,7 @@ class ResultsService
|
|||||||
$comments[] = [
|
$comments[] = [
|
||||||
'id' => (int)$row->id,
|
'id' => (int)$row->id,
|
||||||
'text' => (string)$row->text_value,
|
'text' => (string)$row->text_value,
|
||||||
'value' => (int)$row->numeric_value,
|
'value' => $row->numeric_value === null ? null : (int)$row->numeric_value,
|
||||||
'created' => $row->created->toIso8601String(),
|
'created' => $row->created->toIso8601String(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,20 +136,20 @@ class VoteService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the participant may change the text of their answer afterwards (e.g. to fix a typo):
|
* Whether the participant may change the text of their answer afterwards (e.g. to fix a typo):
|
||||||
* the answer of an open question and the comment of a scale with comment field.
|
* the answer of an open question and the comment of a choice or scale slide with comment field.
|
||||||
*
|
*
|
||||||
* @param \App\Model\Entity\Slide $slide Slide
|
* @param \App\Model\Entity\Slide $slide Slide
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function hasEditableText(Slide $slide): bool
|
public static function hasEditableText(Slide $slide): bool
|
||||||
{
|
{
|
||||||
return $slide->type === Slide::TYPE_OPEN || ($slide->type === Slide::TYPE_SCALE && $slide->hasComments());
|
return $slide->type === Slide::TYPE_OPEN || $slide->hasComments();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the text of the participant's own answer as long as voting on the slide is open
|
* Replaces the text of the participant's own answer as long as voting on the slide is open
|
||||||
* (see hasEditableText()). Open question: `text`, must not be empty. Scale: `comment`, the
|
* (see hasEditableText()). Open question: `text`, must not be empty. Choice/scale: `comment`, the
|
||||||
* rating itself stays unchanged and an empty comment removes it. Same preconditions as submit().
|
* selection or rating itself stays unchanged and an empty comment removes it. Same preconditions as submit().
|
||||||
*
|
*
|
||||||
* @param \App\Model\Entity\Poll $poll Poll
|
* @param \App\Model\Entity\Poll $poll Poll
|
||||||
* @param \App\Model\Entity\Slide $slide Slide
|
* @param \App\Model\Entity\Slide $slide Slide
|
||||||
@@ -167,13 +167,17 @@ class VoteService
|
|||||||
$text = $slide->type === Slide::TYPE_OPEN ? $this->openRows($data)[0]['text_value'] : self::comment($data);
|
$text = $slide->type === Slide::TYPE_OPEN ? $this->openRows($data)[0]['text_value'] : self::comment($data);
|
||||||
$this->Responses->getConnection()->transactional(function () use ($slide, $participantHash, $text): void {
|
$this->Responses->getConnection()->transactional(function () use ($slide, $participantHash, $text): void {
|
||||||
$this->lockSlide($slide);
|
$this->lockSlide($slide);
|
||||||
|
// A multiple choice answer has several rows; the comment always lives in the first one.
|
||||||
$row = $this->Responses->find()
|
$row = $this->Responses->find()
|
||||||
->where(['slide_id' => $slide->id, 'participant_hash' => $participantHash])
|
->where(['slide_id' => $slide->id, 'participant_hash' => $participantHash])
|
||||||
|
->orderBy(['id' => 'ASC'])
|
||||||
->first();
|
->first();
|
||||||
if ($row === null) {
|
if ($row === null) {
|
||||||
throw new VoteException($slide->type === Slide::TYPE_OPEN
|
throw new VoteException(match ($slide->type) {
|
||||||
? __('Du hast hier noch nicht geantwortet.')
|
Slide::TYPE_OPEN => __('Du hast hier noch nicht geantwortet.'),
|
||||||
: __('Bitte gib zuerst deine Bewertung ab.'));
|
Slide::TYPE_CHOICE => __('Bitte gib zuerst deine Auswahl ab.'),
|
||||||
|
default => __('Bitte gib zuerst deine Bewertung ab.'),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
$row->text_value = $text;
|
$row->text_value = $text;
|
||||||
$this->Responses->saveOrFail($row);
|
$this->Responses->saveOrFail($row);
|
||||||
@@ -181,7 +185,7 @@ class VoteService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text of the participant's own answer: open answer or scale comment (null: none or not answered yet).
|
* Text of the participant's own answer: open answer or choice/scale comment (null: none or not answered yet).
|
||||||
*
|
*
|
||||||
* @param \App\Model\Entity\Slide $slide Slide
|
* @param \App\Model\Entity\Slide $slide Slide
|
||||||
* @param string $participantHash Participant hash
|
* @param string $participantHash Participant hash
|
||||||
@@ -192,6 +196,7 @@ class VoteService
|
|||||||
$row = $this->Responses->find()
|
$row = $this->Responses->find()
|
||||||
->select(['text_value'])
|
->select(['text_value'])
|
||||||
->where(['slide_id' => $slide->id, 'participant_hash' => $participantHash])
|
->where(['slide_id' => $slide->id, 'participant_hash' => $participantHash])
|
||||||
|
->orderBy(['id' => 'ASC'])
|
||||||
->disableHydration()
|
->disableHydration()
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -281,7 +286,15 @@ class VoteService
|
|||||||
throw new VoteException(__('Bitte wähle nur eine Antwort aus.'));
|
throw new VoteException(__('Bitte wähle nur eine Antwort aus.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_map(fn(int $id) => ['slide_option_id' => $id], $selected);
|
// The optional comment goes into the first row only, so it is stored once per participant;
|
||||||
|
// counts group by option and ignore text_value.
|
||||||
|
$comment = $slide->hasComments() ? self::comment($data) : null;
|
||||||
|
|
||||||
|
return array_map(
|
||||||
|
fn(int $id, int $index) => ['slide_option_id' => $id, 'text_value' => $index === 0 ? $comment : null],
|
||||||
|
$selected,
|
||||||
|
array_keys($selected),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -103,6 +103,18 @@ $bar = function (float $percent, bool $ok = false): string {
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<?php if ($slide->hasComments()) : ?>
|
||||||
|
<h3><?= __n('{0} Kommentar', '{0} Kommentare', count($r['comments']), count($r['comments'])) ?></h3>
|
||||||
|
<?php if ($r['comments'] === []) : ?>
|
||||||
|
<p class="empty"><?= __('Keine Kommentare.') ?></p>
|
||||||
|
<?php else : ?>
|
||||||
|
<ol class="list">
|
||||||
|
<?php foreach ($r['comments'] as $comment) : ?>
|
||||||
|
<li><?= nl2br(h($comment['text'])) ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ol>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php elseif ($slide->type === 'quiz') : ?>
|
<?php elseif ($slide->type === 'quiz') : ?>
|
||||||
<?php if (!$r['revealed']) : ?>
|
<?php if (!$r['revealed']) : ?>
|
||||||
|
|||||||
@@ -143,7 +143,11 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
|
|||||||
]) ?>
|
]) ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if (($slide->type === 'open' || $slide->isPrivate() || $slide->hasComments()) && $count > 0) :
|
<?php if (($slide->type === 'open' || $slide->isPrivate() || $slide->hasComments()) && $count > 0) :
|
||||||
$answersLabel = $slide->type === 'scale' ? __('Auswertung') : __('Antworten'); ?>
|
$answersLabel = match ($slide->type) {
|
||||||
|
'scale' => __('Auswertung'),
|
||||||
|
'choice' => __('Kommentare'),
|
||||||
|
default => __('Antworten'),
|
||||||
|
}; ?>
|
||||||
<a class="button button--small button--icon" href="<?= $this->Url->build($url('slides:answers', ['id' => $slide->id])) ?>"
|
<a class="button button--small button--icon" href="<?= $this->Url->build($url('slides:answers', ['id' => $slide->id])) ?>"
|
||||||
title="<?= h($answersLabel) ?>" aria-label="<?= h(__('{0} der Folie „{1}“ ansehen', $answersLabel, $slide->question)) ?>">📊</a>
|
title="<?= h($answersLabel) ?>" aria-label="<?= h(__('{0} der Folie „{1}“ ansehen', $answersLabel, $slide->question)) ?>">📊</a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -266,7 +266,9 @@ $countdown = function (?int $remaining): string {
|
|||||||
aria-describedby="edit-text-hint"><?= h((string)$ownText) ?></textarea>
|
aria-describedby="edit-text-hint"><?= h((string)$ownText) ?></textarea>
|
||||||
<p class="hint" id="edit-text-hint"><?= $isOpen
|
<p class="hint" id="edit-text-hint"><?= $isOpen
|
||||||
? __('Möglich, solange die Abstimmung läuft.')
|
? __('Möglich, solange die Abstimmung läuft.')
|
||||||
: __('Möglich, solange die Abstimmung läuft. Ein leeres Feld entfernt deinen Kommentar, deine Bewertung bleibt.') ?></p>
|
: ($slide->type === 'choice'
|
||||||
|
? __('Möglich, solange die Abstimmung läuft. Ein leeres Feld entfernt deinen Kommentar, deine Auswahl bleibt.')
|
||||||
|
: __('Möglich, solange die Abstimmung läuft. Ein leeres Feld entfernt deinen Kommentar, deine Bewertung bleibt.')) ?></p>
|
||||||
<?= $this->Form->button($isOpen ? __('Antwort speichern') : __('Kommentar speichern'), ['class' => 'button button--primary button--block']) ?>
|
<?= $this->Form->button($isOpen ? __('Antwort speichern') : __('Kommentar speichern'), ['class' => 'button button--primary button--block']) ?>
|
||||||
<?= $this->Form->end() ?>
|
<?= $this->Form->end() ?>
|
||||||
</details>
|
</details>
|
||||||
@@ -290,6 +292,11 @@ $countdown = function (?int $remaining): string {
|
|||||||
</label>
|
</label>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
|
<?php if ($slide->hasComments()) : ?>
|
||||||
|
<label class="scale-comment" for="choice-comment"><?= __('Kommentar (optional)') ?></label>
|
||||||
|
<textarea id="choice-comment" name="comment" rows="3" maxlength="500"
|
||||||
|
placeholder="<?= __('Möchtest du deine Auswahl begründen?') ?>"></textarea>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php elseif ($slide->type === 'open') : ?>
|
<?php elseif ($slide->type === 'open') : ?>
|
||||||
<textarea name="text" rows="4" maxlength="500" required
|
<textarea name="text" rows="4" maxlength="500" required
|
||||||
|
|||||||
@@ -9,13 +9,18 @@
|
|||||||
* @var \App\Model\Entity\Slide $slide
|
* @var \App\Model\Entity\Slide $slide
|
||||||
* @var list<array{text: string, created: string}> $answers
|
* @var list<array{text: string, created: string}> $answers
|
||||||
* @var array<string, mixed>|null $scale Distribution of a scale slide, null for open questions
|
* @var array<string, mixed>|null $scale Distribution of a scale slide, null for open questions
|
||||||
* @var list<array{id: int, text: string, value: int, created: string}> $comments Comments of a scale, oldest first
|
* @var list<array{id: int, text: string, value: int|null, created: string}> $comments Comments of a scale or choice slide, oldest first
|
||||||
*/
|
*/
|
||||||
use Cake\I18n\DateTime;
|
use Cake\I18n\DateTime;
|
||||||
|
|
||||||
$this->assign('title', $slide->question);
|
$this->assign('title', $slide->question);
|
||||||
$this->assign('noindex', '1');
|
$this->assign('noindex', '1');
|
||||||
$count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) : count($answers);
|
$isChoice = $slide->type === 'choice';
|
||||||
|
$count = match (true) {
|
||||||
|
$scale !== null => array_sum(array_column($scale['buckets'], 'count')),
|
||||||
|
$isChoice => count($comments),
|
||||||
|
default => count($answers),
|
||||||
|
};
|
||||||
?>
|
?>
|
||||||
<p><a href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>">← <?= __('Zurück zur Verwaltung') ?></a></p>
|
<p><a href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>">← <?= __('Zurück zur Verwaltung') ?></a></p>
|
||||||
|
|
||||||
@@ -27,6 +32,8 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
|||||||
<h1><?= h($slide->question) ?></h1>
|
<h1><?= h($slide->question) ?></h1>
|
||||||
<?php if ($scale !== null) : ?>
|
<?php if ($scale !== null) : ?>
|
||||||
<p class="muted"><?= __n('{0} Bewertung', '{0} Bewertungen', $count, $count) ?></p>
|
<p class="muted"><?= __n('{0} Bewertung', '{0} Bewertungen', $count, $count) ?></p>
|
||||||
|
<?php elseif ($isChoice) : ?>
|
||||||
|
<p class="muted"><?= __n('{0} Kommentar, neueste zuerst', '{0} Kommentare, neueste zuerst', $count, $count) ?></p>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
<p class="muted"><?= __n('{0} Antwort, neueste zuerst', '{0} Antworten, neueste zuerst', $count, $count) ?></p>
|
<p class="muted"><?= __n('{0} Antwort, neueste zuerst', '{0} Antworten, neueste zuerst', $count, $count) ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -85,6 +92,20 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
|||||||
</ol>
|
</ol>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
<?php elseif ($isChoice) : ?>
|
||||||
|
<?php if ($comments === []) : ?>
|
||||||
|
<p class="empty"><?= __('Noch keine Kommentare.') ?></p>
|
||||||
|
<?php else : ?>
|
||||||
|
<ol class="answers-page" reversed>
|
||||||
|
<?php foreach (array_reverse($comments) as $comment) :
|
||||||
|
$created = new DateTime($comment['created']); ?>
|
||||||
|
<li>
|
||||||
|
<?= h($comment['text']) ?>
|
||||||
|
<time datetime="<?= h($comment['created']) ?>"><?= h($created->i18nFormat('dd.MM.yyyy, HH:mm')) ?></time>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ol>
|
||||||
|
<?php endif; ?>
|
||||||
<?php elseif ($answers === []) : ?>
|
<?php elseif ($answers === []) : ?>
|
||||||
<p class="empty"><?= __('Noch keine Antworten.') ?></p>
|
<p class="empty"><?= __('Noch keine Antworten.') ?></p>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|||||||
@@ -132,6 +132,12 @@ $optionsError = $slide->getError('options_text');
|
|||||||
'label' => __('Mehrfachauswahl erlauben'),
|
'label' => __('Mehrfachauswahl erlauben'),
|
||||||
'checked' => (bool)$settings['multiple'],
|
'checked' => (bool)$settings['multiple'],
|
||||||
]) ?>
|
]) ?>
|
||||||
|
<?= $this->Form->control('settings.comments', [
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Auswahl optional begründen)'),
|
||||||
|
'checked' => (bool)$settings['comments'],
|
||||||
|
]) ?>
|
||||||
|
<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') : ?>
|
||||||
<?= $this->Form->control('settings.private', [
|
<?= $this->Form->control('settings.private', [
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
|
|||||||
@@ -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], $slide->settings);
|
$this->assertSame(['multiple' => true, 'comments' => false], $slide->settings);
|
||||||
$this->assertSame(1, $slide->position);
|
$this->assertSame(1, $slide->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,213 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Test\TestCase\Controller;
|
||||||
|
|
||||||
|
use App\Model\Entity\Poll;
|
||||||
|
use App\Model\Entity\Slide;
|
||||||
|
use App\Model\Table\SlidesTable;
|
||||||
|
use App\Service\ResultsService;
|
||||||
|
use App\Service\VoteException;
|
||||||
|
use App\Service\VoteService;
|
||||||
|
use App\Test\TestCase\PlenarioTestTrait;
|
||||||
|
use Cake\TestSuite\IntegrationTestTrait;
|
||||||
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiple choice slides with an optional comment field (stored once per participant in the first row).
|
||||||
|
*/
|
||||||
|
class ChoiceCommentsTest extends TestCase
|
||||||
|
{
|
||||||
|
use IntegrationTestTrait;
|
||||||
|
use PlenarioTestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->enableCsrfToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $settings Extra settings
|
||||||
|
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
|
||||||
|
*/
|
||||||
|
protected function choiceWithComments(array $settings = ['comments' => true, 'multiple' => true]): array
|
||||||
|
{
|
||||||
|
[$poll, $token] = $this->createPoll();
|
||||||
|
$slide = $this->createSlide($poll, Slide::TYPE_CHOICE, ['settings' => $settings], ['Ja', 'Nein', 'Vielleicht']);
|
||||||
|
$poll = $this->goLive($poll, $slide);
|
||||||
|
|
||||||
|
return [$poll, $token, $slide];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function hash(string $char, Poll $poll): string
|
||||||
|
{
|
||||||
|
return VoteService::participantHash(str_repeat($char, 32), $poll->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSettingIsSanitized(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(SlidesTable::sanitizeSettings(Slide::TYPE_CHOICE, ['comments' => '1'])['comments']);
|
||||||
|
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_CHOICE, [])['comments']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormShowsAndSavesCommentSetting(): void
|
||||||
|
{
|
||||||
|
[, $token] = $this->createPoll();
|
||||||
|
$this->get("/admin/$token/slides/add?type=choice");
|
||||||
|
$this->assertResponseContains('name="settings[comments]"');
|
||||||
|
|
||||||
|
$this->post("/admin/$token/slides/add?type=choice", [
|
||||||
|
'type' => 'choice',
|
||||||
|
'question' => 'Was nehmen wir?',
|
||||||
|
'options_text' => "Ja\nNein",
|
||||||
|
'settings' => ['comments' => '1'],
|
||||||
|
]);
|
||||||
|
$slide = $this->slidesTable()->find()->firstOrFail();
|
||||||
|
$this->assertTrue($slide->hasComments());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParticipantPageShowsCommentFieldOnlyWhenEnabled(): void
|
||||||
|
{
|
||||||
|
[$poll] = $this->choiceWithComments();
|
||||||
|
$this->get('/p/' . $poll->join_code);
|
||||||
|
$this->assertResponseContains('name="comment"');
|
||||||
|
|
||||||
|
[$other] = $this->choiceWithComments(['multiple' => true]);
|
||||||
|
$this->get('/p/' . $other->join_code);
|
||||||
|
$this->assertResponseNotContains('name="comment"');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCommentIsStoredOnceInFirstRowAndCountsStayCorrect(): void
|
||||||
|
{
|
||||||
|
[$poll, , $slide] = $this->choiceWithComments();
|
||||||
|
$options = array_map(fn($o) => $o->id, $slide->slide_options);
|
||||||
|
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), [
|
||||||
|
'option_ids' => [$options[0], $options[2]],
|
||||||
|
'comment' => ' Weil <deshalb> ',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rows = $this->slidesTable()->Responses->find()->where(['slide_id' => $slide->id])->orderBy(['id' => 'ASC'])->all()->toList();
|
||||||
|
$this->assertCount(2, $rows);
|
||||||
|
$this->assertSame('Weil <deshalb>', $rows[0]->text_value);
|
||||||
|
$this->assertNull($rows[1]->text_value);
|
||||||
|
|
||||||
|
$results = (new ResultsService())->forSlide($slide);
|
||||||
|
$this->assertSame([1, 0, 1], array_column($results['options'], 'count'));
|
||||||
|
$this->assertSame(2, $results['votes']);
|
||||||
|
$this->assertSame(1, $results['participants']);
|
||||||
|
$this->assertSame(['Weil <deshalb>'], array_column($results['comments'], 'text'));
|
||||||
|
$this->assertSame([null], array_column($results['comments'], 'value'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCommentIsIgnoredWithoutCommentField(): void
|
||||||
|
{
|
||||||
|
[$poll, , $slide] = $this->choiceWithComments(['multiple' => false]);
|
||||||
|
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), [
|
||||||
|
'option_id' => $slide->slide_options[0]->id,
|
||||||
|
'comment' => 'Eingeschmuggelt',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$row = $this->slidesTable()->Responses->find()->where(['slide_id' => $slide->id])->firstOrFail();
|
||||||
|
$this->assertNull($row->text_value);
|
||||||
|
$this->assertSame([], (new ResultsService())->forSlide($slide)['comments']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTooLongCommentIsRejected(): void
|
||||||
|
{
|
||||||
|
[$poll, , $slide] = $this->choiceWithComments();
|
||||||
|
|
||||||
|
$this->expectException(VoteException::class);
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), [
|
||||||
|
'option_ids' => [$slide->slide_options[0]->id],
|
||||||
|
'comment' => str_repeat('x', VoteService::MAX_TEXT_LENGTH + 1),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCommentCanBeEditedAddedAndRemoved(): void
|
||||||
|
{
|
||||||
|
[$poll, , $slide] = $this->choiceWithComments();
|
||||||
|
$hash = $this->hash('a', $poll);
|
||||||
|
$votes = new VoteService();
|
||||||
|
$votes->submit($poll, $slide, $hash, [
|
||||||
|
'option_ids' => [$slide->slide_options[0]->id, $slide->slide_options[1]->id],
|
||||||
|
]);
|
||||||
|
$this->assertNull($votes->ownText($slide, $hash));
|
||||||
|
|
||||||
|
$votes->editText($poll, $slide, $hash, ['comment' => 'Nachgereicht']);
|
||||||
|
$this->assertSame('Nachgereicht', $votes->ownText($slide, $hash));
|
||||||
|
|
||||||
|
$votes->editText($poll, $slide, $hash, ['comment' => 'Korrigiert']);
|
||||||
|
$this->assertSame(['Korrigiert'], array_column((new ResultsService())->comments($slide), 'text'));
|
||||||
|
$this->assertSame(2, $this->slidesTable()->Responses->find()->where(['slide_id' => $slide->id])->count());
|
||||||
|
|
||||||
|
$votes->editText($poll, $slide, $hash, ['comment' => '']);
|
||||||
|
$this->assertNull($votes->ownText($slide, $hash));
|
||||||
|
$this->assertSame([], (new ResultsService())->comments($slide));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEditRequiresAnAnswer(): void
|
||||||
|
{
|
||||||
|
[$poll, , $slide] = $this->choiceWithComments();
|
||||||
|
|
||||||
|
$this->expectException(VoteException::class);
|
||||||
|
(new VoteService())->editText($poll, $slide, $this->hash('z', $poll), ['comment' => 'Ohne Auswahl']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPresenterGetsCommentsButParticipantsNever(): void
|
||||||
|
{
|
||||||
|
[$poll, $token, $slide] = $this->choiceWithComments();
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), [
|
||||||
|
'option_ids' => [$slide->slide_options[0]->id],
|
||||||
|
'comment' => 'Sichtbar auf der Bühne',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get("/admin/$token/state");
|
||||||
|
$results = json_decode((string)$this->_response->getBody(), true)['results'];
|
||||||
|
$this->assertSame(['Sichtbar auf der Bühne'], array_column($results['comments'], 'text'));
|
||||||
|
|
||||||
|
$this->get('/p/' . $poll->join_code . '/state');
|
||||||
|
$state = json_decode((string)$this->_response->getBody(), true);
|
||||||
|
$this->assertNull($state['results']);
|
||||||
|
$this->assertStringNotContainsString('Sichtbar auf der Bühne', (string)$this->_response->getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAnswersPageListsCommentsOfChoiceSlides(): void
|
||||||
|
{
|
||||||
|
[$poll, $token, $slide] = $this->choiceWithComments();
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), [
|
||||||
|
'option_ids' => [$slide->slide_options[0]->id],
|
||||||
|
'comment' => 'Erster <Kommentar>',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
||||||
|
$this->assertResponseOk();
|
||||||
|
$this->assertResponseContains('Erster <Kommentar>');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAnswersPageIsNotFoundForChoiceWithoutComments(): void
|
||||||
|
{
|
||||||
|
[, $token, $slide] = $this->choiceWithComments(['multiple' => false]);
|
||||||
|
|
||||||
|
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
||||||
|
$this->assertResponseCode(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExportContainsComments(): void
|
||||||
|
{
|
||||||
|
[$poll, $token, $slide] = $this->choiceWithComments();
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), [
|
||||||
|
'option_ids' => [$slide->slide_options[0]->id],
|
||||||
|
'comment' => 'Im PDF enthalten',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertStringContainsString('Im PDF enthalten', $this->exportHtml($token));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -610,7 +610,7 @@
|
|||||||
|
|
||||||
choice: function (results) {
|
choice: function (results) {
|
||||||
var max = Math.max.apply(null, results.options.map(function (o) { return o.count; }).concat([1]));
|
var max = Math.max.apply(null, results.options.map(function (o) { return o.count; }).concat([1]));
|
||||||
return el('div', { class: 'bars' }, results.options.map(function (option, index) {
|
var bars = el('div', { class: 'bars' }, results.options.map(function (option, index) {
|
||||||
return el('div', { class: 'bar bar--c' + (index % 6) }, [
|
return el('div', { class: 'bar bar--c' + (index % 6) }, [
|
||||||
el('div', { class: 'bar__label', text: option.label }),
|
el('div', { class: 'bar__label', text: option.label }),
|
||||||
el('div', { class: 'bar__track' }, [
|
el('div', { class: 'bar__track' }, [
|
||||||
@@ -619,6 +619,10 @@
|
|||||||
el('div', { class: 'bar__value', text: formatNumber(option.percent) + ' % (' + option.count + ')' })
|
el('div', { class: 'bar__value', text: formatNumber(option.percent) + ' % (' + option.count + ')' })
|
||||||
]);
|
]);
|
||||||
}));
|
}));
|
||||||
|
if (!results.comments || !results.comments.length) {
|
||||||
|
return bars;
|
||||||
|
}
|
||||||
|
return el('div', { class: 'choice-results' }, [bars, Comments.render(results.comments, String)]);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user