From e00e36fa4f4e5616e6565c51fa9232bee27aef77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 23 Nov 2017 00:06:33 +0100 Subject: [PATCH] MDL-31521 questions: Allow more than one unit with multiplier equal to 1 --- question/type/calculated/questiontype.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 22f56e86337..5d61c5bd657 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -1054,11 +1054,15 @@ class qtype_calculated extends question_type { $comment->outsidelimit = false; $comment->answers = array(); // Find a default unit. - if (!empty($questionid) && $unit = $DB->get_record('question_numerical_units', - array('question' => $questionid, 'multiplier' => 1.0))) { - $unit = $unit->unit; - } else { - $unit = ''; + $unit = ''; + if (!empty($questionid)) { + $units = $DB->get_records('question_numerical_units', + array('question' => $questionid, 'multiplier' => 1.0), + 'id ASC', '*', 0, 1); + if ($units) { + $unit = reset($units); + $unit = $unit->unit; + } } $answers = fullclone($answers);