Skip to content

Commit

Permalink
MDL-64941 qtype_multianswer: keep order of existing wrapped questions
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGauk committed Mar 1, 2019
1 parent b38eb78 commit 5320dc6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions question/type/multianswer/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@ public function save_question_options($question) {
// will also create difficulties if questiontype specific tables reference the id.

// First we get all the existing wrapped questions.
if (!$oldwrappedids = $DB->get_field('question_multianswer', 'sequence',
$oldwrappedquestions = [];
if ($oldwrappedids = $DB->get_field('question_multianswer', 'sequence',
array('question' => $question->id))) {
$oldwrappedquestions = array();
} else {
$oldwrappedquestions = $DB->get_records_list('question', 'id',
explode(',', $oldwrappedids), 'id ASC');
$oldwrappedidsarray = explode(',', $oldwrappedids);
$unorderedquestions = $DB->get_records_list('question', 'id', $oldwrappedidsarray);

// Keep the order as given in the sequence field.
foreach ($oldwrappedidsarray as $questionid) {
if (isset($unorderedquestions[$questionid])) {
$oldwrappedquestions[] = $unorderedquestions[$questionid];
}
}
}

$sequence = array();
Expand Down

0 comments on commit 5320dc6

Please sign in to comment.