From: tjhunt Date: Fri, 15 Dec 2006 18:30:39 +0000 (+0000) Subject: MDL-7928 - Numerical question type should use * for the match anything answer. Merged... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=55894a4205c73d10a3a3df69140833c7cee01d65;p=moodle.git MDL-7928 - Numerical question type should use * for the match anything answer. Merged from MOODLE_17_STABLE. --- diff --git a/lang/en_utf8/help/quiz/numerical.html b/lang/en_utf8/help/quiz/numerical.html index 81636c3207..18e90b8b8e 100644 --- a/lang/en_utf8/help/quiz/numerical.html +++ b/lang/en_utf8/help/quiz/numerical.html @@ -10,4 +10,7 @@ then any number between 25 and 35 will be accepted as correct.

Like with short answer questions, different answers, or the same answer with different precisions can be given. In this case, the first -matching answer is used to determine the score and the feedback.

\ No newline at end of file +matching answer is used to determine the score and the feedback.

+ +

To provide feedback for responses that do not match any of the answers +you entered, provide some feedback with a '*' in the answer box.

\ No newline at end of file diff --git a/question/format/xml/format.php b/question/format/xml/format.php index f7c6425f0e..e3ec77e680 100755 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -326,7 +326,12 @@ class qformat_xml extends qformat_default { $qo->fraction = array(); $qo->tolerance = array(); foreach ($answers as $answer) { - $qo->answer[] = $answer['#'][0]; + $answertext = trim($answer['#'][0]); + if ($answertext == '') { + $qo->answer[] = '*'; + } else { + $qo->answer[] = $answertext; + } $qo->feedback[] = $this->import_text( $answer['#']['feedback'][0]['#']['text'] ); $qo->fraction[] = $answer['#']['fraction'][0]['#']; $qo->tolerance[] = $answer['#']['tolerance'][0]['#']; diff --git a/question/type/numerical/db/upgrade.php b/question/type/numerical/db/upgrade.php index 6102a8fccf..05dab091e1 100644 --- a/question/type/numerical/db/upgrade.php +++ b/question/type/numerical/db/upgrade.php @@ -23,14 +23,12 @@ function xmldb_qtype_numerical_upgrade($oldversion=0) { $result = true; -/// And upgrade begins here. For each one, you'll need one -/// block of code similar to the next one. Please, delete -/// this comment lines once this file start handling proper -/// upgrade code. - -/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php -/// $result = result of "/lib/ddllib.php" function calls -/// } + // In numerical questions, we are changing the 'match anything' answer + // from the empty string to *, to be like short answer questions. + if ($result && $oldversion < 2006121500) { + $result = set_field_select('question_answers', 'answer', '*', + "answer = '' AND question IN (SELECT id FROM {$CFG->prefix}question WHERE qtype = '" . NUMERICAL . "')"); + } return $result; } diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php index 5f33688bcc..476ab9631b 100644 --- a/question/type/numerical/questiontype.php +++ b/question/type/numerical/questiontype.php @@ -117,8 +117,8 @@ class question_numerical_qtype extends question_shortanswer_qtype { if ($dataanswer != '' || trim($question->feedback[$key])) { $answer = new stdClass; $answer->question = $question->id; - if (trim($dataanswer) == '') { - $answer->answer = ''; + if (trim($dataanswer) == '*') { + $answer->answer = '*'; } else { $answer->answer = $this->apply_unit($dataanswer, $units); if ($answer->answer === false) { @@ -269,8 +269,9 @@ class question_numerical_qtype extends question_shortanswer_qtype { * answer, false if it doesn't. */ function test_response(&$question, &$state, $answer) { - if ($answer->answer == '') { - return true; // Blank answer matches anything. + // Deal with the match anything answer. + if ($answer->answer == '*') { + return true; } $response = $this->apply_unit(stripslashes($state->responses['']), $question->options->units); @@ -297,7 +298,7 @@ class question_numerical_qtype extends question_shortanswer_qtype { function get_correct_responses(&$question, &$state) { $correct = parent::get_correct_responses($question, $state); - if ($unit = $this->get_default_numerical_unit($question)) { + if ($correct[''] != '*' && $unit = $this->get_default_numerical_unit($question)) { $correct[''] .= ' '.$unit->unit; } return $correct; @@ -314,8 +315,8 @@ class question_numerical_qtype extends question_shortanswer_qtype { $r->answer = $answer->answer; $r->credit = $answer->fraction; $this->get_tolerance_interval($answer); - if ($unit) { - $r->answer .= ' '.$unit->unit; + if ($r->answer != '*' && $unit) { + $r->answer .= ' ' . $unit->unit; } if ($answer->max != $answer->min) { $max = "$answer->max"; //format_float($answer->max, 2); @@ -465,9 +466,12 @@ class question_numerical_qtype extends question_shortanswer_qtype { $numerical = new stdClass; $numerical->question = $new_question_id; $numerical->answer = backup_todb($num_info['#']['ANSWER']['0']['#']); + if ($numerical->answer = '') { + $numerical->answer = '*'; + } $numerical->tolerance = backup_todb($num_info['#']['TOLERANCE']['0']['#']); - ////We have to recode the answer field + //We have to recode the answer field $answer = backup_getid($restore->backup_unique_code,"question_answers",$numerical->answer); if ($answer) { $numerical->answer = $answer->new_id; diff --git a/question/type/numerical/version.php b/question/type/numerical/version.php index 2d2a8d9fa7..e708d3dffc 100644 --- a/question/type/numerical/version.php +++ b/question/type/numerical/version.php @@ -1,6 +1,6 @@ version = 2006032200; +$plugin->version = 2006121500; $plugin->requires = 2006032200; ?>