Autoquiz plugin: quiz generation programmatically

Autoquiz plugin: quiz generation programmatically

by Alexis HF -
Number of replies: 6

Hello, I'm trying to create a Moodle feature that will make possible to auto-generate a quiz by defining some rules, for example:

- Generate a quiz with:

RULE 1: 50 questions in total, 

RULE 2: include 20 questions from category X

RULE 3: include 30 from category Y

RULE 4: exclude questions that are present in exam: 'EXAM TITLE'

...

After reading some Moodle plugin documentation, I've come the the conclusion that the best plugin type for this would be a 'quiz report' plugin. So the user will have to create an empty quiz and then use this plugin to insert the questions in the quiz following the rules defined.


Can anyone tell me a starting point to learn the functions/APIs needed to create a quiz programmatically?

Thanks a lot 


Average of ratings: -
In reply to Alexis HF

Re: Autoquiz plugin: quiz generation programmatically

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 don't think this needs a plugin. The example you give could just be created using the existing Moodle UI options, and that would only take a few minutes (https://xkcd.com/1205/).

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Autoquiz plugin: quiz generation programmatically

by Alexis HF -

Thanks Tim for your answer, let me explain a little bit better this use case:


Moodle in this case is being used as a digital platform to make an official certification exam. This is how we are using Moodle:


- Moodle is being used mainly as a digital exam platform

- This is an official certification exam orginized by a medical society

- All students (about 20 each year) that want to be certified, attends to a class the date/time they have to take the exam. The organizers give them iPads so they can connect to the exam platform and do the exam in person, but digitally

- All exam must be exactly the same, with the same numer of questions, this is why we cannot use the feature 'include a question randomly' from the quiz module

- The exam has been created in advance, following a set of rules (N questions from category X, M questions from category Y...) and has been review by the exam organizers


What we want to do is, instead of preparing the examen manually following the set of rules, we want Moodle do it for us, so not any person is envolved in the process of the exam preparation.


I don't see a way of doing this but by creating a plugin that includes the questions automatically in an empty exam...

Any suggestion? 

Thanks!


In reply to Alexis HF

Re: Autoquiz plugin: quiz generation programmatically

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

Oh, I see, you want all the people in one session to get the same exam. Now I see why you need to code it.

Anyway, it does not really matter what type of plugin you create (admin tool, or local, might be best. I would not use a quiz report, because typically the quiz report is used for a quiz that already exists, and you want to create new quizzes using this tool).

Either admin tools or local plugins have a way to hook into the settings navigation, so you can get a link to access them where yu want it in the UI.

To built the quzzes, you probably just need quiz_add_instance from mod/quiz/lib.php and quiz_add_quiz_question from mod/quiz/locallib.php. The code in quiz_start_new_attempt (in locallib.php) will show you how to find questions from the question bank.

I hope that helps.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Autoquiz plugin: quiz generation programmatically

by Alexis HF -

Thanks a lot Tim for you quick reply!


I was thinking about 'quiz report' plugin type because my first approach was:


- Manually create a course: '2018 Course Exam'

- Manually create/set a quiz inside the course: 'Exam 2018'

- Using the plugin (autoquiz) to populate the exam with questions following the defined rules


Other approach would be using the plugin from outside any course/quiz and creating the course, quiz and populate the quiz automatically using the plugin. This deliver a better user experience so I think I'd go for it.


Do you know what files I should have a look to create a course programatically?


Thanks again!




In reply to Alexis HF

Re: Autoquiz plugin: quiz generation programmatically

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

Several ways you might be able to see roughly the code to create something in Moodle.


Average of ratings: Useful (1)