Developing question type with multiple answers

Developing question type with multiple answers

by Richard Vialls -
Number of replies: 3

Hi,

I'm trying to develop a question type that has multiple answers. The specific application is that I need learners to fill in a series of labels on a diagram (rather than choose them from an existing list) and the answers then need to be manually graded. I've created a question renderer that displays the image and text areas for the learner to put answers in. What I can't seem to work out is how to collect those answers and store them in the question database. I don't really mind whether each answer is stored as a separate question_attempt_step_data, or whether I combine them as a single record in a comma separated list or similar. But I need to work out what code I need to develop to collect the answer and create the database record.

Does anyone have any suggestions for example question types that would give me hints as to how to do this? Or can someone give me a quick pointer to which bits of code I need to implement in my question type?

Any help would be greatly appreciated

Average of ratings: -
In reply to Richard Vialls

Re: Developing question type with multiple answers

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Possibly the secret thing you are missing is the get_expected_data method on the qtype_..._question class.

Once everything is working, you should not need to worry about storing the data yourself. The core question system should handle that for you. You just need to tell it the names of the inputs that it should expect.

It is definitely a good idea to look at what some other question types do. qtype_match might be the simplest of the core question types which has multiple inputs.

It is not the most helpful documentation page ever, but if you have not already found it, https://docs.moodle.org/dev/Question_types. I also wonder if it is helpful for you to read https://docs.moodle.org/dev/Using_the_question_engine_from_module, to see how the API works from the other sides (code that uses questions, rather than code that implements question type plugins.)
Average of ratings: Useful (1)
In reply to Richard Vialls

Re: Developing question type with multiple answers

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
In reply to Marcus Green

Re: Developing question type with multiple answers

by Richard Vialls -
Thank you both, those were really helpful posts and my plugin now works smile
Average of ratings: Useful (2)