Add optional comment field to multiple choice slides
CI / Deploy / PHP 8.4 (push) Successful in 1m11s
CI / Deploy / PHP 8.5 (push) Successful in 1m11s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

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:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-13 09:29:25 +01:00
1 parent 28bfd535f4
commit 61718ed7c6
14 files changed
+330 -29

No files matched your search

+21 -9
View File
@@ -12,7 +12,9 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* rendered by webroot/js/plenario.js (presenter + participant views).
*
* 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)]]
* (count = participants who named or upvoted the word, down = downvotes,
* weight follows count)
@@ -78,7 +80,7 @@ class ResultsService
];
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_OPEN => $this->open($slide, $limit),
Slide::TYPE_SCALE => $this->scale($slide, $limit, $withRatings),
@@ -141,9 +143,10 @@ class ResultsService
/**
* @param \App\Model\Entity\Slide $slide Slide
* @param int|null $limit Max. comments (newest), null = all
* @return array<string, mixed>
*/
protected function choice(Slide $slide): array
protected function choice(Slide $slide, ?int $limit = null): array
{
$counts = $this->Responses->find()
->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.
*
* @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
* @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
{
// 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()
->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']);
if ($limit !== null) {
$query->limit($limit);
@@ -399,7 +411,7 @@ class ResultsService
$comments[] = [
'id' => (int)$row->id,
'text' => (string)$row->text_value,
'value' => (int)$row->numeric_value,
'value' => $row->numeric_value === null ? null : (int)$row->numeric_value,
'created' => $row->created->toIso8601String(),
];
}