Fix for exception when there are "null" replies

This commit is contained in:
Michael 2023-12-07 09:59:39 +00:00
parent 0d6974a6d2
commit a120debac6

View File

@ -3805,16 +3805,16 @@ class Item
foreach ($options as $key => $option) { foreach ($options as $key => $option) {
if ($question['voters'] > 0) { if ($question['voters'] > 0) {
$percent = $option['replies'] / $question['voters'] * 100; $percent = $option['replies'] / $question['voters'] * 100;
$options[$key]['vote'] = DI::l10n()->tt('%2$s (%3$d%%, %1$d vote)', '%2$s (%3$d%%, %1$d votes)', $option['replies'], $option['name'], round($percent, 1)); $options[$key]['vote'] = DI::l10n()->tt('%2$s (%3$d%%, %1$d vote)', '%2$s (%3$d%%, %1$d votes)', $option['replies'] ?? 0, $option['name'], round($percent, 1));
} else { } else {
$options[$key]['vote'] = DI::l10n()->tt('%2$s (%1$d vote)', '%2$s (%1$d votes)', $option['replies'], $option['name']); $options[$key]['vote'] = DI::l10n()->tt('%2$s (%1$d vote)', '%2$s (%1$d votes)', $option['replies'] ?? 0, $option['name']);
} }
} }
if (!empty($question['voters']) && !empty($question['endtime'])) { if (!empty($question['voters']) && !empty($question['endtime'])) {
$summary = DI::l10n()->tt('%d voter. Poll end: %s', '%d voters. Poll end: %s', $question['voters'], Temporal::getRelativeDate($question['endtime'])); $summary = DI::l10n()->tt('%d voter. Poll end: %s', '%d voters. Poll end: %s', $question['voters'] ?? 0, Temporal::getRelativeDate($question['endtime']));
} elseif (!empty($question['voters'])) { } elseif (!empty($question['voters'])) {
$summary = DI::l10n()->tt('%d voter.', '%d voters.', $question['voters']); $summary = DI::l10n()->tt('%d voter.', '%d voters.', $question['voters'] ?? 0);
} elseif (!empty($question['endtime'])) { } elseif (!empty($question['endtime'])) {
$summary = DI::l10n()->t('Poll end: %s', Temporal::getRelativeDate($question['endtime'])); $summary = DI::l10n()->t('Poll end: %s', Temporal::getRelativeDate($question['endtime']));
} else { } else {