A different twist on quizzes

Re: A different twist on quizzes

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

OK, so what is being asked for here is basically Item 3 from this old proposal: https://moodle.org/mod/forum/discuss.php?d=231180. Everything else there has now been done, but that one has not been. It is still a good idea. It is just really hard to work out how to fit it into the Edit quiz page.

So, in the mean time, is there anything that could be done?

Well, if you are using certain question types, you can fake it. For example using the core calculated question type, you can create a quiz like this using 'Shared datasets'. That is what the shared datasets feature is for. And, for other questoin types like STACK, and the Variable numeric family, you can do similarly syncronised randomisation, using the 'Random group' option when you create/edit the question.

But, what if you want to use other question types? Well, if you are prepared to hack core code, you probably only need to change one function (quiz_start_new_attempt in mod/quiz/locallib.php). However, it is best to avoid core hacks.

OK, so what could one do with a plugin? Well, the way the quiz works is, when a student goes there, it checks to see if they already have a attempt. If so, then it shows a Continue attempt button. Otherwise, it shows a start attempt button. So, rather than waiting for the student to click 'Start attempt' and then have Moodle create the quiz attempt for the student using the standard code, you could create a plugin that makes a quiz attempt for each use ahead of time, using whatever logic you like for which questions to include. The only down-side is that students will see a 'Continue attempt' button when they are expecting to see a 'Start attempt button'.

Ah! but there is a really evil trick to avoid even that. When the user clicks 'Start attempt', this is what happens:

  1. Create the quiz attempt object.
  2. Create an associate 'question usage'
  3. Add all the questions to the usage (using the normal randomisation rules if that is how things are set up).
  4. Fire an 'attempt_started' event, to notify other parts of the code.
  5. Save everything in the database.
  6. Redirect the student to the first page of the quiz attempt.

The process could be subverted by making a plugin that subscribes to the attempt_started. The plugin could:

  1. Delete the question usage created in steps 2 & 3 above.
  2. Make an alternative usage, adding quetions according to its own logic.
  3. Update the quiz attempt to point to this alternate usage.
  4. Then, allow the normal process to continue.

This is a bit inefficient (first Moodle makes a usage, then we throw it away and make a different one). However, it would be completely invisible to the user, and as far as I can see, it could work. Is anyone crazy enough to try it?