From 15f5c0a94cf6e836bddc58f2f8d035eaf80827b6 Mon Sep 17 00:00:00 2001 From: Anupama Sarjoshi Date: Tue, 17 Oct 2023 10:17:16 +0100 Subject: [PATCH] Revert changes in questiontype.php --- questiontype.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/questiontype.php b/questiontype.php index 04c7147..ff6f899 100644 --- a/questiontype.php +++ b/questiontype.php @@ -292,15 +292,19 @@ protected function initialise_question_rows(question_definition $question, $ques foreach ($questiondata->rows as $index => $row) { $newrow = $this->make_row($row); $correctanswers = []; - if($questiondata->options->inputtype == 'single') { - foreach ($questiondata->columns as $column) { - if (isset($newrow->correctanswers) && array_key_exists($column->id, $newrow->correctanswers)) { + $todecode = implode(",", $newrow->correctanswers); + $decodedanswers = json_decode($todecode, true); + foreach ($questiondata->columns as $key => $column) { + if ($decodedanswers != null && array_key_exists($column->id, $decodedanswers)) { + if ($questiondata->options->inputtype == 'single') { $anslabel = 'a' . ($column->number + 1); $correctanswers[$column->id] = $anslabel; + } else { + $correctanswers[$column->id] = $decodedanswers[$column->id]; } } - $newrow->correctanswers = $correctanswers; } + $newrow->correctanswers = $correctanswers; $question->rows[$index] = $newrow; } }