public function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     if (!isset($data['@']['type']) || $data['@']['type'] != 'gapselect') {
         return false;
     }
     $question = $format->import_headers($data);
     $question->qtype = 'gapselect';
     $question->shuffleanswers = $format->trans_single($format->getpath($data, array('#', 'shuffleanswers', 0, '#'), 1));
     if (!empty($data['#']['selectoption'])) {
         // Modern XML format.
         $selectoptions = $data['#']['selectoption'];
         $question->answer = array();
         $question->selectgroup = array();
         foreach ($data['#']['selectoption'] as $selectoptionxml) {
             $question->choices[] = array('answer' => $format->getpath($selectoptionxml, array('#', 'text', 0, '#'), '', true), 'choicegroup' => $format->getpath($selectoptionxml, array('#', 'group', 0, '#'), 1));
         }
     } else {
         // Legacy format containing PHP serialisation.
         foreach ($data['#']['answer'] as $answerxml) {
             $ans = $format->import_answer($answerxml);
             $question->choices[] = array('answer' => $ans->answer, 'choicegroup' => $ans->feedback);
         }
     }
     $format->import_combined_feedback($question, $data, true);
     $format->import_hints($question, $data, true, false, $format->get_format($question->questiontextformat));
     return $question;
 }
示例#2
0
 public function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     if (!isset($data['@']['type']) || $data['@']['type'] != 'ddwtos') {
         return false;
     }
     $question = $format->import_headers($data);
     $question->qtype = 'ddwtos';
     $question->shuffleanswers = $format->trans_single($format->getpath($data, array('#', 'shuffleanswers', 0, '#'), 1));
     if (!empty($data['#']['dragbox'])) {
         // Modern XML format.
         $dragboxes = $data['#']['dragbox'];
         $question->answer = array();
         $question->draggroup = array();
         $question->infinite = array();
         foreach ($data['#']['dragbox'] as $dragboxxml) {
             $question->choices[] = array('answer' => $format->getpath($dragboxxml, array('#', 'text', 0, '#'), '', true), 'choicegroup' => $format->getpath($dragboxxml, array('#', 'group', 0, '#'), 1), 'infinite' => array_key_exists('infinite', $dragboxxml['#']));
         }
     } else {
         // Legacy format containing PHP serialisation.
         foreach ($data['#']['answer'] as $answerxml) {
             $ans = $format->import_answer($answerxml);
             $options = unserialize(stripslashes($ans->feedback['text']));
             $question->choices[] = array('answer' => $ans->answer, 'choicegroup' => $options->draggroup, 'infinite' => $options->infinite);
         }
     }
     $format->import_combined_feedback($question, $data, true);
     $format->import_hints($question, $data, true, false, $format->get_format($question->questiontextformat));
     return $question;
 }
示例#3
0
 /**
  * Imports the question from Moodle XML format.
  *
  * @param array $xml structure containing the XML data
  * @param object $fromform question object to fill: ignored by this function (assumed to be null)
  * @param qformat_xml $format format class exporting the question
  * @param object $extra extra information (not required for importing this question in this format)
  * @return object question object
  */
 public function import_from_xml($xml, $fromform, qformat_xml $format, $extra = null)
 {
     // Return if data type is not our own one.
     if (!isset($xml['@']['type']) || $xml['@']['type'] != $this->name()) {
         return false;
     }
     // Import the common question headers and set the corresponding field.
     $fromform = $format->import_headers($xml);
     $fromform->qtype = $this->name();
     $format->import_combined_feedback($fromform, $xml, true);
     $format->import_hints($fromform, $xml, true);
     $extras = $this->extra_question_fields();
     array_shift($extras);
     foreach ($extras as $extra) {
         $fromform->{$extra} = $format->getpath($xml, array('#', $extra, 0, '#'), '', true);
     }
     return $fromform;
 }
