From 7f8d6575318b2f46e2e80d0c815497e19ff7488d Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 21 Aug 2012 14:11:13 +0100 Subject: [PATCH] MDL-34993 questions: convert numeric fields to float on load. NUMBER(X,Y) typically come back from the DB as strings. If you don't convert them to float, then when you display them, it appears as 1.0000000, which is not normally what you want. Also, increase the size of the field on the edit form, so if you question does have default mark 0.1234567, you can see that! --- lib/questionlib.php | 8 ++++++++ question/type/edit_question_form.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index db7be64e8b8..b99edf708c6 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -780,14 +780,22 @@ function question_load_questions($questionids, $extrafields = '', $join = '') { */ function _tidy_question($question, $loadtags = false) { global $CFG; + + // Load question-type specific fields. if (!question_bank::is_qtype_installed($question->qtype)) { $question->questiontext = html_writer::tag('p', get_string('warningmissingtype', 'qtype_missingtype')) . $question->questiontext; } question_bank::get_qtype($question->qtype)->get_question_options($question); + + // Convert numeric fields to float. (Prevents these being displayed as 1.0000000.) + $question->defaultmark += 0; + $question->penalty += 0; + if (isset($question->_partiallyloaded)) { unset($question->_partiallyloaded); } + if ($loadtags && !empty($CFG->usetags)) { require_once($CFG->dirroot . '/tag/lib.php'); $question->tags = tag_get_tags_array('question', $question->id); diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php index 7428254ebe8..714d6a87009 100644 --- a/question/type/edit_question_form.php +++ b/question/type/edit_question_form.php @@ -190,7 +190,7 @@ abstract class question_edit_form extends question_wizard_form { $mform->setType('questiontext', PARAM_RAW); $mform->addElement('text', 'defaultmark', get_string('defaultmark', 'question'), - array('size' => 3)); + array('size' => 7)); $mform->setType('defaultmark', PARAM_FLOAT); $mform->setDefault('defaultmark', 1); $mform->addRule('defaultmark', null, 'required', null, 'client');