MDL-7928 - Numerical question type should use * for the match anything answer. Merged from MOODLE_17_STABLE.

This commit is contained in:
tjhunt
2006-12-15 18:30:39 +00:00
parent 0dae5d33a7
commit 55894a4205
5 changed files with 29 additions and 19 deletions
+4 -1
View File
@@ -10,4 +10,7 @@ then any number between 25 and 35 will be accepted as correct.</p>
<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>
+6 -1
View File
@@ -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]['#'];
+6 -8
View File
@@ -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;
}
+12 -8
View File
@@ -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;
+1 -1
View File
@@ -1,6 +1,6 @@
<?PHP // $Id$
$plugin->version = 2006032200;
$plugin->version = 2006121500;
$plugin->requires = 2006032200;
?>