Skip to content

Commit

Permalink
fix duplicate method
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Aug 30, 2024
1 parent da511b6 commit d876556
Showing 1 changed file with 0 additions and 60 deletions.
60 changes: 0 additions & 60 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2169,66 +2169,6 @@ public function getSubmissionsLegacy(string $hash): DataResponse {
return new DataResponse($response);
}

/**
* Insert answers for a question
*
* @param Form $form
* @param int $submissionId
* @param array $question
* @param string[]|array<array{uploadedFileId: string, uploadedFileName: string}> $answerArray
*/
private function storeAnswersForQuestion(Form $form, $submissionId, array $question, array $answerArray) {
foreach ($answerArray as $answer) {
$answerEntity = new Answer();
$answerEntity->setSubmissionId($submissionId);
$answerEntity->setQuestionId($question['id']);

$answerText = '';
$uploadedFile = null;
// Are we using answer ids as values
if (in_array($question['type'], Constants::ANSWER_TYPES_PREDEFINED)) {
// Search corresponding option, skip processing if not found
$optionIndex = array_search($answer, array_column($question['options'], 'id'));
if ($optionIndex !== false) {
$answerText = $question['options'][$optionIndex]['text'];
} elseif (!empty($question['extraSettings']['allowOtherAnswer']) && strpos($answer, Constants::QUESTION_EXTRASETTINGS_OTHER_PREFIX) === 0) {
$answerText = str_replace(Constants::QUESTION_EXTRASETTINGS_OTHER_PREFIX, '', $answer);
}
} elseif ($question['type'] === Constants::ANSWER_TYPE_FILE) {
$uploadedFile = $this->uploadedFileMapper->getByUploadedFileId($answer['uploadedFileId']);
$answerEntity->setFileId($uploadedFile->getFileId());

$userFolder = $this->storage->getUserFolder($form->getOwnerId());
$path = $this->formsService->getUploadedFilePath($form, $submissionId, $question['id'], $question['name'], $question['text']);

if ($userFolder->nodeExists($path)) {
$folder = $userFolder->get($path);
} else {
$folder = $userFolder->newFolder($path);
}
/** @var \OCP\Files\Folder $folder */

$file = $userFolder->getById($uploadedFile->getFileId())[0];
$name = $folder->getNonExistingName($file->getName());
$file->move($folder->getPath() . '/' . $name);

$answerText = $name;
} else {
$answerText = $answer; // Not a multiple-question, answerText is given answer
}

if ($answerText === '') {
continue;
}

$answerEntity->setText($answerText);
$this->answerMapper->insert($answerEntity);
if ($uploadedFile) {
$this->uploadedFileMapper->delete($uploadedFile);
}
}
}

/**
* @CORS
* @NoAdminRequired
Expand Down

0 comments on commit d876556

Please sign in to comment.