Esempio n. 1
0
 /**
  * Provide export functionality for xml format
  * @param question object the question object
  * @param format object the format object so that helper methods can be used
  * @param extra mixed any additional format specific data that may be passed by the format (see format code for info)
  * @return string the data to append to the output buffer or false if error
  */
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $expout = '';
     $fs = get_file_storage();
     $contextid = $question->contextid;
     $expout .= "    <shuffleanswers>" . $format->get_single($question->options->shuffleanswers) . "</shuffleanswers>\n";
     $textformat = $format->get_format($question->options->correctfeedbackformat);
     $files = $fs->get_area_files($contextid, 'question', 'correctfeedback', $question->id);
     $expout .= "    <correctfeedback format=\"{$textformat}\">\n" . '      ' . $format->writetext($question->options->correctfeedback);
     $expout .= $format->write_files($files);
     $expout .= "    </correctfeedback>\n";
     $textformat = $format->get_format($question->options->incorrectfeedbackformat);
     $files = $fs->get_area_files($contextid, 'question', 'incorrectfeedback', $question->id);
     $expout .= "    <incorrectfeedback format=\"{$textformat}\">\n" . '      ' . $format->writetext($question->options->incorrectfeedback);
     $expout .= $format->write_files($files);
     $expout .= "    </incorrectfeedback>\n";
     if (!empty($question->options->shownumcorrect)) {
         $expout .= "    <shownumcorrect/>\n";
     }
     $expout .= "    <answernumbering>{$question->options->answernumbering}</answernumbering>\n";
     $expout .= $format->write_answers($question->options->answers);
     return $expout;
 }
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $output = '';
     $output .= '    <shuffleanswers>' . $question->options->shuffleanswers . "</shuffleanswers>\n";
     $output .= $format->write_combined_feedback($question->options, $question->id, $question->contextid);
     foreach ($question->options->answers as $answer) {
         $output .= "    <selectoption>\n";
         $output .= $format->writetext($answer->answer, 3);
         $output .= "      <group>{$answer->feedback}</group>\n";
         $output .= "    </selectoption>\n";
     }
     return $output;
 }
Esempio n. 3
0
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $fs = get_file_storage();
     $contextid = $question->contextid;
     $output = '';
     if ($question->options->shuffleanswers) {
         $output .= "    <shuffleanswers/>\n";
     }
     $output .= $format->write_combined_feedback($question->options, $question->id, $question->contextid);
     $files = $fs->get_area_files($contextid, 'qtype_ddimageortext', 'bgimage', $question->id);
     $output .= "    " . $this->write_files($files, 2) . "\n";
     foreach ($question->options->drags as $drag) {
         $files = $fs->get_area_files($contextid, 'qtype_ddimageortext', 'dragimage', $drag->id);
         $output .= "    <drag>\n";
         $output .= "      <no>{$drag->no}</no>\n";
         $output .= $format->writetext($drag->label, 3) . "\n";
         $output .= "      <draggroup>{$drag->draggroup}</draggroup>\n";
         if ($drag->infinite) {
             $output .= "      <infinite/>\n";
         }
         $output .= $this->write_files($files, 3);
         $output .= "    </drag>\n";
     }
     foreach ($question->options->drops as $drop) {
         $output .= "    <drop>\n";
         $output .= $format->writetext($drop->label, 3);
         $output .= "      <no>{$drop->no}</no>\n";
         $output .= "      <choice>{$drop->choice}</choice>\n";
         $output .= "      <xleft>{$drop->xleft}</xleft>\n";
         $output .= "      <ytop>{$drop->ytop}</ytop>\n";
         $output .= "    </drop>\n";
     }
     return $output;
 }
