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
@@ -171,10 +171,12 @@ $bar = function (float $percent, bool $ok = false): string {
|
||||
<p>
|
||||
<?= __('Durchschnitt') ?>:
|
||||
<span class="stat"><?= $r['average'] === null ? '–' : $number((float)$r['average'], 1) ?></span>
|
||||
<span class="muted"><?= __('auf einer Skala von {0} bis {1}', (int)$r['min'], (int)$r['max']) ?></span>
|
||||
<span class="muted"><?= !empty($r['stars'])
|
||||
? __('von {0} Sternen', (int)$r['max'])
|
||||
: __('auf einer Skala von {0} bis {1}', (int)$r['min'], (int)$r['max']) ?></span>
|
||||
</p>
|
||||
<table>
|
||||
<thead><tr><th><?= __('Wert') ?></th><th class="num"><?= __('Anzahl') ?></th><th class="num"><?= __('Anteil') ?></th><th></th></tr></thead>
|
||||
<thead><tr><th><?= !empty($r['stars']) ? __('Sterne') : __('Wert') ?></th><th class="num"><?= __('Anzahl') ?></th><th class="num"><?= __('Anteil') ?></th><th></th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($r['buckets'] as $i => $bucket) :
|
||||
$label = match (true) {
|
||||
@@ -183,7 +185,7 @@ $bar = function (float $percent, bool $ok = false): string {
|
||||
default => '',
|
||||
}; ?>
|
||||
<tr>
|
||||
<td><?= (int)$bucket['value'] ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></td>
|
||||
<td<?= !empty($r['stars']) ? ' class="stars"' : '' ?>><?= h($slide->ratingText((int)$bucket['value'])) ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></td>
|
||||
<td class="num"><?= (int)$bucket['count'] ?></td>
|
||||
<td class="num"><?= $number((float)$bucket['percent']) ?> %</td>
|
||||
<td class="bar"><?= $bar((float)$bucket['percent']) ?></td>
|
||||
@@ -200,7 +202,7 @@ $bar = function (float $percent, bool $ok = false): string {
|
||||
<?php foreach ($r['comments'] as $comment) : ?>
|
||||
<li>
|
||||
<?= nl2br(h($comment['text'])) ?>
|
||||
<?php if ($comment['value'] !== null) : ?><span class="muted">(<?= __('Bewertung {0}', (int)$comment['value']) ?>)</span><?php endif; ?>
|
||||
<?php if ($comment['value'] !== null) : ?><span class="muted">(<?= __('Bewertung {0}', h($slide->ratingText((int)$comment['value']))) ?>)</span><?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
|
||||
@@ -280,15 +280,28 @@ $countdown = function (?int $remaining): string {
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php elseif ($slide->type === 'scale') : ?>
|
||||
<div class="scale"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
||||
<?php for ($v = (int)$slide->setting('scale_min'); $v <= (int)$slide->setting('scale_max'); $v++) : ?>
|
||||
<label class="scale__step">
|
||||
<input type="radio" name="value" value="<?= $v ?>" required>
|
||||
<span><?= $v ?></span>
|
||||
</label>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<?php elseif ($slide->type === 'scale') :
|
||||
$maxValue = (int)$slide->setting('scale_max'); ?>
|
||||
<?php if ($slide->isStarRating()) : ?>
|
||||
<div class="stars<?= $maxValue > 6 ? ' stars--many' : '' ?>" role="radiogroup" aria-label="<?= __('Bewertung in Sternen') ?>"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
||||
<?php for ($v = 1; $v <= $maxValue; $v++) : ?>
|
||||
<label class="stars__star">
|
||||
<input type="radio" name="value" value="<?= $v ?>" required>
|
||||
<span class="stars__icon" aria-hidden="true">★</span>
|
||||
<span class="sr-only"><?= __('{0} von {1} Sternen', $v, $maxValue) ?></span>
|
||||
</label>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="scale"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
||||
<?php for ($v = (int)$slide->setting('scale_min'); $v <= $maxValue; $v++) : ?>
|
||||
<label class="scale__step">
|
||||
<input type="radio" name="value" value="<?= $v ?>" required>
|
||||
<span><?= $v ?></span>
|
||||
</label>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="scale__labels">
|
||||
<span><?= h((string)$slide->setting('min_label')) ?></span>
|
||||
<span><?= h((string)$slide->setting('max_label')) ?></span>
|
||||
|
||||
@@ -43,12 +43,12 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
||||
<p class="scale-average">
|
||||
<?= __('Durchschnitt') ?>:
|
||||
<strong><?= h($this->Number->format((float)$scale['average'], ['places' => 1, 'precision' => 1, 'locale' => 'de_DE'])) ?></strong>
|
||||
<span class="muted">/ <?= (int)$scale['max'] ?></span>
|
||||
<span class="muted"><?= $slide->isStarRating() ? __('von {0} Sternen', (int)$scale['max']) : '/ ' . (int)$scale['max'] ?></span>
|
||||
</p>
|
||||
<table class="scale-table">
|
||||
<caption class="sr-only"><?= __('Verteilung der Bewertungen') ?></caption>
|
||||
<thead>
|
||||
<tr><th scope="col"><?= __('Wert') ?></th><th scope="col"><?= __('Anzahl') ?></th><th scope="col"><?= __('Anteil') ?></th></tr>
|
||||
<tr><th scope="col"><?= $slide->isStarRating() ? __('Sterne') : __('Wert') ?></th><th scope="col"><?= __('Anzahl') ?></th><th scope="col"><?= __('Anteil') ?></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($scale['buckets'] as $i => $bucket) :
|
||||
@@ -58,7 +58,7 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
||||
default => '',
|
||||
}; ?>
|
||||
<tr>
|
||||
<th scope="row"><?= (int)$bucket['value'] ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></th>
|
||||
<th scope="row"><?= $this->element('rating', ['slide' => $slide, 'value' => (int)$bucket['value']]) ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></th>
|
||||
<td><?= (int)$bucket['count'] ?></td>
|
||||
<td>
|
||||
<span class="scale-table__bar" style="width: <?= (float)$bucket['percent'] ?>%" aria-hidden="true"></span>
|
||||
@@ -79,7 +79,7 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
||||
$created = new DateTime($comment['created']); ?>
|
||||
<li>
|
||||
<?= h($comment['text']) ?>
|
||||
<time datetime="<?= h($comment['created']) ?>"><?= __('Bewertung {0}', $comment['value']) ?> · <?= h($created->i18nFormat('dd.MM.yyyy, HH:mm')) ?></time>
|
||||
<time datetime="<?= h($comment['created']) ?>"><?= __('Bewertung') ?> <?= $this->element('rating', ['slide' => $slide, 'value' => (int)$comment['value']]) ?> · <?= h($created->i18nFormat('dd.MM.yyyy, HH:mm')) ?></time>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
|
||||
@@ -148,14 +148,25 @@ $optionsError = $slide->getError('options_text');
|
||||
'checked' => (bool)$settings['allow_downvotes'],
|
||||
]) ?>
|
||||
<?php elseif ($slide->type === 'scale') : ?>
|
||||
<?php $stars = $settings['style'] === \App\Model\Entity\Slide::SCALE_STARS; ?>
|
||||
<fieldset class="scale-style" data-scale-style>
|
||||
<legend><?= __('Darstellung') ?></legend>
|
||||
<?= $this->Form->radio('settings.style', [
|
||||
['value' => \App\Model\Entity\Slide::SCALE_NUMBERS, 'text' => __('Zahlen (z. B. 1 bis 10)')],
|
||||
['value' => \App\Model\Entity\Slide::SCALE_STARS, 'text' => __('Sterne (wie bei einer Produktbewertung)')],
|
||||
], ['value' => $settings['style']]) ?>
|
||||
</fieldset>
|
||||
<div class="grid grid--2 grid--tight">
|
||||
<?= $this->Form->control('settings.scale_min', [
|
||||
'type' => 'select', 'options' => [0 => '0', 1 => '1'],
|
||||
'label' => __('Von'), 'value' => $settings['scale_min'],
|
||||
'templateVars' => ['attrs' => $stars ? ' hidden' : ''],
|
||||
'templates' => ['inputContainer' => '<div class="input {{type}}{{required}}" data-scale-min{{attrs}}>{{content}}</div>'],
|
||||
]) ?>
|
||||
<?= $this->Form->control('settings.scale_max', [
|
||||
'type' => 'select', 'options' => array_combine(range(2, 10), range(2, 10)),
|
||||
'label' => __('Bis'), 'value' => $settings['scale_max'],
|
||||
'label' => $stars ? __('Anzahl Sterne') : __('Bis'), 'value' => $settings['scale_max'],
|
||||
'data-label-numbers' => __('Bis'), 'data-label-stars' => __('Anzahl Sterne'),
|
||||
]) ?>
|
||||
<?= $this->Form->control('settings.min_label', [
|
||||
'label' => __('Beschriftung links (optional)'), 'maxlength' => 60,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* A scale rating: the number, or stars with a text alternative for screen readers.
|
||||
*
|
||||
* @var \App\View\AppView $this
|
||||
* @var \App\Model\Entity\Slide $slide Scale slide
|
||||
* @var int $value Rating
|
||||
*/
|
||||
if (!$slide->isStarRating()) {
|
||||
echo (int)$value;
|
||||
|
||||
return;
|
||||
}
|
||||
?><span class="rating-stars" aria-hidden="true"><?= h($slide->ratingText((int)$value)) ?></span><span class="sr-only"><?= __('{0} von {1} Sternen', (int)$value, (int)$slide->setting('scale_max')) ?></span>
|
||||
@@ -46,6 +46,7 @@
|
||||
ol.list, ul.list { margin: 1mm 0 0; padding-left: 6mm; }
|
||||
ol.list li, ul.list li { margin-bottom: 1.2mm; }
|
||||
.stat { font-size: 12pt; font-weight: bold; }
|
||||
td.stars { color: #c27c00; letter-spacing: 1pt; }
|
||||
.empty { color: #5d6280; font-style: italic; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
Reference in new issue
Block a user