Add mandatory-option on questions

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
Jonas Rittershofer 2020-04-04 00:00:04 +02:00 committed by John Molakvoæ (skjnldsv)
commit eb2d52d74b
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF
3 changed files with 45 additions and 9 deletions

View file

@ -277,20 +277,23 @@ class PageController extends Controller {
//Insert Answers
foreach($questions as $question) {
if($question['type'] === "checkbox"){
foreach(($answers[$question['text']]) as $ansText) {
// If question is answered, the questionText exists as key in $answers. Does not exist, when a (non-mandatory) question was not answered.
if (array_key_exists($question['text'], $answers)) {
if($question['type'] === "checkbox"){
foreach(($answers[$question['text']]) as $ansText) {
$answer = new Answer();
$answer->setSubmissionId($submissionId);
$answer->setQuestionId($question['id']);
$answer->setText($ansText);
$this->answerMapper->insert($answer);
}
} else {
$answer = new Answer();
$answer->setSubmissionId($submissionId);
$answer->setQuestionId($question['id']);
$answer->setText($ansText);
$answer->setText($answers[$question['text']]);
$this->answerMapper->insert($answer);
}
} else {
$answer = new Answer();
$answer->setSubmissionId($submissionId);
$answer->setQuestionId($question['id']);
$answer->setText($answers[$question['text']]);
$this->answerMapper->insert($answer);
}
}