Add "Keine Angabe" to scales and an "Enthaltung" shortcut for choice slides
Scales and star ratings get an optional "Keine Angabe" answer (setting allow_skip). It counts as taking part but stays out of the average and the distribution; the number is shown separately on stage, in the evaluation and in the PDF. The choice form gets a button that appends an "Enthaltung" option. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1b48ce7852
commit
d6432911ed
14 files changed
+195
-11
No files matched your search
@@ -21,6 +21,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
|
||||
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
|
||||
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool), 'stars' (bool: star rating, min = 1);
|
||||
* 'skipped' (int: answers "Keine Angabe", setting allow_skip; not part of buckets/average);
|
||||
* 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else [];
|
||||
* 'value' is null unless the setting comment_ratings is on;
|
||||
* 'view' (both|average|chart): parts shown in the presentation (setting scale_view,
|
||||
@@ -486,6 +487,7 @@ class ResultsService
|
||||
if (isset($results['buckets'])) {
|
||||
$results['buckets'] = [];
|
||||
$results['average'] = null;
|
||||
$results['skipped'] = 0;
|
||||
$results['comments'] = [];
|
||||
}
|
||||
|
||||
@@ -530,7 +532,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, stars: bool}
|
||||
* @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, skipped: int}
|
||||
*/
|
||||
public function scaleResults(Slide $slide): array
|
||||
{
|
||||
@@ -545,6 +547,11 @@ class ResultsService
|
||||
->combine('numeric_value', 'n')
|
||||
->toArray();
|
||||
|
||||
// "Keine Angabe": taking part without a rating, never part of the average or the distribution
|
||||
$skipped = $slide->setting('allow_skip')
|
||||
? $this->Responses->find()->where(['slide_id' => $slide->id, 'numeric_value IS' => null])->count()
|
||||
: 0;
|
||||
|
||||
$total = 0;
|
||||
$sum = 0;
|
||||
foreach ($counts as $value => $count) {
|
||||
@@ -569,6 +576,7 @@ class ResultsService
|
||||
'minLabel' => (string)$slide->setting('min_label'),
|
||||
'maxLabel' => (string)$slide->setting('max_label'),
|
||||
'stars' => $slide->isStarRating(),
|
||||
'skipped' => $skipped,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -179,6 +179,9 @@ class VoteService
|
||||
default => __('Bitte gib zuerst deine Bewertung ab.'),
|
||||
});
|
||||
}
|
||||
if ($slide->type === Slide::TYPE_SCALE && $row->numeric_value === null) {
|
||||
throw new VoteException(__('Zu „Keine Angabe“ gibt es keinen Kommentar.'));
|
||||
}
|
||||
$row->text_value = $text;
|
||||
$this->Responses->saveOrFail($row);
|
||||
});
|
||||
@@ -203,6 +206,22 @@ class VoteService
|
||||
return $row['text_value'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the participant answered a scale with "Keine Angabe" (a row without rating).
|
||||
*
|
||||
* @param \App\Model\Entity\Slide $slide Slide
|
||||
* @param string $participantHash Participant hash
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSkipped(Slide $slide, string $participantHash): bool
|
||||
{
|
||||
return $slide->type === Slide::TYPE_SCALE && $this->Responses->exists([
|
||||
'slide_id' => $slide->id,
|
||||
'participant_hash' => $participantHash,
|
||||
'numeric_value IS' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll active, slide live and interactive, voting open.
|
||||
*
|
||||
@@ -682,6 +701,14 @@ class VoteService
|
||||
*/
|
||||
protected function scaleRows(Slide $slide, array $data): array
|
||||
{
|
||||
if (self::stringField($data, 'skip') === '1') {
|
||||
if (!$slide->setting('allow_skip')) {
|
||||
throw new VoteException(__('„Keine Angabe“ ist bei dieser Frage nicht möglich.'));
|
||||
}
|
||||
|
||||
// Counts as taking part, but has no rating and no comment.
|
||||
return [['numeric_value' => null, 'text_value' => null]];
|
||||
}
|
||||
$value = filter_var($data['value'] ?? null, FILTER_VALIDATE_INT);
|
||||
$min = (int)$slide->setting('scale_min');
|
||||
$max = (int)$slide->setting('scale_max');
|
||||
|
||||
Reference in new issue
Block a user