<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>
\ No newline at end of file
+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>
\ No newline at end of file
$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]['#'];
$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;
}
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) {
* 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);
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;
$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);
$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;