Permalink
Browse files

changed define to string assignment to prevent multiple defines notif…

…ication

in true false questions added initialisation of both true and false feedback
  to kill notification in lib.php when question is stored
  • Loading branch information...
1 parent 1be0eb6 commit c2df1c2ec25ac44e9451caf7f8830a169b5c1359 thepurpleblob committed Jun 18, 2004
Showing with 57 additions and 2 deletions.
  1. +57 −2 mod/quiz/format/gift/format.php
@@ -83,7 +83,8 @@ function readquestion($lines) {
$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 @@ function readquestion($lines) {
$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 @@ function readquestion($lines) {
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 @@ function readquestion($lines) {
} // 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;
+}
}
?>

0 comments on commit c2df1c2

Please sign in to comment.