|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00038 class qformat_xhtml extends qformat_default { 00039 00040 public function provide_export() { 00041 return true; 00042 } 00043 00044 protected function repchar($text) { 00045 return $text; 00046 } 00047 00048 protected function writequestion($question) { 00049 global $OUTPUT; 00050 // turns question into string 00051 // question reflects database fields for general question and specific to type 00052 00053 // if a category switch, just ignore 00054 if ($question->qtype=='category') { 00055 return ''; 00056 } 00057 00058 // initial string; 00059 $expout = ""; 00060 $id = $question->id; 00061 00062 // add comment and div tags 00063 $expout .= "<!-- question: $id name: $question->name -->\n"; 00064 $expout .= "<div class=\"question\">\n"; 00065 00066 // add header 00067 $expout .= "<h3>$question->name</h3>\n"; 00068 00069 // Format and add the question text 00070 $expout .= '<p class="questiontext">' . format_text($question->questiontext, 00071 $question->questiontextformat) . "</p>\n"; 00072 00073 // selection depends on question type 00074 switch($question->qtype) { 00075 case TRUEFALSE: 00076 $st_true = get_string('true', 'qtype_truefalse'); 00077 $st_false = get_string('false', 'qtype_truefalse'); 00078 $expout .= "<ul class=\"truefalse\">\n"; 00079 $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$st_true\" />$st_true</li>\n"; 00080 $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$st_false\" />$st_false</li>\n"; 00081 $expout .= "</ul>\n"; 00082 break; 00083 case MULTICHOICE: 00084 $expout .= "<ul class=\"multichoice\">\n"; 00085 foreach($question->options->answers as $answer) { 00086 $ans_text = $this->repchar( $answer->answer ); 00087 if ($question->options->single) { 00088 $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"" . s($ans_text) . "\" />$ans_text</li>\n"; 00089 } 00090 else { 00091 $expout .= " <li><input name=\"quest_$id\" type=\"checkbox\" value=\"" . s($ans_text) . "\" />$ans_text</li>\n"; 00092 } 00093 } 00094 $expout .= "</ul>\n"; 00095 break; 00096 case SHORTANSWER: 00097 $expout .= "<ul class=\"shortanswer\">\n"; 00098 $expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n"; 00099 $expout .= "</ul>\n"; 00100 break; 00101 case NUMERICAL: 00102 $expout .= "<ul class=\"numerical\">\n"; 00103 $expout .= " <li><input name=\"quest_$id\" type=\"text\" /></li>\n"; 00104 $expout .= "</ul>\n"; 00105 break; 00106 case MATCH: 00107 $expout .= "<ul class=\"match\">\n"; 00108 00109 // build answer list 00110 $ans_list = array(); 00111 foreach($question->options->subquestions as $subquestion) { 00112 $ans_list[] = $this->repchar( $subquestion->answertext ); 00113 } 00114 shuffle( $ans_list ); // random display order 00115 00116 // build drop down for answers 00117 $dropdown = "<select name=\"quest_$id\">\n"; 00118 foreach($ans_list as $ans) { 00119 $dropdown .= "<option value=\"" . s($ans) . "\">" . s($ans) . "</option>\n"; 00120 } 00121 $dropdown .= "</select>\n"; 00122 00123 // finally display 00124 foreach($question->options->subquestions as $subquestion) { 00125 $quest_text = $this->repchar( $subquestion->questiontext ); 00126 $expout .= " <li>$quest_text</li>\n"; 00127 $expout .= $dropdown; 00128 } 00129 $expout .= "</ul>\n"; 00130 break; 00131 case DESCRIPTION: 00132 break; 00133 case MULTIANSWER: 00134 $expout .= "<!-- CLOZE type is not supported -->\n"; 00135 break; 00136 default: 00137 echo $OUTPUT->notification("No handler for qtype $question->qtype for GIFT export" ); 00138 } 00139 // close off div 00140 $expout .= "</div>\n\n\n"; 00141 return $expout; 00142 } 00143 00144 00145 protected function presave_process($content) { 00146 // override method to allow us to add xhtml headers and footers 00147 00148 global $CFG; 00149 00150 // get css bit 00151 $css_lines = file( "$CFG->dirroot/question/format/xhtml/xhtml.css" ); 00152 $css = implode( ' ',$css_lines ); 00153 00154 $xp = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"; 00155 $xp .= " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; 00156 $xp .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"; 00157 $xp .= "<head>\n"; 00158 $xp .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n"; 00159 $xp .= "<title>Moodle Quiz XHTML Export</title>\n"; 00160 $xp .= $css; 00161 $xp .= "</head>\n"; 00162 $xp .= "<body>\n"; 00163 $xp .= "<form action=\"...REPLACE ME...\" method=\"post\">\n\n"; 00164 $xp .= $content; 00165 $xp .= "<p class=\"submit\">\n"; 00166 $xp .= " <input type=\"submit\" />\n"; 00167 $xp .= "</p>\n"; 00168 $xp .= "</form>\n"; 00169 $xp .= "</body>\n"; 00170 $xp .= "</html>\n"; 00171 00172 return $xp; 00173 } 00174 00175 public function export_file_extension() { 00176 return '.html'; 00177 } 00178 }