Skip to content

Commit

Permalink
Export now works with objects generated in questiontype classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
thepurpleblob committed May 9, 2005
1 parent 683f250 commit 2e21836
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions mod/quiz/format/gift/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,18 @@ function readquestion($lines) {

} // end function readquestion($lines)

function repchar( $text ) {
function repchar( $text, $format=0 ) {
// escapes 'reserved' characters # = ~ { ) and removes new lines
// also pushes text through format routine
$reserved = array( '#','=','~','{','}',"\n","\r" );
$escaped = array( '\#','\=','\~','\{','\}',' ','' );

return str_replace( $reserved, $escaped, $text );
$newtext = str_replace( $reserved, $escaped, $text );
$format = 0; // turn this off for now
if ($format) {
$newtext = format_text( $format );
}
return $newtext;
}

function writequestion( $question ) {
Expand All @@ -484,20 +490,24 @@ function writequestion( $question ) {
// add comment
$expout .= "// question: $question->id name: $question->name \n";

// get question text format
$textformat = $question->questiontextformat;

// output depends on question type
switch($question->qtype) {
case TRUEFALSE:
if ($question->trueanswer->fraction==1) {
$answers = $question->options->answers;
if ($answers['true']->fraction==1) {
$answertext = 'TRUE';
$wrong_feedback = $this->repchar( $question->falseanswer->feedback );
$right_feedback = $this->repchar( $question->trueanswer->feedback );
$wrong_feedback = $this->repchar( $answers['false']->feedback );
$right_feedback = $this->repchar( $answers['true']->feedback );
}
else {
$answertext = 'FALSE';
$wrong_feedback = $this->repchar( $question->trueanswer->feedback );
$right_feedback = $this->repchar( $question->falseanswer->feedback );
$wrong_feedback = $this->repchar( $answers['true']->feedback );
$right_feedback = $this->repchar( $answers['false']->feedback );
}
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext )."{".$this->repchar( $answertext );
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext,$textformat )."{".$this->repchar( $answertext );
if ($wrong_feedback!="") {
$expout .= "#".$wrong_feedback;
}
Expand All @@ -507,8 +517,8 @@ function writequestion( $question ) {
$expout .= "}\n";
break;
case MULTICHOICE:
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext )."{\n";
foreach($question->answers as $answer) {
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext, $textformat )."{\n";
foreach($question->options->answers as $answer) {
if ($answer->fraction==1) {
$answertext = '=';
}
Expand All @@ -528,21 +538,24 @@ function writequestion( $question ) {
$expout .= "}\n";
break;
case SHORTANSWER:
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext )."{\n";
foreach($question->answers as $answer) {
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext, $textformat )."{\n";
foreach($question->options->answers as $answer) {
$weight = 100 * $answer->fraction;
$expout .= "\t=%".$weight."%".$this->repchar( $answer->answer )."#".$this->repchar( $answer->feedback )."\n";
}
$expout .= "}\n";
break;
case NUMERICAL:
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext )."{\n";
$expout .= "\t#".$question->min."..".$question->max."#".$this->repchar( $question->answer->feedback )."\n";
$answer = array_pop( $question->options->answers );
$min = $answer->answer - $question->options->tolerance;
$max = $answer->answer + $question->options->tolerance;
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext, $textformat )."{\n";
$expout .= "\t#".$min."..".$max."#".$this->repchar( $answer->feedback )."\n";
$expout .= "}\n";
break;
case MATCH:
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext )."{\n";
foreach($question->subquestions as $subquestion) {
$expout .= "::".$question->name."::".$this->repchar( $question->questiontext, $textformat )."{\n";
foreach($question->options->subquestions as $subquestion) {
$expout .= "\t=".$this->repchar( $subquestion->questiontext )." -> ".$this->repchar( $subquestion->answertext )."\n";
}
$expout .= "}\n";
Expand Down

0 comments on commit 2e21836

Please sign in to comment.