Esempio n. 4
0
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $output = '';
     $output .= '    <shuffleanswers>' . $question->options->shuffleanswers . "</shuffleanswers>\n";
     $output .= $format->write_combined_feedback($question->options, $question->id, $question->contextid);
     foreach ($question->options->answers as $answer) {
         $options = unserialize($answer->feedback);
         $output .= "    <dragbox>\n";
         $output .= $format->writetext($answer->answer, 3);
         $output .= "      <group>{$options->draggroup}</group>\n";
         if ($options->infinite) {
             $output .= "      <infinite/>\n";
         }
         $output .= "    </dragbox>\n";
     }
     return $output;
 }
 /**
  * export_to_xml
  *
  * @param stdClass    $question
  * @param qformat_xml $format
  * @param string      $extra (optional, default=null)
  * @todo Finish documenting this function
  */
 function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     list($count, $type) = $this->extract_count_and_type($question);
     $output = '';
     $output .= "    <selecttype>{$type}</selecttype>\n";
     $output .= "    <selectcount>{$count}</selectcount>\n";
     foreach ($question->options->answers as $answer) {
         $output .= '    <answer fraction="' . $answer->fraction . '" ' . $format->format($answer->answerformat) . ">\n";
         $output .= $format->writetext($answer->answer, 3);
         if ($feedback = trim($answer->feedback)) {
             // usually there is no feedback
             $output .= '      <feedback ' . $format->format($answer->feedbackformat) . ">\n";
             $output .= $format->writetext($answer->feedback, 4);
             $output .= "      </feedback>\n";
         }
         $output .= "    </answer>\n";
     }
     return $output;
 }
 public function export_to_xml($questiondata, qformat_xml $format, $notused = null)
 {
     $contextid = $questiondata->contextid;
     if (!isset($questiondata->testcases)) {
         // The method get_question_options does not load the testcases, because
         // they are not normally needed, so we have to load them manually here.
         // However, we only do it conditionally, so that the unit tests can
         // just pass the data in.
         $questiondata->testcases = $this->load_question_tests($questiondata->id);
     }
     $output = '';
     $options = $questiondata->options;
     $output .= "    <questionvariables>\n";
     $output .= "      " . $format->writetext($options->questionvariables, 0);
     $output .= "    </questionvariables>\n";
     $output .= $this->export_xml_text($format, 'specificfeedback', $options->specificfeedback, $options->specificfeedbackformat, $contextid, 'specificfeedback', $questiondata->id);
     $output .= "    <questionnote>\n";
     $output .= "      " . $format->writetext($options->questionnote, 0);
     $output .= "    </questionnote>\n";
     $output .= "    <questionsimplify>{$options->questionsimplify}</questionsimplify>\n";
     $output .= "    <assumepositive>{$options->assumepositive}</assumepositive>\n";
     $output .= $this->export_xml_text($format, 'prtcorrect', $options->prtcorrect, $options->prtcorrectformat, $contextid, 'prtcorrect', $questiondata->id);
     $output .= $this->export_xml_text($format, 'prtpartiallycorrect', $options->prtpartiallycorrect, $options->prtpartiallycorrectformat, $contextid, 'prtpartiallycorrect', $questiondata->id);
     $output .= $this->export_xml_text($format, 'prtincorrect', $options->prtincorrect, $options->prtincorrectformat, $contextid, 'prtincorrect', $questiondata->id);
     $output .= "    <multiplicationsign>{$options->multiplicationsign}</multiplicationsign>\n";
     $output .= "    <sqrtsign>{$options->sqrtsign}</sqrtsign>\n";
     $output .= "    <complexno>{$options->complexno}</complexno>\n";
     $output .= "    <inversetrig>{$options->inversetrig}</inversetrig>\n";
     $output .= "    <matrixparens>{$options->matrixparens}</matrixparens>\n";
     $output .= "    <variantsselectionseed>{$format->xml_escape($options->variantsselectionseed)}</variantsselectionseed>\n";
     foreach ($questiondata->inputs as $input) {
         $output .= "    <input>\n";
         $output .= "      <name>{$input->name}</name>\n";
         $output .= "      <type>{$input->type}</type>\n";
         $output .= "      <tans>{$format->xml_escape($input->tans)}</tans>\n";
         $output .= "      <boxsize>{$input->boxsize}</boxsize>\n";
         $output .= "      <strictsyntax>{$input->strictsyntax}</strictsyntax>\n";
         $output .= "      <insertstars>{$input->insertstars}</insertstars>\n";
         $output .= "      <syntaxhint>{$format->xml_escape($input->syntaxhint)}</syntaxhint>\n";
         $output .= "      <forbidwords>{$format->xml_escape($input->forbidwords)}</forbidwords>\n";
         $output .= "      <allowwords>{$format->xml_escape($input->allowwords)}</allowwords>\n";
         $output .= "      <forbidfloat>{$input->forbidfloat}</forbidfloat>\n";
         $output .= "      <requirelowestterms>{$input->requirelowestterms}</requirelowestterms>\n";
         $output .= "      <checkanswertype>{$input->checkanswertype}</checkanswertype>\n";
         $output .= "      <mustverify>{$input->mustverify}</mustverify>\n";
         $output .= "      <showvalidation>{$input->showvalidation}</showvalidation>\n";
         $output .= "      <options>{$input->options}</options>\n";
         $output .= "    </input>\n";
     }
     foreach ($questiondata->prts as $prt) {
         $output .= "    <prt>\n";
         $output .= "      <name>{$prt->name}</name>\n";
         $output .= "      <value>{$prt->value}</value>\n";
         $output .= "      <autosimplify>{$prt->autosimplify}</autosimplify>\n";
         $output .= "      <feedbackvariables>\n";
         $output .= "        " . $format->writetext($prt->feedbackvariables, 0);
         $output .= "      </feedbackvariables>\n";
         foreach ($prt->nodes as $node) {
             $output .= "      <node>\n";
             $output .= "        <name>{$node->nodename}</name>\n";
             $output .= "        <answertest>{$node->answertest}</answertest>\n";
             $output .= "        <sans>{$format->xml_escape($node->sans)}</sans>\n";
             $output .= "        <tans>{$format->xml_escape($node->tans)}</tans>\n";
             $output .= "        <testoptions>{$format->xml_escape($node->testoptions)}</testoptions>\n";
             $output .= "        <quiet>{$node->quiet}</quiet>\n";
             $output .= "        <truescoremode>{$node->truescoremode}</truescoremode>\n";
             $output .= "        <truescore>{$node->truescore}</truescore>\n";
             $output .= "        <truepenalty>{$node->truepenalty}</truepenalty>\n";
             $output .= "        <truenextnode>{$node->truenextnode}</truenextnode>\n";
             $output .= "        <trueanswernote>{$format->xml_escape($node->trueanswernote)}</trueanswernote>\n";
             $output .= $this->export_xml_text($format, 'truefeedback', $node->truefeedback, $node->truefeedbackformat, $contextid, 'prtnodetruefeedback', $node->id, '        ');
             $output .= "        <falsescoremode>{$node->falsescoremode}</falsescoremode>\n";
             $output .= "        <falsescore>{$node->falsescore}</falsescore>\n";
             $output .= "        <falsepenalty>{$node->falsepenalty}</falsepenalty>\n";
             $output .= "        <falsenextnode>{$node->falsenextnode}</falsenextnode>\n";
             $output .= "        <falseanswernote>{$format->xml_escape($node->falseanswernote)}</falseanswernote>\n";
             $output .= $this->export_xml_text($format, 'falsefeedback', $node->falsefeedback, $node->falsefeedbackformat, $contextid, 'prtnodefalsefeedback', $node->id, '        ');
             $output .= "      </node>\n";
         }
         $output .= "    </prt>\n";
     }
     foreach ($questiondata->deployedseeds as $deployedseed) {
         $output .= "    <deployedseed>{$deployedseed}</deployedseed>\n";
     }
     foreach ($questiondata->testcases as $testcase => $qtest) {
         $output .= "    <qtest>\n";
         $output .= "      <testcase>{$testcase}</testcase>\n";
         foreach ($qtest->inputs as $name => $value) {
             $output .= "      <testinput>\n";
             $output .= "        <name>{$name}</name>\n";
             $output .= "        <value>{$format->xml_escape($value)}</value>\n";
             $output .= "      </testinput>\n";
         }
         foreach ($qtest->expectedresults as $name => $expected) {
             $output .= "      <expected>\n";
             $output .= "        <name>{$name}</name>\n";
             $output .= "        <expectedscore>{$format->xml_escape($expected->score)}</expectedscore>\n";
             $output .= "        <expectedpenalty>{$format->xml_escape($expected->penalty)}</expectedpenalty>\n";
             $output .= "        <expectedanswernote>{$format->xml_escape($expected->answernotes[0])}</expectedanswernote>\n";
             $output .= "      </expected>\n";
         }
         $output .= "    </qtest>\n";
     }
     return $output;
 }
 /**
  * Provide export functionality for xml format
  * @param question object the question object
  * @param format object the format object so that helper methods can be used
  * @param extra mixed any additional format specific data that may be passed by the format (see format code for info)
  * @return string the data to append to the output buffer or false if error
  */
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $expout = '';
     $fs = get_file_storage();
     $contextid = $question->contextid;
     $expout .= $format->write_combined_feedback($question->options, $question->id, $question->contextid);
     foreach ($question->options->subquestions as $subquestion) {
         $files = $fs->get_area_files($contextid, 'qtype_ddmatch', 'subquestion', $subquestion->id);
         $textformat = $format->get_format($subquestion->questiontextformat);
         $expout .= "    <subquestion format=\"{$textformat}\">\n";
         $expout .= '      ' . $format->writetext($subquestion->questiontext);
         $expout .= '      ' . $format->write_files($files, 2);
         $expout .= "       <answer format=\"{$textformat}\">\n";
         $expout .= '      ' . $format->writetext($subquestion->answertext);
         $files = $fs->get_area_files($contextid, 'qtype_ddmatch', 'subanswer', $subquestion->id);
         $expout .= '      ' . $format->write_files($files, 2);
         $expout .= "       </answer>\n";
         $expout .= "    </subquestion>\n";
     }
     return $expout;
 }
