$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) {
$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
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
} // 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;
+}
}
?>