class qformat_xhtml in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/xhtml/format.php \qformat_xhtml
@package questionbank @subpackage importexport
Hierarchy
- class \qformat_default- class \qformat_xhtml
 
Expanded class hierarchy of qformat_xhtml
File
- includes/moodle/ question/ format/ xhtml/ format.php, line 7 
View source
class qformat_xhtml extends qformat_default {
  function provide_export() {
    return true;
  }
  function repchar($text) {
    // escapes 'reserved' characters # = ~ { ) and removes new lines
    $reserved = array(
      '#',
      '=',
      '~',
      '{',
      '}',
      "\n",
      "\r",
    );
    $escaped = array(
      '\\#',
      '\\=',
      '\\~',
      '\\{',
      '\\}',
      ' ',
      '',
    );
    return str_replace($reserved, $escaped, $text);
  }
  function writequestion($question) {
    // 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 .= "<!-- question: {$id}  name: {$question->name} -->\n";
    $expout .= "<div class=\"question\">\n";
    // add header
    $expout .= "<h3>{$question->name}</h3>\n";
    // format and add question text
    $questiontext = $question->questiontext;
    $format = $question->questiontextformat;
    $formatted_text = format_text($questiontext, $format);
    $expout .= "<p class=\"questiontext\">{$formatted_text}</p>\n";
    // selection depends on question type
    switch ($question->qtype) {
      case TRUEFALSE:
        $st_true = get_string('true', 'quiz');
        $st_false = get_string('false', 'quiz');
        $expout .= "<ul class=\"truefalse\">\n";
        $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\"{$st_true}\" />{$st_true}</li>\n";
        $expout .= "  <li><input name=\"quest_{$id}\" type=\"radio\" value=\"{$st_false}\" />{$st_false}</li>\n";
        $expout .= "</ul>\n";
        break;
      case MULTICHOICE:
        $expout .= "<ul class=\"multichoice\">\n";
        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";
          }
          else {
            $expout .= "  <li><input name=\"quest_{$id}\" type=\"checkbox\" value=\"{$ans_text}\" />{$ans_text}</li>\n";
          }
        }
        $expout .= "</ul>\n";
        break;
      case SHORTANSWER:
        $expout .= "<ul class=\"shortanswer\">\n";
        $expout .= "  <li><input name=\"quest_{$id}\" type=\"text\" /></li>\n";
        $expout .= "</ul>\n";
        break;
      case NUMERICAL:
        $expout .= "<ul class=\"numerical\">\n";
        $expout .= "  <li><input name=\"quest_{$id}\" type=\"text\" /></li>\n";
        $expout .= "</ul>\n";
        break;
      case MATCH:
        $expout .= "<ul class=\"match\">\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 = "<select name=\"quest_{$id}\">\n";
        foreach ($ans_list as $ans) {
          $dropdown .= "<option value=\"{$ans}\">{$ans}</option>\n";
        }
        $dropdown .= "</select>\n";
        // finally display
        foreach ($question->options->subquestions as $subquestion) {
          $quest_text = $this
            ->repchar($subquestion->questiontext);
          $expout .= "  <li>{$quest_text}</li>\n";
          $expout .= $dropdown;
        }
        $expout .= "</ul>\n";
        break;
      case DESCRIPTION:
        break;
      case MULTIANSWER:
        $expout .= "<!-- CLOZE type is not supported  -->\n";
        break;
      default:
        notify("No handler for qtype {$question->qtype} for GIFT export");
    }
    // close off div
    $expout .= "</div>\n\n\n";
    return $expout;
  }
  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 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
    $xp .= "  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
    $xp .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
    $xp .= "<head>\n";
    $xp .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n";
    $xp .= "<title>Moodle Quiz XHTML Export</title>\n";
    $xp .= $css;
    $xp .= "</head>\n";
    $xp .= "<body>\n";
    $xp .= "<form action=\"...REPLACE ME...\" method=\"post\">\n\n";
    $xp .= $content;
    $xp .= "<p class=\"submit\">\n";
    $xp .= "  <input type=\"submit\" />\n";
    $xp .= "</p>\n";
    $xp .= "</form>\n";
    $xp .= "</body>\n";
    $xp .= "</html>\n";
    return $xp;
  }
  function export_file_extension() {
    return ".html";
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | property | |||
| qformat_default:: | function | Count all non-category questions in the questions array. | ||
| qformat_default:: | function | find and/or create the category described by a delimited list e.g. $course$/tom/dick/harry or tom/dick/harry | ||
| qformat_default:: | function | return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. This should not be overridden. | ||
| qformat_default:: | function | Handle parsing error | ||
| qformat_default:: | function | Do an post-processing that may be required | ||
| qformat_default:: | function | Do any pre-processing that may be required | 1 | |
| qformat_default:: | function | Do the export For most types this should not need to be overrided | 1 | |
| qformat_default:: | function | where question specifies a moodle (text) format this performs the conversion. | ||
| qformat_default:: | function | get the category as a path (e.g., tom/dick/harry) | ||
| qformat_default:: | function | Import an image file encoded in base64 format | ||
| qformat_default:: | function | Override if any post-processing is required | 2 | |
| qformat_default:: | function | Perform any required pre-processing | 2 | |
| qformat_default:: | function | Process the file This method should not normally be overidden | 1 | |
| qformat_default:: | function | 12 | ||
| qformat_default:: | function | get directory into which export is going | ||
| qformat_default:: | function | Return complete file within an array, one item per line | 1 | |
| qformat_default:: | function | Given the data known to define a question in this format, this function converts it into a question object suitable for processing and insertion into Moodle. | 5 | |
| qformat_default:: | function | Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). Questions are defined as anything between blank lines. | 9 | |
| qformat_default:: | function | set the category | ||
| qformat_default:: | function | set catfromfile | ||
| qformat_default:: | function | set cattofile | ||
| qformat_default:: | function | set contextfromfile | ||
| qformat_default:: | function | set an array of contexts. | ||
| qformat_default:: | function | set contexttofile | ||
| qformat_default:: | function | set the course class variable | ||
| qformat_default:: | function | set the filename | ||
| qformat_default:: | function | set matchgrades | ||
| qformat_default:: | function | Set the specific questions to export. Should not include questions with parents (sub questions of cloze question type). Only used for question export. | ||
| qformat_default:: | function | set the "real" filename (this is what the user typed, regardless of wha happened next) | ||
| qformat_default:: | function | set stoponerror | ||
| qformat_default:: | function | |||
| qformat_default:: | function | Provide export functionality for plugin questiontypes Do not override | ||
| qformat_default:: | function | Import for questiontype plugins Do not override. | ||
| qformat_xhtml:: | function | Return the files extension appropriate for this type
override if you don't want .txt Overrides qformat_default:: | ||
| qformat_xhtml:: | function | Enable any processing to be done on the content
just prior to the file being saved
default is to do nothing Overrides qformat_default:: | ||
| qformat_xhtml:: | function | Overrides qformat_default:: | ||
| qformat_xhtml:: | function | |||
| qformat_xhtml:: | function | convert a single question object into text output in the given
format.
This must be overriden Overrides qformat_default:: | 
