.
/**
* XHTML question exporter.
*
* @package qformat
* @subpackage xhtml
* @copyright 2005 Howard Miller
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* XHTML question exporter.
*
* Exports questions as static HTML.
*
* @copyright 2005 Howard Miller
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_xhtml extends qformat_default {
public function provide_export() {
return true;
}
protected function repchar($text) {
return $text;
}
protected function writequestion($question) {
global $OUTPUT;
// turns question into string
// question reflects database fields for general question and specific to type
// if a category switch, just ignore
if ($question->qtype=='category') {
return '';
}
// initial string;
$expout = "";
$id = $question->id;
// add comment and div tags
$expout .= "\n";
$expout .= "
\n";
// add header
$expout .= "
$question->name
\n";
// Format and add the question text
$expout .= '
\n";
// selection depends on question type
switch($question->qtype) {
case TRUEFALSE:
$st_true = get_string('true', 'qtype_truefalse');
$st_false = get_string('false', 'qtype_truefalse');
$expout .= "
\n";
$expout .= "
$st_true
\n";
$expout .= "
$st_false
\n";
$expout .= "
\n";
break;
case MULTICHOICE:
$expout .= "
\n";
foreach($question->options->answers as $answer) {
$ans_text = $this->repchar( $answer->answer );
if ($question->options->single) {
$expout .= "
$ans_text
\n";
}
else {
$expout .= "
$ans_text
\n";
}
}
$expout .= "
\n";
break;
case SHORTANSWER:
$expout .= "
\n";
$expout .= " \n";
$expout .= "
\n";
break;
case NUMERICAL:
$expout .= "
\n";
$expout .= " \n";
$expout .= "
\n";
break;
case MATCH:
$expout .= "
\n";
// build answer list
$ans_list = array();
foreach($question->options->subquestions as $subquestion) {
$ans_list[] = $this->repchar( $subquestion->answertext );
}
shuffle( $ans_list ); // random display order
// build drop down for answers
$dropdown = "\n";
// finally display
foreach($question->options->subquestions as $subquestion) {
$quest_text = $this->repchar( $subquestion->questiontext );
$expout .= "
$quest_text
\n";
$expout .= $dropdown;
}
$expout .= "
\n";
break;
case DESCRIPTION:
break;
case MULTIANSWER:
$expout .= "\n";
break;
default:
echo $OUTPUT->notification("No handler for qtype $question->qtype for GIFT export" );
}
// close off div
$expout .= "
\n\n\n";
return $expout;
}
protected function presave_process($content) {
// override method to allow us to add xhtml headers and footers
global $CFG;
// get css bit
$css_lines = file( "$CFG->dirroot/question/format/xhtml/xhtml.css" );
$css = implode( ' ',$css_lines );
$xp = "\n";
$xp .= "\n";
$xp .= "\n";
$xp .= "\n";
$xp .= "Moodle Quiz XHTML Export\n";
$xp .= $css;
$xp .= "\n";
$xp .= "\n";
$xp .= "\n";
$xp .= "\n";
$xp .= "\n";
return $xp;
}
public function export_file_extension() {
return '.html';
}
}