示例#1
0
    public function test_import_multichoice_19() {
        $xml = '  <question type="multichoice">
    <name>
      <text>Multiple choice question</text>
    </name>
    <questiontext format="html">
      <text>Which are the even numbers?</text>
    </questiontext>
    <generalfeedback>
      <text>The even numbers are 2 and 4.</text>
    </generalfeedback>
    <defaultgrade>2</defaultgrade>
    <penalty>0.3333333</penalty>
    <hidden>0</hidden>
    <single>false</single>
    <shuffleanswers>false</shuffleanswers>
    <answernumbering>abc</answernumbering>
    <correctfeedback>
      <text><![CDATA[<p>Your answer is correct.</p>]]></text>
    </correctfeedback>
    <partiallycorrectfeedback>
      <text><![CDATA[<p>Your answer is partially correct.</p>]]></text>
    </partiallycorrectfeedback>
    <incorrectfeedback>
      <text><![CDATA[<p>Your answer is incorrect.</p>]]></text>
    </incorrectfeedback>
    <shownumcorrect/>
    <answer fraction="0">
      <text>1</text>
      <feedback>
        <text></text>
      </feedback>
    </answer>
    <answer fraction="100">
      <text>2</text>
      <feedback>
        <text></text>
      </feedback>
    </answer>
    <answer fraction="0">
      <text>3</text>
      <feedback>
        <text></text>
      </feedback>
    </answer>
    <answer fraction="100">
      <text>4</text>
      <feedback>
        <text></text>
      </feedback>
    </answer>
    <hint>
      <text>Hint 1.</text>
    </hint>
    <hint>
      <text>Hint 2.</text>
    </hint>
  </question>';
        $xmldata = xmlize($xml);

        $importer = new qformat_xml();
        $q = $importer->import_multichoice($xmldata['question']);

        $expectedq = new stdClass();
        $expectedq->qtype = 'multichoice';
        $expectedq->name = 'Multiple choice question';
        $expectedq->questiontext = 'Which are the even numbers?';
        $expectedq->questiontextformat = FORMAT_HTML;
        $expectedq->correctfeedback = array(
                'text'   => '<p>Your answer is correct.</p>',
                'format' => FORMAT_HTML);
        $expectedq->shownumcorrect = false;
        $expectedq->partiallycorrectfeedback = array(
                'text'   => '<p>Your answer is partially correct.</p>',
                'format' => FORMAT_HTML);
        $expectedq->shownumcorrect = true;
        $expectedq->incorrectfeedback = array(
                'text'   => '<p>Your answer is incorrect.</p>',
                'format' => FORMAT_HTML);
        $expectedq->generalfeedback = 'The even numbers are 2 and 4.';
        $expectedq->defaultmark = 2;
        $expectedq->length = 1;
        $expectedq->penalty = 0.3333333;
        $expectedq->shuffleanswers = 0;
        $expectedq->single = false;

        $expectedq->answer = array(
            array('text' => '1', 'format' => FORMAT_HTML),
            array('text' => '2', 'format' => FORMAT_HTML),
            array('text' => '3', 'format' => FORMAT_HTML),
            array('text' => '4', 'format' => FORMAT_HTML));
        $expectedq->fraction = array(0, 1, 0, 1);
        $expectedq->feedback = array(
            array('text' => '', 'format' => FORMAT_HTML),
            array('text' => '', 'format' => FORMAT_HTML),
            array('text' => '', 'format' => FORMAT_HTML),
            array('text' => '', 'format' => FORMAT_HTML));

        $expectedq->hint = array(
            array('text' => 'Hint 1.', 'format' => FORMAT_HTML),
            array('text' => 'Hint 2.', 'format' => FORMAT_HTML),
        );
        $expectedq->hintshownumcorrect = array(false, false);
        $expectedq->hintclearwrong = array(false, false);

        $this->assert(new question_check_specified_fields_expectation($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;
}