diff --git a/app/views/questionnaire/question_types/likert/likert_evaluation.php b/app/views/questionnaire/question_types/likert/likert_evaluation.php index 873f058538c6a32eb1ee029535a7909a568161ef..f92adf99a81d643313864236f368a807653b63b6 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 ddf0bd0e4fc36d05c370630340d1c688f374ccb1..7f090ddbcca035be1c646874190e754a2880e9b6 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>