question export MDL-25088 this is the first part. I think question export is now working for all types.

Import to follow soon.
This commit is contained in:
Tim Hunt
2010-11-12 12:06:48 +00:00
parent e7ff48d284
commit 13bb604ed5
3 changed files with 358 additions and 292 deletions
+8 -12
View File
@@ -10,15 +10,11 @@ class qformat_xhtml extends qformat_default {
return true;
}
function repchar( $text ) {
// escapes 'reserved' characters # = ~ { ) and removes new lines
$reserved = array( '#','=','~','{','}',"\n","\r" );
$escaped = array( '\#','\=','\~','\{','\}',' ','' );
function repchar($text) {
return $text;
}
return str_replace( $reserved, $escaped, $text );
}
function writequestion( $question ) {
function writequestion($question) {
global $OUTPUT;
// turns question into string
// question reflects database fields for general question and specific to type
@@ -42,7 +38,7 @@ function writequestion( $question ) {
// format and add question text
$questiontext = $question->questiontext;
$format = $question->questiontextformat;
$formatted_text = format_text( $questiontext, $format );
$formatted_text = format_text($questiontext, $format);
$expout .= "<p class=\"questiontext\">$formatted_text</p>\n";
// selection depends on question type
@@ -60,10 +56,10 @@ function writequestion( $question ) {
foreach($question->options->answers as $answer) {
$ans_text = $this->repchar( $answer->answer );
if ($question->options->single) {
$expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$ans_text\" />$ans_text</li>\n";
$expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"" . s($ans_text) . "\" />$ans_text</li>\n";
}
else {
$expout .= " <li><input name=\"quest_$id\" type=\"checkbox\" value=\"$ans_text\" />$ans_text</li>\n";
$expout .= " <li><input name=\"quest_$id\" type=\"checkbox\" value=\"" . s($ans_text) . "\" />$ans_text</li>\n";
}
}
$expout .= "</ul>\n";
@@ -91,7 +87,7 @@ function writequestion( $question ) {
// build drop down for answers
$dropdown = "<select name=\"quest_$id\">\n";
foreach($ans_list as $ans) {
$dropdown .= "<option value=\"$ans\">$ans</option>\n";
$dropdown .= "<option value=\"" . s($ans) . "\">" . s($ans) . "</option>\n";
}
$dropdown .= "</select>\n";