aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Vote.php
diff options
context:
space:
mode:
authorRasmus Fuhse <fuhse@data-quest.de>2024-06-14 14:23:27 +0000
committerRasmus Fuhse <fuhse@data-quest.de>2024-06-14 16:24:37 +0200
commitb9fedd1b07993f1fd04c6279e44c434b4b48a6ac (patch)
tree568e2168c860b0d894e06bf97a86ede7de3e1963 /lib/models/Vote.php
parent4d6df668f1b73d1e15ae4ced622cd5d63b37861c (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.php43
1 files changed, 32 insertions, 11 deletions
diff --git a/lib/models/Vote.php b/lib/models/Vote.php
index 0520401..c992eda 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;
}