Question Type Importing/Exporting

Question Type Importing/Exporting

by Matthew Leventi -
Number of replies: 8
Is there any way to include code that will allow the import and export of my question type to Moodle XML format without having to modify the format/xml/format.php file. Can it be done within my question type folder?

This is for the WeBWorK question type I am developing (screenshot below). It can be found by CVS checkout:

cvs -d :pserver:anoncvs@cvs.webwork.rochester.edu:/webwork/cvs/system co wwmoodle/wwquestion

Thanks,
Attachment webwork.gif
Average of ratings: -
In reply to Matthew Leventi

Re: Question Type Importing/Exporting

by Jean-Michel Védrine -
Hello Matthew,
Unfortunely not, this is bug MDL-2727 and it is not yet resolved.
Unless you need import/export very quickly I suggest you wait until a solution is found, because modifying core files is a real pain at each Moodle upgrade.
Now that a lot of new questiontypes are floating around maybe things will evolve.
In reply to Matthew Leventi

Re: Question Type Importing/Exporting

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This is clearly something we need to get sorted - for 1.9 I guess. We should kick around some ideas in the Developer docs.

I'll have a think (again) about it and write something down. I know Pierre had some good ideas, but he has been strangely quiet of late.

I think the gist of it will be to add addition methods into the questiontype class that the XML import export format checks for to handle non-core questions.
In reply to Howard Miller

Re: Question Type Importing/Exporting

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Howard, if it helps, feel free to skype me today to talk about it.

But you are right, the basic idea has to be that when a particular export format encounters a question type it does not understand, it looks in the question type class to see if the question type implements expor to that format (probably using a call to

method_exists($QTYPE[$question->type], 'export_' . $format . '_format')

) if if that method is there, it calls it. The difficult thing is to do this in a way that still lets the export format class handle the standard question fields, so that you don't have to duplicate code in all of the question types.


You would then do something similar for import.


While it would be nice to come up with a general scheme that works for all question types, probably the details (that is, how you combine the custom code in each question type with the generic code in format.php) will be slightly different for each format, in which case, I would be happy if we just get this working for XML and Gift format.


I think we only use this new mechanism for third-party question types. For the core question types, we continue to leave all the code in the format.php files.


Does all that make sense?
In reply to Tim Hunt

Re: Question Type Importing/Exporting

by Matthew Leventi -
What you describe would be a very nice enhancement. For now I have solved part of my problem by making a custom importer for WeBWorK questions. Hence I can load them in by the truck load.

Yet I still need the ability to export and import with Moodle XML so for now I am going to take jean-michel suggestion and hardcode in some changes so moodle thinks my question type is standard. I would be willing to make the generic modification that you suggest just to hurry things along.

Matt


In reply to Tim Hunt

Re: Question Type Importing/Exporting

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Tim,

I broadly agree, although I don't quite follow "do this in a way that still lets the export format class handle the standard question fields, so that you don't have to duplicate code in all of the question types."

I was really just thinking about the XML format, but constructing the methods in such a way that it *could* work for any format (in particular, the Blackboard format is sufficiently popular that I think it would be worth making it work for that).

One problem that applies to import is that question type names differ so a questiontype would have to have some way of "broadcasting" the permitted names aliases so the import format knew which questiontype to actually call.

I'll see if I can bash something out in the docs and we can go from there.

I think we got banned from using Skype here sad
In reply to Howard Miller

Re: Question Type Importing/Exporting

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Getting a concrete proposal on the wiki is definitely the place to start. Then we have something to discuss.

Certainly, it is find if it only works for Moodle XML format in the first instance, as long as it is possible to to extend it to other formats in future.

Good point about type names.

What I mean about standard fields was that when you import from Moodle XML format, you have to read the question text and various other things in the same way for all question types, and then read the question-type specific data. When we are delegating the import of a custom question type to the question type class, it would be nice if the code for reading the standard fields did not have to be duplicated in the custom question type.


What is it with bureaucrats and Skype? Here we are permitted to use it, but only after filling in a form.
In reply to Tim Hunt

Re: Question Type Importing/Exporting

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Oh yes - I see what you mean. With XML it is dead easy as you end up with either a question object or a (xmlized) xml fragment that you don't know what to do with. I think only one function would need kicked out to (say) questionlib. Gift is a bit trickier but I think we can work around that.

Off to the docs......
In reply to Howard Miller

Re: Question Type Importing/Exporting

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Enabling question export/import for third-party question types is something I've been expecting to happen for quite some time now... It would be great if Howard, Tim, Jean-Michel, etc. would get their great programming skills togethercool and come up with a viable solution. Personally I think we should aim at XML import/export format first of all. But maybe this is because it is my favorite format and I never use GIFT or any other format myself.
Thanks in advance, it would be great if this was available for 1.9 (and I am of course willing to test it).
Joseph