From: tjhunt For Multiple Choice questions, feedback is displayed only for the answer the student selected.
For short answer, feedback is shown only when students input the corresponding correct answer.
- For true-false questions, the imported feedback is saved so that it will display if the student chose the wrong answer.
- So, in the last example above, the student would see the feedback only if they selected TRUE as their answer.
Percentage Answer Weights:
Percentage answer weights are available for both Multiple Choice and Short Answer questions.
diff --git a/question/format/gift/format.php b/question/format/gift/format.php
index 6d23a28dd7..fc6e3fe266 100755
--- a/question/format/gift/format.php
+++ b/question/format/gift/format.php
@@ -35,11 +35,11 @@
class qformat_gift extends qformat_default {
function provide_import() {
- return true;
+ return true;
}
function provide_export() {
- return true;
+ return true;
}
function answerweightparser(&$answer) {
@@ -65,18 +65,16 @@ class qformat_gift extends qformat_default {
}
function split_truefalse_comment($comment){
- // splits up comment around # marks
- // returns an array of true/false feedback
- $feedback = explode('#',$comment);
- if (count($feedback)>=2) {
- $true_feedback = $feedback[0];
- $false_feedback = $feedback[1];
- }
- else {
- $true_feedback = $feedback[0];
- $false_feedback = '';
- }
- return array( 'true'=>$true_feedback, 'false'=>$false_feedback );
+ // splits up comment around # marks
+ // returns an array of true/false feedback
+ $bits = explode('#',$comment);
+ $feedback = array('wrong' => $bits[0]);
+ if (count($bits) >= 2) {
+ $feedback['right'] = $bits[1];
+ } else {
+ $feedback['right'] = '';
+ }
+ return $feedback;
}
function escapedchar_pre($string) {
@@ -100,17 +98,17 @@ class qformat_gift extends qformat_default {
}
function check_answer_count( $min, $answers, $text ) {
- $countanswers = count($answers);
- if ($countanswers < $min) {
- if ($this->displayerrors) {
- $errormessage = get_string( 'importminerror', 'quiz' );
- echo "
$text
\n"; - echo "$errormessage
\n"; - } - return false; - } - - return true; + $countanswers = count($answers); + if ($countanswers < $min) { + if ($this->displayerrors) { + $errormessage = get_string( 'importminerror', 'quiz' ); + echo "$text
\n"; + echo "$errormessage
\n"; + } + return false; + } + + return true; } @@ -125,11 +123,11 @@ class qformat_gift extends qformat_default { // REMOVED COMMENTED LINES and IMPLODE foreach ($lines as $key => $line) { - $line = trim($line); - if (substr($line, 0, 2) == "//") { + $line = trim($line); + if (substr($line, 0, 2) == "//") { // echo "Commented line removed.$text
$err
@@ -511,7 +508,7 @@ function repchar( $text, $format=0 ) { $newtext = str_replace( $reserved, $escaped, $text ); $format = 0; // turn this off for now if ($format) { - $newtext = format_text( $format ); + $newtext = format_text( $format ); } return $newtext; } @@ -530,46 +527,35 @@ function writequestion( $question ) { $textformat = $question->questiontextformat; $tfname = ""; if ($textformat!=FORMAT_MOODLE) { - $tfname = text_format_name( (int)$textformat ); - $tfname = "[$tfname]"; + $tfname = text_format_name( (int)$textformat ); + $tfname = "[$tfname]"; } // output depends on question type switch($question->qtype) { case TRUEFALSE: - $answers = $question->options->answers; - foreach ($answers as $answer) { - if (trim($answer->answer)=='True') { - if ($answer->fraction==1) { - $answertext = 'TRUE'; - $right_feedback = $answer->feedback; - } - else { - $answertext = 'FALSE'; - $wrong_feedback = $answer->feedback; - } - } - else { - if ($answer->fraction==1) { - $answertext = 'FALSE'; - $right_feedback = $answer->feedback; - } - else { - $answertext = 'TRUE'; - $wrong_feedback = $answer->feedback; - } - } + $trueanswer = $question->options->answers[$question->options->trueanswer]; + $falseanswer = $question->options->answers[$question->options->falseanswer]; + if ($trueanswer->fraction == 1) { + $answertext = 'TRUE'; + $right_feedback = $trueanswer->feedback; + $wrong_feedback = $falseanswer->feedback; + } else { + $answertext = 'FALSE'; + $right_feedback = $falseanswer->feedback; + $wrong_feedback = $trueanswer->feedback; } - $wrong_feedback = $this->repchar( $wrong_feedback ); - $right_feedback = $this->repchar( $right_feedback ); - $expout .= "::".$this->repchar($question->name)."::".$tfname.$this->repchar( $question->questiontext,$textformat ); - $expout .= "{".$this->repchar( $answertext ); - if ($wrong_feedback!="") { - $expout .= "#".$wrong_feedback; + $wrong_feedback = $this->repchar($wrong_feedback); + $right_feedback = $this->repchar($right_feedback); + $expout .= "::".$this->repchar($question->name)."::".$tfname.$this->repchar( $question->questiontext,$textformat )."{".$this->repchar( $answertext ); + if ($wrong_feedback) { + $expout .= "#" . $wrong_feedback; + } else if ($right_feedback) { + $expout .= "#"; } - if ($right_feedback!="") { - $expout .= "#".$right_feedback; + if ($right_feedback) { + $expout .= "#" . $right_feedback; } $expout .= "}\n"; break; @@ -583,8 +569,8 @@ function writequestion( $question ) { $answertext = '~'; } else { - $export_weight = $answer->fraction*100; - $answertext = "~%$export_weight%"; + $export_weight = $answer->fraction*100; + $answertext = "~%$export_weight%"; } $expout .= "\t".$answertext.$this->repchar( $answer->answer ); if ($answer->feedback!="") {