Joseph Rézeau
Missatges enviats per Joseph Rézeau
By the way, what is the $extra parameter for?
Joseph
Yes it does! Thanks Tim. Does this mean that the function function writetext( $raw, $ilev=0, $short=true) {} in question/format/xml/format.php is no longer needed?
Joseph
Hi Howard,
I have started to play with the new import/export format for plugin question types in HEAD, with my REGEXP question type. So far I have implemented the export_to_xml method and am glad to report that it was quite easy to implement and that it does work fine! In file question/type/regexp/questiontype.php, inside class question_regexp_qtype extends default_questiontype {} I simply added the following:
function export_to_xml( $question, $format, $extra=null ) {
$expout = " <usehint>{$question->options->usehint}</usehint>\n ";
foreach($question->options->answers as $answer) {
$percent = 100 * $answer->fraction;
$expout .= " <answer fraction=\"$percent\">\n";
$expout .= $this->writetext( $answer->answer,3,false );
$expout .= " <feedback>\n";
$expout .= $this->writetext( $answer->feedback,4,false );
$expout .= " </feedback>\n";
$expout .= " </answer>\n";
}
return $expout;
}
I also needed to copy from question/format/xml/format.php function writetext( $raw, $ilev=0, $short=true) {} because it seems I cannot link to that file from my own question type, but it's only a few lines.
I will now work on the import_from_xml method, and test backup/restore and then report here. I hope the recent changes by Jamie Pratt to the question bank will not interfere too much with your import/export methods. If you want to take a look at my REGEXP question type you can download it (version 1.8 is OK for 1.9/HEAD) from the plugins download here.
Many thanks for making these methods available to "plugin question types".
Joseph
It would be a desirable goal to unify all those "survey, feedback, questionnaire, etc." modules into one unique serve-all purposes module, but in the meantime each of them serves its own purposes, so why not make life easier for moodlers by including them into core?
Joseph