Random question by TAGS. Qtype only or quiz core hack?

Random question by TAGS. Qtype only or quiz core hack?

by Ray Morris -
Number of replies: 6

Just as one can currently select a random question from a given category, I'm looking at adding a random question from a given set of tags.  I'd like to ask if that might be useful to others, and for some thoughts on implementation.

 As an example, suppose you had a quiz about Moodle development. One of the questions is "which directory contains question types?"  That question might be tagged with these tags:

Directory/folder structure  Quiz  Extending Moodle  

 

You could then add a random Extending Moodle question and that one might be chosen.  That question would also fill a requirement for a random Directory / Folder structure question. Does that sound useful to anyone?

I see that "random" is a question type in question/type/random/ , so  that suggests that I should be able to create a very similar type called question/type/randombytag/ .  That would be great if it could be done as a question type, like random is, because that would allow the new feature to be self-contained, without affecting any code from mainline. Hacking Quiz core has a number of challenges that make it expensive in terms of time and effort, and new features may not be accepted into mainline.  

On the other hand, within mod/quiz/ I see addrandom.php and addrandomform.php.  Drats!  Before I spend a couple of hours groking the code in both to see how they interact, I figured I'd ask here if someone already familiar with the how that works can say whether or not you'd think it could be done purely as a new qtype.

 

PS - allowing questions to be in multiple categories might be a cleaner way to accomplish the same thing, but that would definitely involve significant changes to the question bank and to Quiz, changes which I'm not currently able to steer to completion and acceptance.

 

Average of ratings: -
In reply to Ray Morris

Re: Random question by TAGS. Qtype only or quiz core hack?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There are two issues here:

1. the code that executes when a quiz attempt starts. This is in mod/quiz/startattempt.php. Look for the comment "// Starting a normal, new, quiz attempt."

Unfortunately, this currenty hard codes if ($questiondata->qtype == 'random'). However, if you are prepared to change this bit of code, adding new functionality here is easy.

2. Providing a UI to let teachers set up what they want to happen. This is the code in mod/quiz/edit.php and mod/quiz/editlib.php. Changing this is much more work. Again, it is not currently plug-in-able.

Allowing questions in multiple categories is a really bad idea. That way lies maintenance insanity. Using tags is the right way to label questions for what you want.

I do not think that the way random questions currently work is the right way to implement this, so don't copy that model when implemented random selection of questions by tag.

We (the OU) are planning to work on the quiz edit page in the second half of this year, in order to add some other features that we want. I have not got my head round that yet. I will post more fully in this forum about what we propose before we start doing it. Anyway, as part of that work, it would be good to make quiz editing, and quiz question selection, more plug-in-able. I will bear that in mind, but I don't know how much it will be possible to do.

So, short answer: If you want to do this now, you almost certanly can, but only by hacking core quiz code.

In reply to Tim Hunt

Re: Random question by TAGS. Qtype only or quiz core hack?

by Ray Morris -

Thank you very much for your comments, Tim.  I was hoping you would reply.

 

I do not think that the way random questions currently work is the right way to implement this,

> so don't copy that model when implemented random selection of questions by tag.

 

Are you planning on re-doing any of that as part of what OU is doing?  If so, we may wish to coordinate efforts, as I may need to start before you finish.

I'd really like to find the simplest way to achieve the goal, which is to a) have questions tat match multiple tags/categories/labels and b) require a question which meets some combination of tags/categories/labels.

 

 

In reply to Ray Morris

Re: Random question by TAGS. Qtype only or quiz core hack?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I would like to change this as part of our changes, but I don't know if we will have time.

In reply to Tim Hunt

Re: Random question by TAGS. Qtype only or quiz core hack?

by Ray Morris -

I may be able to put in some of the coding time if you come up with a plan that works.

 

In reply to Ray Morris

Re: Random question by TAGS. Qtype only or quiz core hack?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Right. The problem is I don't have a plan yet. I suppose it would be good to come up with a plan sooner rather than later. Hmm ...

In reply to Ray Morris

Re: Random question by TAGS. Qtype only or quiz core hack?

by Ewout ter Haar -

I did a proof of concept implementation of this. The idea is to permit tags to be associated with question of type random. If the random question has tags, the questions will be chosen (randomly, off course) from the intersection of the set of questions that have those tags, in addition to those that belong the category.

I hoped everything could be implemented in question/type/random/ , but that turned out not to be case (in the end I had to make edits to mod/quiz/addrandom.php, mod/quiz/addrandomform.php, mod/quiz/editlib.php, question/question.php, question/type/random /edit_random_form.php and question/type/random/questiontype.php )

I am a amateur coder, there are no tests, and the user interface is lacking (no easy way to see which candidate questions belong to the random question). But it works.

I don't know, maybe the idea of simply extending the random question type to have tags may inspire somebody to a professional coding job that could be submitted for incorporation into Moodle.

For those interested, see http://git.atp.usp.br/moodle.git/commitdiff/60e1f50565f07d8ea658fadf7dc30a6e6a7539ee and http://git.atp.usp.br/moodle.git/commitdiff/9deff854e3eb5dcbc78c2cfc5924bec1be067f2c