Recreating the quiz Edit Quiz Question Selection feature in another module

Recreating the quiz Edit Quiz Question Selection feature in another module

by Arvind Murali -
Number of replies: 5

I'm trying to write a game module that will allow questions from the question bank to be added and then played with. I'd like to be able to implement a question add feature similar to the quiz module where teachers pick and choose the questions for the quiz. I'd like to be able to pass a list of selected question ids to the game from where the questions can be rendered. Can someone with experience with the quiz module give me general guidance on how to reproduce just that part of the quiz for another module? 

Average of ratings: -
In reply to Arvind Murali

Re: Recreating the quiz Edit Quiz Question Selection feature in another module

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Have you seen https://moodle.org/plugins/mod_quizgame?

I would not necessarily copy how the quiz does it. That bit was coded quite a long time ago, and so is not done in a way that is currently recommended.

To let the use pick questions, you need to show a view of the question bank. The quiz does that with these classes https://github.com/moodle/moodle/tree/master/mod/quiz/classes/question/bank, and you can search to see where they are used.

Then you need to store the list of question ids somewhere. The quiz does that in the quiz_slots table.

P.S. it is not what you are asking here, but at some point you will probably need this docs page https://docs.moodle.org/dev/Using_the_question_engine_from_module at some time.
In reply to Tim Hunt

Re: Recreating the quiz Edit Quiz Question Selection feature in another module

by Arvind Murali -
Hey Tim,


I am infact starting with the quizgame but the game uses a mod_form to select a question category and pulls in all questions within that category. I want teachers to pick the questions from possibly multiple categories. When you say "I would not necessarily copy how the quiz does it.", I'm not sure I follow. Based on your input I see that edit.php basically calls the classes you mention. I haven't quite identified where the quiz_slots table gets updated with the selected questions, but I'm sure it's there. So, if I replicate edit.php in the mod_quizgame, I should be able to get the same experience right? When you say don't copy how the quiz does it, I'm sure sure what you are cautioning me about. ( I'm going to heed to your caution. Just trying to clarify a bit more! smile )

Thanks
In reply to Arvind Murali

Re: Recreating the quiz Edit Quiz Question Selection feature in another module

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

The code in edit.php, edit_rest.php, classes/output/edit_renderer.php and classes/structure.php is not a good example of how to build Moodle code. For example

  1. edit_rest.php is defnitely the wrong thing to do these days. You should implement web services to update things on the back-end, and use core/ajax JavaScript module to interact with those services. (https://docs.moodle.org/dev/External_functions_API)
  2. These days, better to use templates to generate the display of which questions have been selected, rather than putting lots of complex code in a renderer. Also, the acutual HTML we output is pretty horrible. I am sure you can display the info you need on screen with much simpler HTML.
The bits you should keep are:
  1. The general design of the quiz_slots table. You will need a similar table adapted to your needs.
  2. Acutally, the idea of a class like structure.php to implement the DB updates required by the external API is a good one. I am just not sure if the specific code there is nice.
  3. The general way the quiz shows a view of the question bank in a pop-up (mod/quiz/amd/src/add_question_modal_launcher.js, mod/quiz/classes/question/bank/custom_view.php is probably OK.
In reply to Tim Hunt

Re: Recreating the quiz Edit Quiz Question Selection feature in another module

by Arvind Murali -

Thanks Tim, 

I get your points. Not sure if I'm equipped enough to be able to code this though. I am not experienced enough to be able to pull this off. I'll see if I can find someone to help with this. Are you working on updating these for the quiz? 

In reply to Arvind Murali

Re: Recreating the quiz Edit Quiz Question Selection feature in another module

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 think that, for most of the issues I mentioned with the quiz code, it is not very broken for users, so we aren't going to fix it right now, because there are more imporant things to work on.

If you have the resources, there are Moodle partners who can do custom development for you.