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;
 }
 public function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     global $CFG;
     if (!array_key_exists('@', $data)) {
         return false;
     }
     if (!array_key_exists('type', $data['@'])) {
         return false;
     }
     if ($data['@']['type'] == 'jme') {
         // Get common parts.
         $question = $format->import_headers($data);
         // Header parts particular to jme.
         $question->qtype = 'jme';
         $question->jmeoptions = $format->getpath($data, array('#', 'jmeoptions', 0, '#'), $CFG->qtype_jme_options);
         $question->width = $format->getpath($data, array('#', 'width', 0, '#'), QTYPE_JME_APPLET_WIDTH);
         $question->height = $format->getpath($data, array('#', 'height', 0, '#'), QTYPE_JME_APPLET_HEIGHT);
         // Run through the answers.
         $answers = $data['#']['answer'];
         $anscount = 0;
         foreach ($answers as $answer) {
             $ans = $format->import_answer($answer);
             $question->answer[$anscount] = $ans->answer['text'];
             $question->fraction[$anscount] = $ans->fraction;
             $question->feedback[$anscount] = $ans->feedback;
             ++$anscount;
         }
         $format->import_hints($question, $data);
         return $question;
     }
     return false;
 }
Пример #3
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;
 }
Пример #4
0
    public function import_from_xml($data, $question, qformat_xml $format, $extra=null) {
        $question_type = $data['@']['type'];
        if ($question_type != $this->name()) {
            return false;
        }

        $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) {
            $qo->$field = $format->getpath($data, array('#', $field, 0, '#'), '');
        }

        // Run through the answers.
        $answers = $data['#']['answer'];
        $a_count = 0;
        $extraanswersfields = $this->extra_answer_fields();
        if (is_array($extraanswersfields)) {
            array_shift($extraanswersfields);
        }
        foreach ($answers as $answer) {
            $ans = $format->import_answer($answer);
            if (!$this->has_html_answers()) {
                $qo->answer[$a_count] = $ans->answer['text'];
            } else {
                $qo->answer[$a_count] = $ans->answer;
            }
            $qo->fraction[$a_count] = $ans->fraction;
            $qo->feedback[$a_count] = $ans->feedback;
            if (is_array($extraanswersfields)) {
                foreach ($extraanswersfields as $field) {
                    $qo->{$field}[$a_count] =
                        $format->getpath($answer, array('#', $field, 0, '#'), '');
                }
            }
            ++$a_count;
        }
        return $qo;
    }
Пример #5
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;
 }
