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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user