From b9fedd1b07993f1fd04c6279e44c434b4b48a6ac Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <fuhse@data-quest.de> Date: Fri, 14 Jun 2024 14:23:27 +0000 Subject: [PATCH] =?UTF-8?q?Resolve=20"Fragebogen:=20Single=20Choice=20CSV-?= =?UTF-8?q?Export=20unn=C3=B6tig=20kompliziert"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4308 Merge request studip/studip!3110 --- lib/models/Vote.php | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/models/Vote.php b/lib/models/Vote.php index 0520401296f..c992eda43ca 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; } -- GitLab