Add internal feedback and comments to scale slides

- Setting "private": distribution and average are only shown in the
  admin evaluation page and CSV export, the stage shows just the count.
- Setting "comments": optional comment field for participants; on public
  scales the comments rotate on the results ("Kommentar X von N") with
  previous/next/pause controls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-08 15:52:55 +01:00
1 parent a138425ab0
commit 238797ecfd
15 files changed
+665 -23

No files matched your search

+2
View File
@@ -310,6 +310,8 @@ class AdminController extends AdminAppController
$response->slide_option_id !== null => $labels[$response->slide_option_id] ?? '',
$response->text_value !== null && $response->numeric_value === VoteService::DOWNVOTE
=> __('Downvote: {0}', $response->text_value),
$slide->type === Slide::TYPE_SCALE && $response->text_value !== null
=> __('{0} (Kommentar: {1})', $response->numeric_value, $response->text_value),
$response->numeric_value !== null => (string)$response->numeric_value,
default => (string)$response->text_value,
};
+7 -3
View File
@@ -164,7 +164,8 @@ class SlidesController extends AdminAppController
}
/**
* All answers of an open question (also anonymous feedback, which is never shown on the stage).
* All answers of an open question or the ratings of a scale
* (also anonymous/internal feedback, which is never shown on the stage).
*
* @param string $id Slide id
* @return void
@@ -172,11 +173,14 @@ class SlidesController extends AdminAppController
public function answers(string $id): void
{
$slide = $this->loadSlide($id);
if ($slide->type !== Slide::TYPE_OPEN) {
if (!in_array($slide->type, [Slide::TYPE_OPEN, Slide::TYPE_SCALE], true)) {
throw new NotFoundException(__('Folie nicht gefunden.'));
}
$results = new ResultsService();
$this->set('slide', $slide);
$this->set('answers', (new ResultsService())->answers($slide));
$this->set('answers', $slide->type === Slide::TYPE_OPEN ? $results->answers($slide) : []);
$this->set('scale', $slide->type === Slide::TYPE_SCALE ? $results->scaleResults($slide) : null);
$this->set('comments', $slide->hasComments() ? $results->comments($slide) : []);
}
/**
+18 -4
View File
@@ -84,7 +84,11 @@ class Slide extends Entity
self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true],
// private: anonymous feedback, answers only visible in the admin area (never on the stage)
self::TYPE_OPEN => ['private' => false],
self::TYPE_SCALE => ['scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => ''],
// private: internal feedback, ratings only visible in the admin area (never on the stage)
// comments: optional comment field, comments rotate on the results (unless private)
self::TYPE_SCALE => [
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false, 'comments' => false,
],
self::TYPE_CONTENT => [],
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
self::TYPE_QUIZ => ['time_limit' => 30],
@@ -377,13 +381,23 @@ class Slide extends Entity
}
/**
* Open question collecting anonymous feedback: answers are never shown on the
* presenter screen or to participants, only in the admin area and the CSV export.
* Open question or scale collecting anonymous/internal feedback: answers and ratings are
* never shown on the presenter screen or to participants, only in the admin area and the CSV export.
*
* @return bool
*/
public function isPrivate(): bool
{
return $this->type === self::TYPE_OPEN && (bool)$this->setting('private');
return in_array($this->type, [self::TYPE_OPEN, self::TYPE_SCALE], true) && (bool)$this->setting('private');
}
/**
* Scale with an optional comment field for participants.
*
* @return bool
*/
public function hasComments(): bool
{
return $this->type === self::TYPE_SCALE && (bool)$this->setting('comments');
}
}
+2
View File
@@ -156,6 +156,8 @@ class SlidesTable extends Table
$settings['scale_max'] = $max;
$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);
$settings['comments'] = filter_var($input['comments'] ?? false, FILTER_VALIDATE_BOOLEAN);
break;
case Slide::TYPE_QUIZ:
$limit = (int)($input['time_limit'] ?? $settings['time_limit']);
+63 -1
View File
@@ -19,7 +19,10 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
* private (anonymous feedback): 'answers' is always empty, texts only via answers()
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
* 'min', 'max', 'minLabel', 'maxLabel'
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool);
* 'comments' => [['id', 'text', 'value']] oldest first (only with the comment field, else []);
* private (internal feedback): 'buckets' and 'comments' are always empty and 'average' null,
* ratings and comments only via scaleResults() / comments()
* - quiz: 'phase' (ready|running|finished), 'timeLimit' (s, 0 = manual), 'remaining' (s|null),
* 'revealed' (bool), 'options' => [['id', 'label']] while not finished;
* once finished additionally per option 'count', 'percent', 'correct' (bool)
@@ -307,6 +310,65 @@ class ResultsService
* @return array<string, mixed>
*/
protected function scale(Slide $slide): array
{
if (!$slide->isPrivate()) {
return $this->scaleResults($slide) + [
'private' => false,
'comments' => $slide->hasComments() ? $this->comments($slide, self::MAX_ANSWERS) : [],
];
}
return [
'buckets' => [],
'average' => null,
'min' => (int)$slide->setting('scale_min'),
'max' => (int)$slide->setting('scale_max'),
'minLabel' => (string)$slide->setting('min_label'),
'maxLabel' => (string)$slide->setting('max_label'),
'private' => true,
'comments' => [],
];
}
/**
* Comments of a scale with their rating, oldest first – also of private slides,
* so the unfiltered call is only for the admin area.
*
* @param \App\Model\Entity\Slide $slide Scale slide
* @param int|null $limit Max. comments (the newest ones), null = all
* @return list<array{id: int, text: string, value: int, created: string}>
*/
public function comments(Slide $slide, ?int $limit = null): array
{
$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])
->orderBy(['id' => 'DESC']);
if ($limit !== null) {
$query->limit($limit);
}
$comments = [];
foreach ($query->all() as $row) {
$comments[] = [
'id' => (int)$row->id,
'text' => (string)$row->text_value,
'value' => (int)$row->numeric_value,
'created' => $row->created->toIso8601String(),
];
}
return array_reverse($comments);
}
/**
* Distribution and average of a scale – also of private slides,
* so only for the admin area (never for the presenter screen or participants).
*
* @param \App\Model\Entity\Slide $slide Scale slide
* @return array{buckets: list<array{value: int, count: int, percent: float|int}>, average: float|null, min: int, max: int, minLabel: string, maxLabel: string}
*/
public function scaleResults(Slide $slide): array
{
$min = (int)$slide->setting('scale_min');
$max = (int)$slide->setting('scale_max');
+6 -1
View File
@@ -422,7 +422,12 @@ class VoteService
if ($value === false || $value < $min || $value > $max) {
throw new VoteException(__('Bitte wähle einen Wert zwischen {0} und {1}.', $min, $max));
}
// The optional comment is stored in the same row; ignored if the slide has no comment field.
$comment = $slide->hasComments() ? trim((string)($data['comment'] ?? '')) : '';
if (mb_strlen($comment) > self::MAX_TEXT_LENGTH) {
throw new VoteException(__('Der Kommentar darf maximal {0} Zeichen lang sein.', self::MAX_TEXT_LENGTH));
}
return [['numeric_value' => $value]];
return [['numeric_value' => $value, 'text_value' => $comment === '' ? null : $comment]];
}
}