Moodle is one of the top online educational portals. Students can learn specific courses and then take quiz at the end of the course to find out how much they have learned. Recently, I was searching how to reopen a completed quiz in Moodle directly from database, but couldn’t find any information. I started experimenting on Moodle database structure myself, and achieved the desired result which I like to share.
First of all, to reopen any completed quiz in Moodle, we should understand how Moodle handles quiz queries. Whenever a new quiz is started, Moodle saves ’“attempt_id” in a “mdl_quiz_attempts” table. Response to a question is saved in “mdl_question_states” table, and the latest response of a question that is viewed in the quiz is logged in “mdl_question_sessions” table. When a quiz is completed, Moodle grades it, updates the event’s flag, and puts the finish time against “ATTEMPT_ID”.
Since we want to allow a user to update his mistakes after completing a quiz, the following steps should be performed. First of all, set “timefinish” column value to zero (0) in “mdl_quiz_attempts” table against provided “attempt_id”. Now the attempt is marked open, but green and red marks will be shown along the questions and answers. To eliminate the grading, we need to reset the “event” column value to two (2) in “mdl_question_states” table. Now, updating the event status will remove the grades option along the questions. Now you can correct your answers from a completed quiz and mark it as completed again.