Moving quiz results to a different course

Moving quiz results to a different course

by Claudio Bartoloni -
Number of replies: 4

I have only a course in my moodle installation that I duplicate every month to start a new class with new user.  After six month I close the course and move user who have not completed the course to a new one. 

When I move the users I would like to move the result of their quiz attempts in the old course to the same quiz in the new course.

I found this topic https://moodle.org/mod/forum/discuss.php?d=347705 that is related to a similar problem but in that case the quiz attempts were moved from two similar quiz in the same course just by changing 2 values:

  • The quiz id in the row of the quiz_attempts table.
  • The contextid in the corresponding row of the question_usages table.
I would like to ask if changing also the course id  those changes can solve also my problem.

In this case I would like to ask which is the easiest way to find the context id of the quiz in the new course.

These are the sql statements I would like to use: 

  • to identify the attempts that I need to move

Select quiza.id, quiza.quiz, quiza.userid, quiza.uniqueid, qu.contextid from mdl_quiz_attempts AS quiza 

JOIN mdl_question_usages qu ON qu.id = quiza.uniqueid 

WHERE quiza.quiz = (Select id from mdl_quiz where name = 'Simulazione 1' and course = (Select id from mdl_course where shortname = 'PMEZEM18')) and quiza.state = 'finished' ;

  • to identify the grades that I need to move

Select id, quiz, userid, grade from mdl_quiz_grades where quiz = (Select id from mdl_quiz where name = 'Simulazione 1' and course = (Select id from mdl_course where shortname = 'PMEZEM18'));

  • to identify the quiz in the new course where to move the results

Select id from mdl_quiz where name = 'Simulazione 1' and course = (Select id from mdl_course where shortname = 'PMEZEM19');

Thanks

Moodle 3.6.1

Average of ratings: -
In reply to Claudio Bartoloni

Re: Moving quiz results to a different course

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

That should probably work, if you are careful. (Best to test this on a test copy of your main site, if you have one, just in case everything goes horribly wrong.)

The way contexts work is this. ... well, for activities like quiz. Look in the mdl_context table. All the activities have contextlevel = 70. The instanceids link to the course_modules.id column. In that table mod links to the modules table, and tells you what type of activity it is. For activities that are quizzes, the course_modules.instance column links to the quiz.id column. I hope that makes sense.

To verify that, then in the Moodle UI, go to Quiz settings -> Permissions for that quiz. The contextid will be in the URL.

In reply to Tim Hunt

Re: Moving quiz results to a different course

by Claudio Bartoloni -

I'm doing some test in a copy of my site.

I can move the attempts from a quiz to another updating selected fields on the tables mdl__quiz_attempts and mdl_quiz_grades.

But the grades for the user are not moved. 

I suppose it is necessary to update also the table mdl_grade_grades to complete the move.

Could you please explain how the grade tables works?


In reply to Claudio Bartoloni

Re: Moving quiz results to a different course

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

There is a function (grades_update_grade) that is called by the quiz (or any graded activity) to update the grade book. With the quiz this happens after an attempt is graded (or regraded). You might try regrading one of the transferred attempts in the new quiz. It should get the grade item from the updated quiz id and put it in the right place. If that works do regrade all.

In reply to Daniel Thies

Re: Moving quiz results to a different course

by Claudio Bartoloni -

Hi Daniel

I regraded the transferred attempt and  it works fine.

But I couldn't find a way to remove the grades (with no attempts) in the old quiz

Also regrading all the old quiz do not remove the grades for the transferred attempts.

So I deleted the proper row in the mdl_grade_grades table and all looks fine.

Thank you for your help