Esempio n. 8
0
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $fs = get_file_storage();
     $contextid = $question->contextid;
     $output = '';
     if ($question->options->shuffleanswers) {
         $output .= "    <shuffleanswers/>\n";
     }
     if ($question->options->showmisplaced) {
         $output .= "    <showmisplaced/>\n";
     }
     $output .= $format->write_combined_feedback($question->options, $question->id, $question->contextid);
     $files = $fs->get_area_files($contextid, 'qtype_ddmarker', 'bgimage', $question->id);
     $output .= "    " . $this->write_files($files, 2) . "\n";
     foreach ($question->options->drags as $drag) {
         $files = $fs->get_area_files($contextid, 'qtype_ddmarker', 'dragimage', $drag->id);
         $output .= "    <drag>\n";
         $output .= "      <no>{$drag->no}</no>\n";
         $output .= $format->writetext($drag->label, 3);
         if ($drag->infinite) {
             $output .= "      <infinite/>\n";
         }
         $output .= "      <noofdrags>{$drag->noofdrags}</noofdrags>\n";
         $output .= "    </drag>\n";
     }
     foreach ($question->options->drops as $drop) {
         $output .= "    <drop>\n";
         $output .= "      <no>{$drop->no}</no>\n";
         $output .= "      <shape>{$drop->shape}</shape>\n";
         $output .= "      <coords>{$drop->coords}</coords>\n";
         $output .= "      <choice>{$drop->choice}</choice>\n";
         $output .= "    </drop>\n";
     }
     return $output;
 }
