On 9th April 2003, Martin Dougiamas introduced the random question type (https://github.com/moodle/moodle/commit/34d52ad7d29675bc1f1c6275bddf896e262145be) as a clever application of the adaptor pattern to allow questions to be added randomly to the quiz. With the benefit of 11.25 year's hind-sight, we can say this was probably a mistake. Maybe
The implementation was already greatly simplified as part of the question engine rewrite (
MDL-20636, e.g. https://github.com/moodle/moodle/commit/f9b0500f7fc461365303338181c33920a7b2c2c1).
However, we should probably completely remove qtype_random eventually, since overall it is more trouble than it is worth. Signs that there is a problem:
- mod/quiz/startattempt.php already has to have some code the manually detect random questions and handle them differently from other questions.
- special case code when question categories and quizzes are deleted, to clean up unused random questions (see
- some of the complexity in question backup and restore.
What we should do instead:
- Change mdl_quiz_slots to allow either a questionid or a categoryid, to mean that either that slot holds a specific question, or one picked at random from a category. (In future this would be more extensible when we want to allow random selection of question by tag, not category.)
- Deprecate qtype_random, but leave it in place, to handle restoring old backups, and converting the data to the new DB structure.
- Move the useful helper methods (e.g. select a question from this category) from inside qtype_random to core_question question bank library code.
- Update the quiz code to work with the new DB structure.
- Write the DB upgrade code.