diff --git a/lib/models/Vote.php b/lib/models/Vote.php index 0520401296f3a24a850df3af10ab27ecc15cc01e..c992eda43cae145827135a7f9c503eb42a1af880 100644 --- a/lib/models/Vote.php +++ b/lib/models/Vote.php @@ -113,28 +113,49 @@ class Vote extends QuestionnaireQuestion implements QuestionType $output = []; $options = $this['questiondata']['options'] ? $this['questiondata']['options']->getArrayCopy() : []; + $multiplechoice = (bool) $this['questiondata']['multiplechoice']; + + if ($multiplechoice) { + foreach ($options as $key => $option) { + $answerOption = []; + $countNobodys = 0; + + foreach ($this->answers as $answer) { + $answerData = $answer['answerdata']->getArrayCopy(); + + if ($answer['user_id'] && $answer['user_id'] != 'nobody') { + $userId = $answer['user_id']; + } else { + $countNobodys++; + $userId = _('unbekannt') . ' ' . $countNobodys; + } + + if (in_array($key, (array) $answerData['answers'])) { + $answerOption[$userId] = 1; + } else { + $answerOption[$userId] = 0; + } + } + $output[$option] = $answerOption; + } + } else { - foreach ($options as $key => $option) { $answerOption = []; $countNobodys = 0; foreach ($this->answers as $answer) { $answerData = $answer['answerdata']->getArrayCopy(); - if ($answer['user_id'] && $answer['user_id'] != 'nobody') { + if ($answer['user_id'] && $answer['user_id'] !== 'nobody') { $userId = $answer['user_id']; } else { - $countNobodys++; - $userId = _('unbekannt').' '.$countNobodys; - } - - if (in_array($key, (array) $answerData['answers'])) { - $answerOption[$userId] = 1; - } else { - $answerOption[$userId] = 0; + $userId = _('unbekannt') . ' ' . ++$countNobodys; } + $answerOption[$userId] = $options[$answerData['answers']]; } - $output[$option] = $answerOption; + + $question = strip_tags($this['questiondata']['description']); + $output[$question] = $answerOption; } return $output; }