Esempio n. 9
0
 public function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     //get file storage
     $fs = get_file_storage();
     $expout = "";
     $expout .= "    <responseformat>" . $question->options->responseformat . "</responseformat>\n";
     $expout .= "    <responsefieldlines>" . $question->options->responsefieldlines . "</responsefieldlines>\n";
     $expout .= "    <attachments>" . $question->options->attachments . "</attachments>\n";
     $expout .= "    <graderinfo " . $format->format($question->options->graderinfoformat) . ">\n";
     $expout .= $format->writetext($question->options->graderinfo, 3);
     $expout .= $format->write_files($fs->get_area_files($question->contextid, 'qtype_poodllrecording', 'graderinfo', $question->id));
     $expout .= "    </graderinfo>\n";
     $expout .= "    <backimage>" . $format->write_files($fs->get_area_files($question->contextid, 'qtype_poodllrecording', 'backimage', $question->id)) . "</backimage>\n";
     $expout .= "    <boardsize>" . $question->options->boardsize . "</boardsize>\n";
     $expout .= "    <timelimit>" . $question->options->timelimit . "</timelimit>\n";
     return $expout;
 }
function wrsqz_export_to_xml($questionType, $dbType, &$question, &$format, &$extra) {
	$objProblem = get_record('question_' . $dbType, 'question', $question->id);

	$expout = '';
	$qfxml = new qformat_xml();
	
	if ($questionType == 'essay') {
		foreach ($question->options->answers as $answer) {
			$expout .= '<answer fraction="' . (100 * $answer->fraction) . '"><feedback>' . $qfxml->writetext($answer->feedback) . '</feedback></answer>';
		}
	}
	else if ($questionType == 'match') {
		foreach ($question->options->subquestions as $subquestion) {
			$expout .= '<subquestion>' . $qfxml->writetext($subquestion->questiontext) . '<answer>' . $qfxml->writetext($subquestion->answertext) . '</answer></subquestion>';
		}
	}
	else if ($questionType == 'multichoice') {
		$expout .= '<single>' . $qfxml->get_single($question->options->single) . '</single>';
		$expout .= '<shuffleanswers>' . $qfxml->get_single($question->options->shuffleanswers) . '</shuffleanswers>';
		$expout .= '<correctfeedback>' . $qfxml->writetext($question->options->correctfeedback, 3) . '</correctfeedback>';
		$expout .= '<partiallycorrectfeedback>' . $qfxml->writetext($question->options->partiallycorrectfeedback, 3) . '</partiallycorrectfeedback>';
		$expout .= '<incorrectfeedback>' . $qfxml->writetext($question->options->incorrectfeedback, 3) . '</incorrectfeedback>';
		$expout .= '<answernumbering>' . $question->options->answernumbering . '</answernumbering>';
		
		foreach ($question->options->answers as $answer) {
			$expout .= '<answer fraction="' . ($answer->fraction * 100) . '">' . $qfxml->writetext( $answer->answer,4,false ) . '<feedback>' . $qfxml->writetext($answer->feedback, 5, false) . '</feedback></answer>';
		}
	}
	else if ($questionType == 'shortanswer') {
		$expout .= '<usecase>' . $question->options->usecase . '</usecase>';
		
		foreach ($question->options->answers as $answer) {
			$expout .= '<answer fraction="' . (100 * $answer->fraction) . '">' . $qfxml->writetext($answer->answer, 3, false) . '<feedback>' . $qfxml->writetext($answer->feedback, 4, false) . '</feedback></answer>';
		}
	}
	else if ($questionType == 'truefalse') {
		foreach ($question->options->answers as $answer) {
			if ($answer->id == $question->options->trueanswer) {
				$answertext = 'true';
			}
			else {
				$answertext = 'false';
			}
			
			$expout .= '<answer fraction="' . round($answer->fraction * 100) . '"><text>' . $answertext . '</text><feedback>' . $qfxml->writetext($answer->feedback) . '</feedback></answer>';
		}
	}else if ($questionType == 'multianswer'){

        $questiontext = $question->questiontext;
        $a_count=1;
        foreach($question->options->questions as $child) {
           $pattern = addslashes("{#".$a_count."}");
           $replace = $child->questiontext;
           $questiontext= str_replace($pattern, $replace, $questiontext);
           $a_count++;
        }
        $expout .= '<wirisquestiontext>'.$qfxml->writetext($questiontext).'</wirisquestiontext>';

    }
	
	$programParsed = wrsqz_mathmlEncode($objProblem->program);
	$expout .= '<wirisquestion>' . $programParsed . '</wirisquestion>';

	if ($questionType == 'multichoice') {
		$expout .= '<wirisoverrideanswer>' . $question->options->wiris->override . '</wirisoverrideanswer>';
	}else if ($questionType == 'truefalse') {
		if (empty($question->options->wiris->override)) {
			$expout .= '<wirisoverrideanswer></wirisoverrideanswer>';
		}
		else {
			$values = explode(';', $question->options->wiris->override);
			$expout .= '<wirisoverrideanswer>' . $values[0] . '</wirisoverrideanswer>';
		}
	}else if ($questionType == 'shortanswer') {
		$expout .= '<wiriseditor>' . htmlentities($question->options->wiris->eqoption, ENT_QUOTES, 'UTF-8') . '</wiriseditor>';
	}else if ($questionType == 'multianswer') {
        //$expout .= '<wiriseditor>' . htmlentities($question->options->wiris->eqoption, ENT_QUOTES, 'UTF-8') . '</wiriseditor>';
  }
  $options = $question->options->wiris->options;
  $expout .= '<wirisoptions>';
  foreach($options as $key=>$value){
    if($key == 'hiddenInitialCASValue') $value = wrsqz_mathmlEncode($value);
    $expout .= '<'.$key.'>'.print_r($value, true).'</'.$key.'>';
  }
  $expout .=   '</wirisoptions>';
	return $expout;
}
Esempio n. 11
0
 function export_to_xml($question, qformat_xml $format, $extra = null)
 {
     $extraquestionfields = $this->extra_question_fields();
     if (!is_array($extraquestionfields)) {
         return false;
     }
     //omit table name (question)
     array_shift($extraquestionfields);
     $expout = '';
     foreach ($extraquestionfields as $field) {
         $exportedvalue = $question->options->{$field};
         if (!empty($exportedvalue) && htmlspecialchars($exportedvalue) != $exportedvalue) {
             $exportedvalue = '<![CDATA[' . $exportedvalue . ']]>';
         }
         $expout .= "    <{$field}>{$exportedvalue}</{$field}>\n";
     }
     foreach ($question->options->answers as $answer) {
         $percent = 100 * $answer->fraction;
         $expout .= "    <answer fraction=\"{$percent}\">\n";
         $expout .= $format->writetext($answer->answer, 3, false);
         $expout .= "      <feedback format=\"html\">\n";
         $expout .= $format->writetext($answer->feedback, 4, false);
         $expout .= "      </feedback>\n";
         $expout .= "    </answer>\n";
     }
     return $expout;
 }