/**
  * Provide export functionality for xml format
  * As answers field in question_jme contains answers ids we can't use typebase method.
  * @param question object the question object
  * @param format object the format object so that helper methods can be used
  * @param extra mixed any additional format specific data that may be passed by the format (see format code for info)
  * @return string the data to append to the output buffer or false if error
  */
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $extraquestionfields = $this->extra_question_fields();
     array_shift($extraquestionfields);
     $expout = '';
     foreach ($extraquestionfields as $field) {
         $exportedvalue = $format->xml_escape($question->options->{$field});
         $expout .= "    <{$field}>{$exportedvalue}</{$field}>\n";
     }
     // Write out all the answers.
     $expout .= $format->write_answers($question->options->answers);
     return $expout;
 }
示例#2
0
    public function export_to_xml($question, qformat_xml $format, $extra=null) {
        $extraquestionfields = $this->extra_question_fields();
        if (!is_array($extraquestionfields)) {
            return false;
        }

        // Omit table name.
        array_shift($extraquestionfields);
        $expout='';
        foreach ($extraquestionfields as $field) {
            $exportedvalue = $format->xml_escape($question->options->$field);
            $expout .= "    <$field>{$exportedvalue}</$field>\n";
        }

        $extraanswersfields = $this->extra_answer_fields();
        if (is_array($extraanswersfields)) {
            array_shift($extraanswersfields);
        }
        foreach ($question->options->answers as $answer) {
            $extra = '';
            if (is_array($extraanswersfields)) {
                foreach ($extraanswersfields as $field) {
                    $exportedvalue = $format->xml_escape($answer->$field);
                    $extra .= "      <{$field}>{$exportedvalue}</{$field}>\n";
                }
            }

            $expout .= $format->write_answer($answer, $extra);
        }
        return $expout;
    }
示例#3
0
 public function test_xml_escape_code_that_looks_like_cdata_end_ok()
 {
     $exporter = new qformat_xml();
     $input = "if (x[[0]]>a) print('hah');";
     $expected = "<![CDATA[if (x[[0]]]]><![CDATA[>a) print('hah');]]>";
     $this->assertEquals($expected, $exporter->xml_escape($input));
     // Check that parsing the expected result does give the input again.
     $parsed = simplexml_load_string('<div>' . $expected . '</div>');
     $this->assertEquals($input, $parsed->xpath('//div')[0]);
 }
示例#4
0
 public function xexport_to_xml($question, qformat_xml $format, $extra = null)
 {
     $extraquestionfields = $this->extra_question_fields();
     if (!is_array($extraquestionfields)) {
         return false;
     }
     //get file storage
     $fs = get_file_storage();
     //omit table name
     array_shift($extraquestionfields);
     $expout = '';
     foreach ($extraquestionfields as $field) {
         if ($field == 'backimage') {
             $exportedvalue = $format->write_files($fs->get_area_files($question->contextid, 'qtype_poodllrecording', 'backimage', $question->id));
         } else {
             $exportedvalue = $format->xml_escape($question->options->{$field});
         }
         $expout .= "    <{$field}>{$exportedvalue}</{$field}>\n";
     }
     return $expout;
 }