示例#4
0
 public function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     if (!isset($data['@']['type']) || $data['@']['type'] != 'ddimageortext') {
         return false;
     }
     $question = $format->import_headers($data);
     $question->qtype = 'ddimageortext';
     $question->shuffleanswers = array_key_exists('shuffleanswers', $format->getpath($data, array('#'), array()));
     $filexml = $format->getpath($data, array('#', 'file'), array());
     $question->bgimage = $format->import_files_as_draft($filexml);
     $drags = $data['#']['drag'];
     $question->drags = array();
     foreach ($drags as $dragxml) {
         $dragno = $format->getpath($dragxml, array('#', 'no', 0, '#'), 0);
         $dragindex = $dragno - 1;
         $question->drags[$dragindex] = array();
         $question->draglabel[$dragindex] = $format->getpath($dragxml, array('#', 'text', 0, '#'), '', true);
         $question->drags[$dragindex]['infinite'] = array_key_exists('infinite', $dragxml['#']);
         $question->drags[$dragindex]['draggroup'] = $format->getpath($dragxml, array('#', 'draggroup', 0, '#'), 1);
         $filexml = $format->getpath($dragxml, array('#', 'file'), array());
         $question->dragitem[$dragindex] = $format->import_files_as_draft($filexml);
         if (count($filexml)) {
             $question->drags[$dragindex]['dragitemtype'] = 'image';
         } else {
             $question->drags[$dragindex]['dragitemtype'] = 'word';
         }
     }
     $drops = $data['#']['drop'];
     $question->drops = array();
     foreach ($drops as $dropxml) {
         $dropno = $format->getpath($dropxml, array('#', 'no', 0, '#'), 0);
         $dropindex = $dropno - 1;
         $question->drops[$dropindex] = array();
         $question->drops[$dropindex]['choice'] = $format->getpath($dropxml, array('#', 'choice', 0, '#'), 0);
         $question->drops[$dropindex]['droplabel'] = $format->getpath($dropxml, array('#', 'text', 0, '#'), '', true);
         $question->drops[$dropindex]['xleft'] = $format->getpath($dropxml, array('#', 'xleft', 0, '#'), '');
         $question->drops[$dropindex]['ytop'] = $format->getpath($dropxml, array('#', 'ytop', 0, '#'), '');
     }
     $format->import_combined_feedback($question, $data, true);
     $format->import_hints($question, $data, true, false, $format->get_format($question->questiontextformat));
     return $question;
 }
 /**
  * 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;
     }
 }
示例#6
0
 public function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     if (!isset($data['@']['type']) || $data['@']['type'] != 'ddmarker') {
         return false;
     }
     $question = $format->import_headers($data);
     $question->qtype = 'ddmarker';
     $question->shuffleanswers = array_key_exists('shuffleanswers', $format->getpath($data, array('#'), array()));
     $question->showmisplaced = array_key_exists('showmisplaced', $format->getpath($data, array('#'), array()));
     $filexml = $format->getpath($data, array('#', 'file'), array());
     $question->bgimage = $format->import_files_as_draft($filexml);
     $drags = $data['#']['drag'];
     $question->drags = array();
     foreach ($drags as $dragxml) {
         $dragno = $format->getpath($dragxml, array('#', 'no', 0, '#'), 0);
         $dragindex = $dragno - 1;
         $question->drags[$dragindex] = array();
         $question->drags[$dragindex]['label'] = $format->getpath($dragxml, array('#', 'text', 0, '#'), '', true);
         if (array_key_exists('infinite', $dragxml['#'])) {
             $question->drags[$dragindex]['noofdrags'] = 0;
             // Means infinite in the form.
         } else {
             // Defaults to 1 if 'noofdrags' not set.
             $question->drags[$dragindex]['noofdrags'] = $format->getpath($dragxml, array('#', 'noofdrags', 0, '#'), 1);
         }
     }
     $drops = $data['#']['drop'];
     $question->drops = array();
     foreach ($drops as $dropxml) {
         $dropno = $format->getpath($dropxml, array('#', 'no', 0, '#'), 0);
         $dropindex = $dropno - 1;
         $question->drops[$dropindex] = array();
         $question->drops[$dropindex]['choice'] = $format->getpath($dropxml, array('#', 'choice', 0, '#'), 0);
         $question->drops[$dropindex]['shape'] = $format->getpath($dropxml, array('#', 'shape', 0, '#'), '');
         $question->drops[$dropindex]['coords'] = $format->getpath($dropxml, array('#', 'coords', 0, '#'), '');
     }
     $format->import_combined_feedback($question, $data, true);
     $format->import_hints($question, $data, true, true, $format->get_format($question->questiontextformat));
     return $question;
 }