From 13c303d4f3431ee7e429d6eea47b2619d347a603 Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <fuhse@data-quest.de> Date: Tue, 26 Nov 2024 11:21:05 +0000 Subject: [PATCH] Resolve "Probleme mit Nicht-Pflicht-Fragen bei Likert- und Polskalen" Closes #4908 Merge request studip/studip!3683 --- .../question_types/likert/likert_evaluation.php | 12 +++++++++--- .../rangescale/rangescale_evaluation.php | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/views/questionnaire/question_types/likert/likert_evaluation.php b/app/views/questionnaire/question_types/likert/likert_evaluation.php index 873f058538c..f92adf99a81 100644 --- a/app/views/questionnaire/question_types/likert/likert_evaluation.php +++ b/app/views/questionnaire/question_types/likert/likert_evaluation.php @@ -43,10 +43,16 @@ $options = $vote->questiondata['options']; <? $average = 0; if (count($answers) > 0) { + $countableAnswers = 0; foreach ($answers as $answer) { $average += $answer['answerdata']['answers'][$key]; + if ($answer['answerdata']['answers'][$key] !== null) { + $countableAnswers++; + } + } + if ($countableAnswers > 0) { + $average /= $countableAnswers; } - $average /= count($answers); } ?> @@ -55,7 +61,7 @@ $options = $vote->questiondata['options']; $hits = 0; $names = []; foreach ($answers as $answer) { - if ($answer['answerdata']['answers'][$key] == $option_index) { + if ($answer['answerdata']['answers'][$key] === $option_index) { $hits++; if ($answer['user_id'] && $answer['user_id'][0] !== 'q' && $answer['user_id'][0] !== 'n') { $names[] = $answer->user->getFullName('full'); @@ -64,7 +70,7 @@ $options = $vote->questiondata['options']; } ?> <td <?= count($names) > 0 ? 'title="'.htmlReady(implode(', ', $names)).'"' : ''?>> - <? if ($option_index === 0 && count($answers)) : ?> + <? if ($option_index === 0 && count($answers) && $average > 0) : ?> <div class="average" style="margin-left: <?= 80 * $average + 34 ?>px;"> Ø<?= htmlReady(str_replace('.', ',', (string) round($average, 2) + 1)) ?> </div> diff --git a/app/views/questionnaire/question_types/rangescale/rangescale_evaluation.php b/app/views/questionnaire/question_types/rangescale/rangescale_evaluation.php index ddf0bd0e4fc..7f090ddbcca 100644 --- a/app/views/questionnaire/question_types/rangescale/rangescale_evaluation.php +++ b/app/views/questionnaire/question_types/rangescale/rangescale_evaluation.php @@ -42,10 +42,16 @@ $options = range($vote->questiondata['minimum'], $vote->questiondata['maximum']) <? $average = 0; if (count($answers) > 0) { + $countableAnswers = 0; foreach ($answers as $answer) { $average += $answer['answerdata']['answers'][$key]; + if ($answer['answerdata']['answers'][$key] !== null) { + $countableAnswers++; + } + } + if ($countableAnswers > 0) { + $average /= $countableAnswers; } - $average /= count($answers); $average = round($average, 2); } ?> @@ -64,7 +70,7 @@ $options = range($vote->questiondata['minimum'], $vote->questiondata['maximum']) } ?> <td style="white-space: nowrap;"<?= count($names) > 0 ? 'title="'.htmlReady(implode(', ', $names)).'"' : ''?>> - <? if ($option_index === 0 && count($answers) > 0) : ?> + <? if ($option_index === 0 && count($answers) > 0 && $average > 0) : ?> <div class="average" style="margin-left: <?= (count($options) * 80) * $average / $vote->questiondata['maximum'] - $vote->questiondata['minimum'] * 80 + 34 ?>px;"> Ø<?= htmlReady(str_replace('.', ',', (string) round($average, 2))) ?> </div> -- GitLab