diff options
| author | Rasmus Fuhse <fuhse@data-quest.de> | 2024-06-14 14:23:27 +0000 |
|---|---|---|
| committer | Rasmus Fuhse <fuhse@data-quest.de> | 2024-06-14 14:23:27 +0000 |
| commit | 2ab989c714d65a80a946939defce66d1b7c8f2cc (patch) | |
| tree | 4e7180a117f8b0afab117b3268b409355adc5b56 /lib/models/Vote.php | |
| parent | e0cea7c6578f479f777c2002753899ee759f99d4 (diff) | |
Resolve "Fragebogen: Single Choice CSV-Export unnötig kompliziert"
Closes #4308
Merge request studip/studip!3110
Diffstat (limited to 'lib/models/Vote.php')
| -rw-r--r-- | lib/models/Vote.php | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/lib/models/Vote.php b/lib/models/Vote.php index ede0cea..a434f7b 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; } |
