diff --git a/app/views/questionnaire/question_types/likert/likert_evaluation.php b/app/views/questionnaire/question_types/likert/likert_evaluation.php index 9ac7872bea0d921426568f512ed49f34b07bd025..ac0a671d04a12a35e9f5afc3a0dc9e56106795ef 100644 --- a/app/views/questionnaire/question_types/likert/likert_evaluation.php +++ b/app/views/questionnaire/question_types/likert/likert_evaluation.php @@ -27,44 +27,46 @@ $options = $vote->questiondata['options']; </thead> <tbody> <? $countAnswers = $vote->questionnaire->countAnswers() ?> - <? foreach ($vote->questiondata['statements'] as $key => $statement) : ?> - <tr> - <td> - <strong><?= htmlReady($statement) ?></strong> - </td> + <? if (!empty($vote->questiondata['statements'])) : ?> + <? foreach ($vote->questiondata['statements'] as $key => $statement) : ?> + <tr> + <td> + <strong><?= htmlReady($statement) ?></strong> + </td> - <? foreach($options as $option_index => $option) : ?> - <? - $hits = 0; - $names = []; - foreach ($answers as $answer) { - 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'); + <? foreach($options as $option_index => $option) : ?> + <? + $hits = 0; + $names = []; + foreach ($answers as $answer) { + 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'); + } } } - } - $color = 'hsl(0 0% '.round(70 + (30 * (1 - ($hits / $countAnswers ?? 1)) )).'%)'; - ?> - <td style="background-color: <?= $color ?>;" <?= count($names) > 0 ? 'title="'.htmlReady(implode(', ', $names)).'"' : ''?>> - <? if ($filtered !== null && $filtered == $key.'_'.$option_index) : ?> - <a href="" - onclick="STUDIP.Questionnaire.removeFilter('<?= htmlReady($vote['questionnaire_id']) ?>'); return false;" - title="<?= _('Zeige wieder alle Ergebnisse ohne Filterung an.') ?>"> - <?= Icon::create('filter2', Icon::ROLE_CLICKABLE)->asImg(16, ['class' => 'text-bottom']) ?> - <?= round(100 * $hits / $countAnswers) ?>% - </a> - <? else : ?> - <a href="" - onclick="STUDIP.Questionnaire.addFilter('<?= htmlReady($vote['questionnaire_id']) ?>', '<?= htmlReady($vote->getId()) ?>', '<?= $key.'_'.$option_index ?>'); return false;" - title="<?= _('Zeige nur Ergebnisse von Personen an, die diese Option gewählt haben.') ?>"> - <?= round(100 * $hits / $countAnswers) ?>% - </a> - <? endif ?> - </td> - <? endforeach ?> - </tr> - <? endforeach ?> + $color = 'hsl(0 0% '.round(70 + (30 * (1 - ($hits / $countAnswers ?? 1)) )).'%)'; + ?> + <td style="background-color: <?= $color ?>;" <?= count($names) > 0 ? 'title="'.htmlReady(implode(', ', $names)).'"' : ''?>> + <? if ($filtered !== null && $filtered == $key.'_'.$option_index) : ?> + <a href="" + onclick="STUDIP.Questionnaire.removeFilter('<?= htmlReady($vote['questionnaire_id']) ?>'); return false;" + title="<?= _('Zeige wieder alle Ergebnisse ohne Filterung an.') ?>"> + <?= Icon::create('filter2', Icon::ROLE_CLICKABLE)->asImg(16, ['class' => 'text-bottom']) ?> + <?= round(100 * $hits / $countAnswers) ?>% + </a> + <? else : ?> + <a href="" + onclick="STUDIP.Questionnaire.addFilter('<?= htmlReady($vote['questionnaire_id']) ?>', '<?= htmlReady($vote->getId()) ?>', '<?= $key.'_'.$option_index ?>'); return false;" + title="<?= _('Zeige nur Ergebnisse von Personen an, die diese Option gewählt haben.') ?>"> + <?= round(100 * $hits / $countAnswers) ?>% + </a> + <? endif ?> + </td> + <? endforeach ?> + </tr> + <? endforeach ?> + <? endif ?> </tbody> </table> diff --git a/lib/models/LikertScale.php b/lib/models/LikertScale.php index 5e55e3c294d80fb1062b72e9e29ad31120582dff..6659cb2d7134d780236afefc03c6ffaa85df9378 100644 --- a/lib/models/LikertScale.php +++ b/lib/models/LikertScale.php @@ -32,7 +32,7 @@ class LikertScale extends QuestionnaireQuestion implements QuestionType $questiondata['description'] = \Studip\Markup::markAsHtml( \Studip\Markup::purifyHtml($questiondata['description']) ); - $questiondata['statements'] = array_filter($questiondata['statements']); + $questiondata['statements'] = array_filter($questiondata['statements'] ?? []); return $questiondata; } diff --git a/lib/models/RangeScale.php b/lib/models/RangeScale.php index 3c89195704f006be6f2ca63b31260fd41945b62e..89feb02c86f44f2f7375f1e337031794e96a5e00 100644 --- a/lib/models/RangeScale.php +++ b/lib/models/RangeScale.php @@ -27,7 +27,7 @@ class RangeScale extends QuestionnaireQuestion implements QuestionType $questiondata['description'] = \Studip\Markup::markAsHtml( \Studip\Markup::purifyHtml($questiondata['description']) ); - $questiondata['statements'] = array_filter($questiondata['statements']); + $questiondata['statements'] = array_filter($questiondata['statements'] ?? []); return $questiondata; }