Пример #6
0
 /**
  * Provide import functionality for xml format
  * @param data mixed the segment of data containing the question
  * @param question 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($data, $question, qformat_xml $format, $extra = null)
 {
     // Check question is for us.
     if (!isset($data['@']['type']) || $data['@']['type'] != 'multichoiceset') {
         return false;
     }
     $question = $format->import_headers($data);
     $question->qtype = 'multichoiceset';
     $question->shuffleanswers = $format->trans_single($format->getpath($data, array('#', 'shuffleanswers', 0, '#'), 1));
     $question->answernumbering = $format->getpath($data, array('#', 'answernumbering', 0, '#'), 'abc');
     $question->correctfeedback = array();
     $question->correctfeedback['text'] = $format->getpath($data, array('#', 'correctfeedback', 0, '#', 'text', 0, '#'), '', true);
     $question->correctfeedback['format'] = $format->trans_format($format->getpath($data, array('#', 'correctfeedback', 0, '@', 'format'), $format->get_format($question->questiontextformat)));
     $question->correctfeedback['files'] = array();
     // Restore files in correctfeedback.
     $files = $format->getpath($data, array('#', 'correctfeedback', 0, '#', 'file'), array(), false);
     foreach ($files as $file) {
         $filesdata = new stdclass();
         $filesdata->content = $file['#'];
         $filesdata->encoding = $file['@']['encoding'];
         $filesdata->name = $file['@']['name'];
         $question->correctfeedback['files'][] = $filesdata;
     }
     $question->incorrectfeedback = array();
     $question->incorrectfeedback['text'] = $format->getpath($data, array('#', 'incorrectfeedback', 0, '#', 'text', 0, '#'), '', true);
     $question->incorrectfeedback['format'] = $format->trans_format($format->getpath($data, array('#', 'incorrectfeedback', 0, '@', 'format'), $format->get_format($question->questiontextformat)));
     $question->incorrectfeedback['files'] = array();
     // Restore files in incorrectfeedback.
     $files = $format->getpath($data, array('#', 'incorrectfeedback', 0, '#', 'file'), array(), false);
     foreach ($files as $file) {
         $filesdata = new stdclass();
         $filesdata->content = $file['#'];
         $filesdata->encoding = $file['@']['encoding'];
         $filesdata->name = $file['@']['name'];
         $question->incorrectfeedback['files'][] = $filesdata;
     }
     $question->shownumcorrect = array_key_exists('shownumcorrect', $data['#']);
     // Run through the answers.
     $answers = $data['#']['answer'];
     foreach ($answers as $answer) {
         $ans = $format->import_answer($answer, true, $format->get_format($question->questiontextformat));
         $question->answer[] = $ans->answer;
         $question->correctanswer[] = !empty($ans->fraction);
         $question->feedback[] = $ans->feedback;
         // Backwards compatibility.
         if (array_key_exists('correctanswer', $answer['#'])) {
             $key = end(array_keys($question->correctanswer));
             $question->correctanswer[$key] = $format->getpath($answer, array('#', 'correctanswer', 0, '#'), 0);
         }
     }
     $format->import_hints($question, $data, true, true, $format->get_format($question->questiontextformat));
     // Get extra choicefeedback setting from each hint.
     if (!empty($question->hintoptions)) {
         foreach ($question->hintoptions as $key => $options) {
             $question->hintshowchoicefeedback[$key] = !empty($options);
         }
     }
     return $question;
 }
Пример #7
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;
 }
Пример #8
0
 public function import_from_xml($xml, $fromform, qformat_xml $format, $notused = null)
 {
     if (!isset($xml['@']['type']) || $xml['@']['type'] != $this->name()) {
         return false;
     }
     $fromform = $format->import_headers($xml);
     $fromform->qtype = $this->name();
     $fromform->questionvariables = $format->getpath($xml, array('#', 'questionvariables', 0, '#', 'text', 0, '#'), '', true);
     $fromform->specificfeedback = $this->import_xml_text($xml, 'specificfeedback', $format, $fromform->questiontextformat);
     $fromform->questionnote = $format->getpath($xml, array('#', 'questionnote', 0, '#', 'text', 0, '#'), '', true);
     $fromform->questionsimplify = $format->getpath($xml, array('#', 'questionsimplify', 0, '#'), 1);
     $fromform->assumepositive = $format->getpath($xml, array('#', 'assumepositive', 0, '#'), 0);
     $fromform->prtcorrect = $this->import_xml_text($xml, 'prtcorrect', $format, $fromform->questiontextformat);
     $fromform->prtpartiallycorrect = $this->import_xml_text($xml, 'prtpartiallycorrect', $format, $fromform->questiontextformat);
     $fromform->prtincorrect = $this->import_xml_text($xml, 'prtincorrect', $format, $fromform->questiontextformat);
     $fromform->penalty = $format->getpath($xml, array('#', 'penalty', 0, '#'), 0.1);
     $fromform->multiplicationsign = $format->getpath($xml, array('#', 'multiplicationsign', 0, '#'), 'dot');
     $fromform->sqrtsign = $format->getpath($xml, array('#', 'sqrtsign', 0, '#'), 1);
     $fromform->complexno = $format->getpath($xml, array('#', 'complexno', 0, '#'), 'i');
     $fromform->inversetrig = $format->getpath($xml, array('#', 'inversetrig', 0, '#'), 'cos-1');
     $fromform->matrixparens = $format->getpath($xml, array('#', 'matrixparens', 0, '#'), '[');
     $fromform->variantsselectionseed = $format->getpath($xml, array('#', 'variantsselectionseed', 0, '#'), 'i');
     if (isset($xml['#']['input'])) {
         foreach ($xml['#']['input'] as $inputxml) {
             $this->import_xml_input($inputxml, $fromform, $format);
         }
     }
     if (isset($xml['#']['input'])) {
         foreach ($xml['#']['input'] as $inputxml) {
             $this->import_xml_input($inputxml, $fromform, $format);
         }
     }
     if (isset($xml['#']['prt'])) {
         foreach ($xml['#']['prt'] as $prtxml) {
             $this->import_xml_prt($prtxml, $fromform, $format);
         }
     }
     $format->import_hints($fromform, $xml, false, false, $format->get_format($fromform->questiontextformat));
     if (isset($xml['#']['deployedseed'])) {
         $fromform->deployedseeds = array();
         foreach ($xml['#']['deployedseed'] as $seedxml) {
             $fromform->deployedseeds[] = $format->getpath($seedxml, array('#'), null);
         }
     }
     if (isset($xml['#']['qtest'])) {
         $fromform->testcases = array();
         foreach ($xml['#']['qtest'] as $qtestxml) {
             list($no, $testcase) = $this->import_xml_qtest($qtestxml, $format);
             $fromform->testcases[$no] = $testcase;
         }
     }
     return $fromform;
 }
 public function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     $question_type = $format->getpath($data, array('@', 'type'), '');
     if ($question_type != 'ordering') {
         return false;
     }
     $newquestion = $format->import_headers($data);
     $newquestion->qtype = $question_type;
     // fix empty or long question name
     $newquestion->name = $this->fix_questionname($newquestion->name, $newquestion->questiontext);
     // extra fields fields fields - "selecttype" and "selectcount"
     // (these fields used to be called "logical" and "studentsee")
     if (isset($data['#']['selecttype'])) {
         $selecttype = 'selecttype';
         $selectcount = 'selectcount';
     } else {
         $selecttype = 'logical';
         $selectcount = 'studentsee';
     }
     $selecttype = $format->getpath($data, array('#', $selecttype, 0, '#'), 'RANDOM');
     $selectcount = $format->getpath($data, array('#', $selectcount, 0, '#'), 6);
     $this->set_count_and_type($newquestion, $selectcount, $selecttype);
     $newquestion->answer = array();
     $newquestion->answerformat = array();
     $newquestion->fraction = array();
     $newquestion->feedback = array();
     $newquestion->feedbackformat = array();
     $i = 0;
     while ($answer = $format->getpath($data, array('#', 'answer', $i), '')) {
         if ($text = $format->getpath($answer, array('#', 'text', 0, '#'), '')) {
             $newquestion->answer[] = $text;
             $answerformat = $format->getpath($answer, array('@', 'format'), 'moodle_auto_format');
             $newquestion->answerformat[] = $format->trans_format($answerformat);
             $newquestion->fraction[] = 1;
             // will be reset later in save_question_options()
             $newquestion->feedback[] = $format->getpath($answer, array('#', 'feedback', 0, '#', 'text', 0, '#'), '');
             $feedbackformat = $format->getpath($answer, array('#', 'format', 0, '@', 'format'), 'moodle_auto_format');
             $newquestion->feedbackformat[] = $format->trans_format($feedbackformat);
         }
         $i++;
     }
     return $newquestion;
 }
Пример #10
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 = $this->import_files_to_draft_file_area($format, $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);
         $question->drags[$dragindex]['infinite'] = array_key_exists('infinite', $dragxml['#']);
     }
     $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;
 }
 /**
  * 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;
     }
 }
Пример #12
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;
 }
Пример #13
0
 function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     if ($extra != null) {
         throw new coding_exception("coderunner:import_from_xml: unexpected 'extra' parameter");
     }
     $questiontype = $data['@']['type'];
     if ($questiontype != $this->name()) {
         return false;
     }
     $extraquestionfields = $this->extra_question_fields();
     if (!is_array($extraquestionfields)) {
         return false;
     }
     //omit table name
     array_shift($extraquestionfields);
     $qo = $format->import_headers($data);
     $qo->qtype = $questiontype;
     $newdefaults = array('allornothing' => 1, 'answerboxlines' => 15, 'answerboxcolumns' => 90, 'useace' => 1);
     foreach ($extraquestionfields as $field) {
         if ($field === 'pertesttemplate' && isset($data['#']['custom_template'])) {
             // Legacy import
             $qo->pertesttemplate = $format->getpath($data, array('#', 'custom_template', 0, '#'), '');
         } else {
             $map = $this->legacy_field_name_map();
             if (isset($map[$field]) && isset($data['#'][$map[$field]])) {
                 $data['#'][$field] = $data['#'][$map[$field]];
                 // Map old field names to new
                 unset($data['#'][$map[$field]]);
             }
             if (array_key_exists($field, $newdefaults)) {
                 $default = $newdefaults[$field];
             } else {
                 $default = '';
             }
             $qo->{$field} = $format->getpath($data, array('#', $field, 0, '#'), $default);
         }
     }
     $qo->isnew = true;
     $qo->testcases = array();
     if (isset($data['#']['testcases'][0]['#']['testcase']) && is_array($data['#']['testcases'][0]['#']['testcase'])) {
         $testcases = $data['#']['testcases'][0]['#']['testcase'];
         foreach ($testcases as $testcase) {
             $tc = new stdClass();
             $tc->testcode = $testcase['#']['testcode'][0]['#']['text'][0]['#'];
             $tc->stdin = $testcase['#']['stdin'][0]['#']['text'][0]['#'];
             if (isset($testcase['#']['output'])) {
                 // Handle old exports
                 $tc->expected = $testcase['#']['output'][0]['#']['text'][0]['#'];
             } else {
                 $tc->expected = $testcase['#']['expected'][0]['#']['text'][0]['#'];
             }
             $tc->extra = $testcase['#']['extra'][0]['#']['text'][0]['#'];
             $tc->display = 'SHOW';
             $tc->mark = 1.0;
             if (isset($testcase['@']['mark'])) {
                 $tc->mark = floatval($testcase['@']['mark']);
             }
             if (isset($testcase['@']['hidden']) && $testcase['@']['hidden'] == "1") {
                 $tc->display = 'HIDE';
                 // Handle old-style export too
             }
             if (isset($testcase['#']['display'])) {
                 $tc->display = $testcase['#']['display'][0]['#']['text'][0]['#'];
             }
             if (isset($testcase['@']['hiderestiffail'])) {
                 $tc->hiderestiffail = $testcase['@']['hiderestiffail'] == "1" ? 1 : 0;
             } else {
                 $tc->hiderestiffail = 0;
             }
             $tc->useasexample = $testcase['@']['useasexample'] == "1" ? 1 : 0;
             $qo->testcases[] = $tc;
         }
     }
     $datafiles = $format->getpath($data, array('#', 'testcases', 0, '#', 'file'), array());
     if (is_array($datafiles)) {
         // Seems like a non-array does occur in some versions of PHP :-/
         $qo->datafiles = $format->import_files_as_draft($datafiles);
     }
     return $qo;
 }
Пример #14
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;
 }
Пример #15
0
 function import_from_xml($data, $question, qformat_xml $format, $extra = null)
 {
     // check question is for us///
     $qtype = $data['@']['type'];
     if ($qtype == 'regexp') {
         $qo = $format->import_headers($data);
         // header parts particular to regexp
         $qo->qtype = "regexp";
         $qo->usehint = 0;
         // get usehint
         $qo->usehint = $format->getpath($data, array('#', 'usehint', 0, '#'), $qo->usehint);
         // get usecase
         $qo->usecase = $format->getpath($data, array('#', 'usecase', 0, '#'), $qo->usecase);
         // get studentshowalternate
         $qo->studentshowalternate = $format->getpath($data, array('#', 'studentshowalternate', 0, '#'), $qo->studentshowalternate);
         // run through the answers
         $answers = $data['#']['answer'];
         $a_count = 0;
         foreach ($answers as $answer) {
             $ans = $format->import_answer($answer);
             $qo->answer[$a_count] = $ans->answer['text'];
             $qo->fraction[$a_count] = $ans->fraction;
             $qo->feedback[$a_count] = $ans->feedback;
             ++$a_count;
         }
         return $qo;
     } else {
         return false;
     }
 }