/** * Provide import functionality for xml format * @param $xml mixed the segment of data containing the question * @param $fromform object question object processed (so far) by standard import code * @param $format object the format object so that helper methods can be used (in particular error() ) * @param $extra mixed any additional format specific data that may be passed by the format (see format code for info) * @return object question object suitable for save_options() call or false if cannot handle */ public function import_from_xml($xml, $fromform, qformat_xml $format, $extra = null) { // Check question is for us. $qtype = $xml['@']['type']; if ($qtype == 'ddmatch') { $fromform = $format->import_headers($xml); // Header parts particular to ddmatch qtype. $fromform->qtype = $this->name(); $fromform->shuffleanswers = $format->getpath($xml, array('#', 'shuffleanswers', 0, '#'), 1); // Run through subquestions. $fromform->subquestions = array(); $fromform->subanswers = array(); foreach ($xml['#']['subquestion'] as $subqxml) { $fromform->subquestions[] = $format->import_text_with_files($subqxml, array(), '', $format->get_format($fromform->questiontextformat)); $answers = $format->getpath($subqxml, array('#', 'answer', 0), array()); $fromform->subanswers[] = $format->import_text_with_files($answers, array(), '', $format->get_format($fromform->questiontextformat)); } $format->import_combined_feedback($fromform, $xml, true); $format->import_hints($fromform, $xml, true); return $fromform; } else { return false; } }
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; }