I used the insert_record function to put data into quiz and quiz_sections table. There's a function quiz_add_instance which adds data to the tables quiz and quiz_section and returns the quiz_id. But this functionn calls another function quiz_after_add_or_update. In this function there is a variable $cmid. What is the use of cmid and how do I fetch/generate it to proceed further?
Take a look at the docs on course modules - https://docs.moodle.org/dev/Course_module
Hi Davo,
I already went through the link, but the thing I could not understand is the relation between section field with the course_module table.
The only 'section' field I am aware of is in mdl_course_sections.
mdl_course_sections has several fields:
- id - the unique id of the section (i.e. section 2 in two different courses will have a different id here)
- course - the course the section belongs to
- section - the section position within the course (0, 1, 2, 3, etc. for each course) (i.e. if there is a 2nd section in multiple courses, then all of them will have a 2 here).
- sequence - ordered, comma-separated list of ids for the mdl_course_modules table, the activities that are present in that course section
I could finally get all my required data into the database and created a quiz.
The tables I modified are:
quiz, quiz_sections, course_modules, course_sections and quiz_slots
Now since all the tables have data and I got a quiz id from using the DML functions provided by moodle, the quiz should show up but I am still not able to see the quiz on my moodle dashboard. Is there anything left to do now? Is there any other table that I might be missing out or anything that I haven't done? Really need some assistance now.
Regards,
Mohanish
Hi Mohanish,
Please check attached ER-Diagram of DB tables by Markus. That might help to see relationships between tables.
Hello Mohanish,
I'm trying to create a quiz programmatically as you are doing.
I've used the function quiz_add_instance included in mod/quiz/lib.php but still don't see the quiz in Moodle after having created it.
Did you come up with a solution?
Thanks
Hi, I reply myself...
Finally I was able to do it!
I created a quiz programmatically and I'm able to see it on Moodle.
You just need to use this function (Tim mentioned it) properly:
$quiz = add_moduleinfo($quiz, $course, null)It is included in
https://github.com/moodle/moodle/blob/master/course/modlib.php#L44
Hi Alexis,
If possible can you please share the script that you have created for creating quizes.
Thanks, Dipak