Add a star rating style to scale slides
Scales can now be shown as stars (1 to n) instead of numbered steps: participants tap stars, the stage shows the average as partly filled stars and the distribution as bars from most to fewest stars, and the evaluation page and PDF export print ratings as stars. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1ee870d67c
commit
c1f9be2eef
14 files changed
+400
-31
No files matched your search
@@ -55,6 +55,12 @@ class Slide extends Entity
|
||||
*/
|
||||
public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300];
|
||||
|
||||
/**
|
||||
* Display styles of a scale: numbered steps or a star rating (always starts at 1 star).
|
||||
*/
|
||||
public const SCALE_NUMBERS = 'numbers';
|
||||
public const SCALE_STARS = 'stars';
|
||||
|
||||
/**
|
||||
* Q&A stages, see qaStage(): participants submit questions, then upvote
|
||||
* them, then the presenter discusses them one by one (most upvoted first).
|
||||
@@ -88,7 +94,9 @@ class Slide extends Entity
|
||||
// comments: optional comment field, comments rotate in the presentation (unless private)
|
||||
// comment_ratings: show the rating next to each comment in the presentation
|
||||
// (time per comment depends on its length, see Comments.delay() in plenario.js)
|
||||
// style: numbers or stars (SCALE_*), stars always start at scale_min = 1
|
||||
self::TYPE_SCALE => [
|
||||
'style' => self::SCALE_NUMBERS,
|
||||
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
|
||||
'comments' => false, 'comment_ratings' => false,
|
||||
],
|
||||
@@ -449,4 +457,31 @@ class Slide extends Entity
|
||||
{
|
||||
return $this->type === self::TYPE_SCALE && (bool)$this->setting('comments');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale shown as a star rating (1 to scale_max stars) instead of numbered steps.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStarRating(): bool
|
||||
{
|
||||
return $this->type === self::TYPE_SCALE && $this->setting('style') === self::SCALE_STARS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rating of a scale as plain text: the number, or filled and empty stars (e.g. ★★★★☆).
|
||||
*
|
||||
* @param int $value Rating
|
||||
* @return string
|
||||
*/
|
||||
public function ratingText(int $value): string
|
||||
{
|
||||
if (!$this->isStarRating()) {
|
||||
return (string)$value;
|
||||
}
|
||||
$max = (int)$this->setting('scale_max');
|
||||
$value = max(0, min($max, $value));
|
||||
|
||||
return str_repeat('★', $value) . str_repeat('☆', $max - $value);
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,10 @@ class SlidesTable extends Table
|
||||
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||
break;
|
||||
case Slide::TYPE_SCALE:
|
||||
$min = max(0, min(1, (int)($input['scale_min'] ?? 1)));
|
||||
$stars = ($input['style'] ?? null) === Slide::SCALE_STARS;
|
||||
$settings['style'] = $stars ? Slide::SCALE_STARS : Slide::SCALE_NUMBERS;
|
||||
// Stars always start at one star (zero stars is no rating).
|
||||
$min = $stars ? 1 : max(0, min(1, (int)($input['scale_min'] ?? 1)));
|
||||
$max = max(2, min(10, (int)($input['scale_max'] ?? 5)));
|
||||
$settings['scale_min'] = $min;
|
||||
$settings['scale_max'] = $max;
|
||||
|
||||
@@ -18,7 +18,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
* weight follows count)
|
||||
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
|
||||
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
|
||||
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool);
|
||||
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool), 'stars' (bool: star rating, min = 1);
|
||||
* 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else [];
|
||||
* 'value' is null unless the setting comment_ratings is on;
|
||||
* presentation only: participants never get results of scale slides, see PollStateService);
|
||||
@@ -394,7 +394,7 @@ class ResultsService
|
||||
* Distribution and average of a scale.
|
||||
*
|
||||
* @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}
|
||||
* @return array{buckets: list<array{value: int, count: int, percent: float|int}>, average: float|null, min: int, max: int, minLabel: string, maxLabel: string, stars: bool}
|
||||
*/
|
||||
public function scaleResults(Slide $slide): array
|
||||
{
|
||||
@@ -432,6 +432,7 @@ class ResultsService
|
||||
'max' => $max,
|
||||
'minLabel' => (string)$slide->setting('min_label'),
|
||||
'maxLabel' => (string)$slide->setting('max_label'),
|
||||
'stars' => $slide->isStarRating(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -665,7 +665,9 @@ class VoteService
|
||||
$min = (int)$slide->setting('scale_min');
|
||||
$max = (int)$slide->setting('scale_max');
|
||||
if ($value === false || $value < $min || $value > $max) {
|
||||
throw new VoteException(__('Bitte wähle einen Wert zwischen {0} und {1}.', $min, $max));
|
||||
throw new VoteException($slide->isStarRating()
|
||||
? __('Bitte vergib zwischen {0} und {1} Sternen.', $min, $max)
|
||||
: __('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.
|
||||
return [['numeric_value' => $value, 'text_value' => $slide->hasComments() ? self::comment($data) : null]];
|
||||
|
||||
Reference in new issue
Block a user