/**
  * Helper method used by {@link export_to_xml()}.
  * @param array $xml the XML to extract the data from.
  * @param string $field the name of the sub-tag in the XML to load the data from.
  * @param qformat_xml $format the importer/exporter object.
  * @param int $defaultformat Dfeault text format, if it is not given in the file.
  * @return array with fields text, format and files.
  */
 protected function import_xml_text($xml, $field, qformat_xml $format, $defaultformat)
 {
     $text = array();
     $text['text'] = $format->getpath($xml, array('#', $field, 0, '#', 'text', 0, '#'), '', true);
     $text['format'] = $format->trans_format($format->getpath($xml, array('#', $field, 0, '@', 'format'), $format->get_format($defaultformat)));
     $text['files'] = $format->import_files($format->getpath($xml, array('#', $field, 0, '#', 'file'), array(), false));
     return $text;
 }
示例#2
0
 public function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     global $CFG;
     $question_type = "poodllrecording";
     //omit table name
     $qo = $format->import_headers($data);
     $qo->qtype = $question_type;
     $q = $data;
     $qo->responseformat = $format->getpath($q, array('#', 'responseformat', 0, '#'), 'picture');
     $qo->responsefieldlines = $format->getpath($q, array('#', 'responsefieldlines', 0, '#'), 15);
     $qo->attachments = $format->getpath($q, array('#', 'attachments', 0, '#'), 0);
     //older versions handled files diff. SeeM DL-39-57
     if ($CFG->version < 2013051400) {
         $qo->graderinfo['text'] = $format->getpath($q, array('#', 'graderinfo', 0, '#', 'text', 0, '#'), '', true);
         $qo->graderinfo['format'] = $format->trans_format($format->getpath($q, array('#', 'graderinfo', 0, '@', 'format'), $format->get_format($qo->questiontextformat)));
         $qo->graderinfo['files'] = $format->import_files($format->getpath($q, array('#', 'graderinfo', '0', '#', 'file'), array()));
         $qo->backimage = $format->import_files($format->getpath($q, array('#', 'backimage', '0', '#', 'file'), array()));
     } else {
         $qo->graderinfo = $format->import_text_with_files($q, array('#', 'graderinfo', 0), '', $qo->questiontextformat);
         $qo->backimage = $format->import_files_as_draft($format->getpath($q, array('#', 'backimage', '0', '#', 'file'), array()));
     }
     $qo->boardsize = $format->getpath($q, array('#', 'boardsize', 0, '#'), '320x320');
     $qo->timelimit = $format->getpath($q, array('#', 'timelimit', 0, '#'), 0);
     return $qo;
 }
 /**
  * Create a draft files area, import files into it and return the draft item id.
  * @param qformat_xml $format
  * @param array $xml an array of <file> nodes from the the parsed XML.
  * @return integer draftitemid
  */
 public function import_files_to_draft_file_area($format, $xml)
 {
     global $USER;
     $fs = get_file_storage();
     $files = $format->import_files($xml);
     $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
     $draftitemid = file_get_unused_draft_itemid();
     foreach ($files as $file) {
         $record = new stdClass();
         $record->contextid = $usercontext->id;
         $record->component = 'user';
         $record->filearea = 'draft';
         $record->itemid = $draftitemid;
         $record->filename = $file->name;
         $record->filepath = '/';
         $fs->create_file_from_string($record, $this->decode_file($file));
     }
     return $draftitemid;
 }
示例#4
0
 public function ximport_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     $question_type = "poodllrecording";
     $extraquestionfields = $this->extra_question_fields();
     if (!is_array($extraquestionfields)) {
         return false;
     }
     //omit table name
     array_shift($extraquestionfields);
     $qo = $format->import_headers($data);
     $qo->qtype = $question_type;
     foreach ($extraquestionfields as $field) {
         if ($field == 'backimage') {
             //this probably wont work, it might save the file, but the id will not get stored in the backimage field
             //maybe do as we do in save_question_options above, see base 64 decode logic in questiontypebase.php import_file
             $qo->backimage['files'] = $format->import_files($format->getpath($question, array('#', 'backimage', '0', '#', 'file'), array()));
         } else {
             $qo->{$field} = $format->getpath($data, array('#', $field, 0, '#'), '');
         }
         //end of if back image
     }
     //end of for each
     return $qo;
 }