From: thepurpleblob Date: Fri, 18 Jun 2004 08:41:16 +0000 (+0000) Subject: changed define to string assignment to prevent multiple defines notification X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c2df1c2ec25ac44e9451caf7f8830a169b5c1359;p=moodle.git changed define to string assignment to prevent multiple defines notification in true false questions added initialisation of both true and false feedback to kill notification in lib.php when question is stored --- diff --git a/mod/quiz/format/gift/format.php b/mod/quiz/format/gift/format.php index 118c05f562..cd39a62e97 100755 --- a/mod/quiz/format/gift/format.php +++ b/mod/quiz/format/gift/format.php @@ -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; +} } ?>