]> git.mjollnir.org Git - moodle.git/commitdiff
changed define to string assignment to prevent multiple defines notification
authorthepurpleblob <thepurpleblob>
Fri, 18 Jun 2004 08:41:16 +0000 (08:41 +0000)
committerthepurpleblob <thepurpleblob>
Fri, 18 Jun 2004 08:41:16 +0000 (08:41 +0000)
in true false questions added initialisation of both true and false feedback
  to kill notification in lib.php when question is stored

mod/quiz/format/gift/format.php

index 118c05f562dd4807b80e18ac8bcbc07b85fc2e9f..cd39a62e9709b20d875bc3fbd6f2cb56ef41e1b9 100755 (executable)
@@ -83,7 +83,8 @@ class quiz_file_format extends quiz_default_format {
 
         $question = NULL;
         $comment = NULL;
-        define("GIFT_ANSWERWEIGHT_REGEX", "^%\-*([0-9]{1,2})\.?([0-9]*)%");        
+        // define replaced by simple assignment, stop redefine notices
+        $gift_answerweight_regex = "^%\-*([0-9]{1,2})\.?([0-9]*)%";        
 
         // REMOVED COMMENTED LINES and IMPLODE
         foreach ($lines as $key => $line) {
@@ -233,7 +234,7 @@ class quiz_file_format extends quiz_default_format {
                         $answer_weight = 1;
                         $answer = substr($answer, 1);
     
-                    } elseif (ereg(GIFT_ANSWERWEIGHT_REGEX, $answer)) {    // check for properly formatted answer weight
+                    } elseif (ereg($gift_answerweight_regex, $answer)) {    // check for properly formatted answer weight
                         $answer_weight = $this->answerweightparser($answer);
                     
                     } else {     //default, i.e., wrong anwer
@@ -298,9 +299,11 @@ class quiz_file_format extends quiz_default_format {
                 if ($answer == "T" OR $answer == "TRUE") {
                     $question->answer = 1;
                     $question->feedbackfalse = $comment; //feedback if answer is wrong
+                    $question->feedbacktrue = ""; // make sure this exists to stop notifications
                 } else {
                     $question->answer = 0;
                     $question->feedbacktrue = $comment; //feedback if answer is wrong
+                    $question->feedbackfalse = ""; // make sure this exists to stop notifications
                 }
                 $question->defaultgrade = 1;
                 $question->image = "";   // No images with this format
@@ -428,6 +431,58 @@ class quiz_file_format extends quiz_default_format {
         } // end switch ($question->qtype)
 
     }    // end function readquestion($lines)
+
+function writequestion( $question ) {
+    // turns question into string
+    // question reflects database fields for general question and specific to type
+
+    // initial string;
+    $expout = "";
+
+    // add comment
+    $expout .= "// question: $question->id  name: $question->name \n";
+
+    // output depends on question type
+    switch($question->qtype) {
+    case TRUEFALSE:
+        if ($question->trueanswer->fraction==1) {
+            $answertext = 'TRUE';
+            $feedback = $question->falseanswer->feedback;
+        }
+        else {
+            $answertext = 'FALSE';
+            $feedback = $question->trueanswer->feedback;
+        }
+        $expout .= $question->questiontext."{".$answertext;
+        if ($feedback!="") {
+            $expout .= "#".$feedback;
+        }
+        $expout .= "}\n";
+        break;
+    case MULTICHOICE:
+        $expout .= $question->questiontext."{\n";
+        foreach($question->answers as $answer) {
+            if ($answer->fraction==1) {
+                $answertext = '=';
+            }
+            else {
+                $answertext = '~';
+            }
+            $expout .= "\t".$answertext.$answer->answer;
+            if ($answer->feedback!="") {
+                $expout .= "#".$answer->feedback;
+            }
+            $expout .= "\n";
+        }
+        $expout .= "}\n";
+        break;
+    default:
+        error( "No handler for qtype $question->qtype for GIFT export" );
+    }
+    // add empty line to delimit questions
+    $expout .= "\n";
+    return $expout;
+}
 }
 
 ?>