diff --git a/question/type/ordering/tests/fixtures/testexport.moodle.xml b/question/type/ordering/tests/fixtures/testexport.moodle.xml
index 8a35b313307..7e0fa9839c0 100644
--- a/question/type/ordering/tests/fixtures/testexport.moodle.xml
+++ b/question/type/ordering/tests/fixtures/testexport.moodle.xml
@@ -29,37 +29,37 @@
That is not right at all.
1
-
+
Modular
Modular is correct.
-
+
Object
Object is correct.
-
+
Oriented
Oriented is correct.
-
+
Dynamic
Dynamic is correct.
-
+
Learning
Learning is correct.
-
+
Environment
Environment is correct.
diff --git a/question/type/ordering/tests/output/feedback_test.php b/question/type/ordering/tests/output/feedback_test.php
index f59f7e025b1..62c2ec540e4 100644
--- a/question/type/ordering/tests/output/feedback_test.php
+++ b/question/type/ordering/tests/output/feedback_test.php
@@ -98,7 +98,8 @@ final class feedback_test extends qbehaviour_walkthrough_test_base {
$attempt = $qa;
} else {
$this->start_attempt_at_question($question, 'interactive');
- $this->process_submission(array_merge(['-submit' => 1], ['answers' => array_values($answeritems)]));
+ $response = qtype_ordering_test_helper::get_response($question, array_values($answeritems));
+ $this->process_submission(array_merge(['-submit' => 1], $response));
$attempt = $this->get_question_attempt();
// Omit the numparts as we are not testing it here, and it can be a bit flaky when manually processing an attempt.
$this->displayoptions->numpartscorrect = false;
diff --git a/question/type/ordering/tests/output/specific_grade_detail_feedback_test.php b/question/type/ordering/tests/output/specific_grade_detail_feedback_test.php
index dfb094e9233..4ae392e0038 100644
--- a/question/type/ordering/tests/output/specific_grade_detail_feedback_test.php
+++ b/question/type/ordering/tests/output/specific_grade_detail_feedback_test.php
@@ -197,7 +197,7 @@ final class specific_grade_detail_feedback_test extends advanced_testcase {
qtype_ordering_question::SELECT_ALL,
],
'Incorrect question attempt (SELECT_RANDOM). Grading type: GRADING_ABSOLUTE_POSITION' => [
- [14 => 'Object', 16 => 'Dynamic', 13 => 'Modular', 17 => 'Learning', 18 => 'Environment', 15 => 'Oriented'],
+ [16 => 'Dynamic', 14 => 'Object', 13 => 'Modular', 17 => 'Learning', 18 => 'Environment', 15 => 'Oriented'],
qtype_ordering_question::GRADING_ABSOLUTE_POSITION,
'vertical',
[
diff --git a/question/type/ordering/tests/questionhint_test.php b/question/type/ordering/tests/questionhint_test.php
index 46eaf40562d..ed75bbee411 100644
--- a/question/type/ordering/tests/questionhint_test.php
+++ b/question/type/ordering/tests/questionhint_test.php
@@ -24,6 +24,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/question/type/ordering/questiontype.php');
/**
* A test class used to test question_hint_ordering.
diff --git a/question/type/ordering/tests/questiontype_test.php b/question/type/ordering/tests/questiontype_test.php
index b574e732b25..e9b98b3795f 100644
--- a/question/type/ordering/tests/questiontype_test.php
+++ b/question/type/ordering/tests/questiontype_test.php
@@ -39,7 +39,7 @@ require_once($CFG->dirroot . '/question/type/ordering/edit_ordering_form.php');
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format.php');
require_once($CFG->dirroot . '/question/format/gift/format.php');
-require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/question/format/xml/format.php');
/**
* Unit tests for the ordering question type class.
diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php
index 3f9130fba43..78f585d7f4d 100644
--- a/question/type/questiontypebase.php
+++ b/question/type/questiontypebase.php
@@ -931,13 +931,13 @@ class question_type {
if (is_array($extraanswerfields)) {
$answerextensiontable = array_shift($extraanswerfields);
// Use LEFT JOIN in case not every answer has extra data.
- $question->options->answers = $DB->get_records_sql("
+ $answers = $DB->get_records_sql("
SELECT qa.*, qax." . implode(', qax.', $extraanswerfields) . '
FROM {question_answers} qa ' . "
LEFT JOIN {{$answerextensiontable}} qax ON qa.id = qax.answerid
WHERE qa.question = ?
ORDER BY qa.id", array($question->id));
- if (!$question->options->answers) {
+ if (!$answers) {
echo $OUTPUT->notification('Failed to load question answers from the table ' .
$answerextensiontable . 'for questionid ' . $question->id);
return false;
@@ -945,9 +945,15 @@ class question_type {
} else {
// Don't check for success or failure because some question types do
// not use the answers table.
- $question->options->answers = $DB->get_records('question_answers',
+ $answers = $DB->get_records('question_answers',
array('question' => $question->id), 'id ASC');
}
+ // Store the answers into the question object.
+ $question->options->answers = array_map(function($answer) {
+ // Some database engines return floats as strings like '1.0000000'. Cast to float for consistency.
+ $answer->fraction = (float) $answer->fraction;
+ return $answer;
+ }, $answers);
$question->hints = $DB->get_records('question_hints',
array('questionid' => $question->id), 'id ASC');