From 4c1b378f12586aade5c77f063aecec03ce315b41 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Tue, 15 Nov 2022 18:47:16 +0100 Subject: [PATCH] fixed failing Lint checks --- lib/Service/SubmissionService.php | 59 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index 801733660..5a674316c 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -299,45 +299,44 @@ public function getQuestionCsv(int $formId, int $questionId): array { // Process each answers foreach ($submissionEntities as $submission) { $currentSubmissionAnswers = $this->answerMapper->findBySubmissionAndQuestionId($submission->getId(), $questionId); - $row = []; - - // User - $user = $this->userManager->get($submission->getUserId()); - if ($user === null) { - // Give empty userId - $row[] = ''; - // TRANSLATORS Shown on export if no Display-Name is available. - $row[] = $this->l10n->t('Anonymous user'); + $row = []; + + // User + $user = $this->userManager->get($submission->getUserId()); + if ($user === null) { + // Give empty userId + $row[] = ''; + // TRANSLATORS Shown on export if no Display-Name is available. + $row[] = $this->l10n->t('Anonymous user'); + } else { + $row[] = $user->getUID(); + $row[] = $user->getDisplayName(); + } + + // Date + $row[] = $this->dateTimeFormatter->formatDateTime($submission->getTimestamp(), 'full', 'full', new DateTimeZone($userTimezone), $this->l10n); + + // Answers, make sure we keep the question order + $answers = array_reduce($currentSubmissionAnswers, function (array $carry, Answer $answer) { + $questionId = $answer->getQuestionId(); + + // If key exists, insert separator + if (key_exists($questionId, $carry)) { + $carry[$questionId] .= '; ' . $answer->getText(); } else { - $row[] = $user->getUID(); - $row[] = $user->getDisplayName(); + $carry[$questionId] = $answer->getText(); } - - // Date - $row[] = $this->dateTimeFormatter->formatDateTime($submission->getTimestamp(), 'full', 'full', new DateTimeZone($userTimezone), $this->l10n); - - // Answers, make sure we keep the question order - $answers = array_reduce($currentSubmissionAnswers, function (array $carry, Answer $answer) { - $questionId = $answer->getQuestionId(); - - // If key exists, insert separator - if (key_exists($questionId, $carry)) { - $carry[$questionId] .= '; ' . $answer->getText(); - } else { - $carry[$questionId] = $answer->getText(); - } - return $carry; - }, []); + return $carry; + }, []); - $row[] = key_exists($question->getId(), $answers) + $row[] = key_exists($question->getId(), $answers) ? $answers[$question->getId()] : null; - $data[] = $row; - + $data[] = $row; } // TRANSLATORS Appendix for CSV-Export: 'Form Title (responses).csv'