public function test_import_match_19() { $xml = ' <question type="matching"> <name> <text>Matching question</text> </name> <questiontext format="html"> <text>Match the upper and lower case letters.</text> </questiontext> <generalfeedback> <text>The answer is A -> a, B -> b and C -> c.</text> </generalfeedback> <defaultgrade>1</defaultgrade> <penalty>0.3333333</penalty> <hidden>0</hidden> <shuffleanswers>false</shuffleanswers> <correctfeedback> <text>Well done.</text> </correctfeedback> <partiallycorrectfeedback> <text>Not entirely.</text> </partiallycorrectfeedback> <incorrectfeedback> <text>Completely wrong!</text> </incorrectfeedback> <subquestion> <text>A</text> <answer> <text>a</text> </answer> </subquestion> <subquestion> <text>B</text> <answer> <text>b</text> </answer> </subquestion> <subquestion> <text>C</text> <answer> <text>c</text> </answer> </subquestion> <subquestion> <text></text> <answer> <text>d</text> </answer> </subquestion> <hint> <text>Hint 1</text> <shownumcorrect /> </hint> <hint> <text></text> <shownumcorrect /> <clearwrong /> </hint> </question>'; $xmldata = xmlize($xml); $importer = new qformat_xml(); $q = $importer->import_matching($xmldata['question']); $expectedq = new stdClass(); $expectedq->qtype = 'match'; $expectedq->name = 'Matching question'; $expectedq->questiontext = 'Match the upper and lower case letters.'; $expectedq->questiontextformat = FORMAT_HTML; $expectedq->correctfeedback = array('text' => 'Well done.', 'format' => FORMAT_MOODLE, 'files' => array()); $expectedq->partiallycorrectfeedback = array('text' => 'Not entirely.', 'format' => FORMAT_MOODLE, 'files' => array()); $expectedq->shownumcorrect = false; $expectedq->incorrectfeedback = array('text' => 'Completely wrong!', 'format' => FORMAT_MOODLE, 'files' => array()); $expectedq->generalfeedback = 'The answer is A -> a, B -> b and C -> c.'; $expectedq->generalfeedbackformat = FORMAT_MOODLE; $expectedq->defaultmark = 1; $expectedq->length = 1; $expectedq->penalty = 0.3333333; $expectedq->shuffleanswers = 0; $expectedq->subquestions = array( array('text' => 'A', 'format' => FORMAT_MOODLE, 'files' => array()), array('text' => 'B', 'format' => FORMAT_MOODLE, 'files' => array()), array('text' => 'C', 'format' => FORMAT_MOODLE, 'files' => array()), array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array())); $expectedq->subanswers = array('a', 'b', 'c', 'd'); $expectedq->hint = array( array('text' => 'Hint 1', 'format' => FORMAT_MOODLE, 'files' => array()), array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()), ); $expectedq->hintshownumcorrect = array(true, true); $expectedq->hintclearwrong = array(false, true); $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q); }
function wrsqz_import_from_xml($questionType, $dbType, &$data, &$question, &$format, &$extra) { if (isset($data['@']['type']) && $data['@']['type'] == $questionType . 'wiris') { $qfxml = new qformat_xml(); if ($questionType == 'essay') { $question = $qfxml->import_essay($data); }else if ($questionType == 'match') { $question = $qfxml->import_matching($data); }else if ($questionType == 'multichoice') { $question = $qfxml->import_multichoice($data); }else if ($questionType == 'truefalse') { $question = $qfxml->import_truefalse($data); }else if ($questionType == 'shortanswer') { $question = $qfxml->import_shortanswer($data); }else if ($questionType == 'multianswer') { $questiontext = $data['#']['wirisquestiontext'][0]['#']['text']; $container = new stdClass; $container->questiontext = $qfxml->import_text($questiontext); $question = wrsqz_qtype_multianswer_extract_question($container); $question->course = $qfxml->course; $question->generalfeedback = $qfxml->getpath($data, array('#','generalfeedback',0,'#','text',0,'#'), '', true ); $question->name = $qfxml->import_text( $data['#']['name'][0]['#']['text'] ); } unset($qfxml); $question->qtype = $questionType . 'wiris'; $program = wrsqz_mathmlDecode($format->getpath($data, array('#', 'wirisquestion', 0, '#'), 0)); $imported = wrsqz_importCASSession($program); if($imported===false) return false; $question->hiddenCASValue = $imported[0]; $translation = $imported[1]; if ($questionType == 'shortanswer') { mb_parse_str($format->getpath($data, array('#', 'wiriseditor', 0, '#'), 0), $eqoptionArray); $question->wirisEditor = (isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true') ? 'editor=true' : ''; $question->multipleAnswers = (isset($eqoptionArray['multipleAnswers']) && $eqoptionArray['multipleAnswers'] == 'true') ? 'multipleAnswers=true' : ''; $question->wirisCASForComputations = (isset($eqoptionArray['wirisCASForComputations']) && $eqoptionArray['wirisCASForComputations'] == 'true') ? 'wirisCASForComputations=true' : ''; if(isset($eqoptionArray['testFunctionName'])){ foreach ($eqoptionArray['testFunctionName'] as $index => $functionName){ if(!empty($functionName)){ $question->testFunctionName[$index]=$functionName; } } } }else if ($questionType == 'multichoice') { $question->gradeOverride = explode(';', $format->getpath($data, array('#', 'wirisoverrideanswer', 0, '#'), 0)); }else if ($questionType == 'truefalse') { $question->wirisAnswer = $format->getpath($data, array('#', 'wirisoverrideanswer', 0, '#'), 0); }else if ($questionType == 'multianswer'){ //mb_parse_str($format->getpath($data, array('#', 'wiriseditor', 0, '#'), 0), $eqoptionArray); //$question->wirisEditor = (isset($eqoptionArray['editor']) && $eqoptionArray['editor'] == 'true') ? 'editor=true' : ''; } $options = $format->getpath($data, array('#', 'wirisoptions',0,'#'), array()); $question->wirisCASForComputations = $format->getpath($options, array('wirisCASForComputations',0,'#'),0); //TODO: translate cas if needed. $question->hiddenInitialCASValue = wrsqz_mathmlDecode($format->getpath($options, array('hiddenInitialCASValue',0,'#'),0)); if(!empty($translation)){ wrsqz_replaceVarReferencesInFlatQuestion($questionType, $question, $translation); } return $question; } return false; }