Skip to content
Browse files

MDL-7928 - Numerical question type should use * for the match anythin…

…g answer. Merged from MOODLE_17_STABLE.
  • Loading branch information...
1 parent 0dae5d3 commit 55894a4205c73d10a3a3df69140833c7cee01d65 tjhunt committed Dec 15, 2006
View
5 lang/en_utf8/help/quiz/numerical.html
@@ -10,4 +10,7 @@
<p>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.<p>
+matching answer is used to determine the score and the feedback.<p>
+
+<p>To provide feedback for responses that do not match any of the answers
+you entered, provide some feedback with a '*' in the answer box.</p>
View
7 question/format/xml/format.php
@@ -326,7 +326,12 @@ function import_numerical( $question ) {
$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]['#'];
View
14 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;
}
View
20 question/type/numerical/questiontype.php
@@ -117,8 +117,8 @@ function save_question_options($question) {
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 @@ function compare_responses(&$question, $state, $teststate) {
* 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 @@ function check_response(&$question, &$state){
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 @@ function get_all_responses(&$question, &$state) {
$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 @@ function restore($old_question_id,$new_question_id,$info,$restore) {
$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;
View
2 question/type/numerical/version.php
@@ -1,6 +1,6 @@
<?PHP // $Id$
-$plugin->version = 2006032200;
+$plugin->version = 2006121500;
$plugin->requires = 2006032200;
?>

0 comments on commit 55894a4

Please sign in to comment.
Something went wrong with that request. Please try again.