Handling quiz attempts when merging user profiles

Handling quiz attempts when merging user profiles

by Luis de Vasconcelos -
Number of replies: 6
Picture of Particularly helpful Moodlers

Several fine gentlemen including Nicolas Dunand and Jordi Pujol-Ahulló have contributed to a Moodle Merge User Profiles plugin over at https://github.com/ndunand/moodle-mergeusers.

One of the discussion topics that has come up is how quiz attempts should be handled, especially when there are multiple quiz attempts on one or both of the two user profiles that are being merged. 

Tim (and any other Quiz experts here) could we have your valuable input on this important issue?

Example: https://github.com/ndunand/moodle-mergeusers/pull/24#issuecomment-41305098

Thanks.

Nicolas Dunand
Average of ratings: -
In reply to Luis de Vasconcelos

Re: Handling quiz attempts when merging user profiles

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 guess your code basically has a function like merge_users($useridtokeep, $useridtogetridof).

Mostly, you just need to update the mdl_quiz_attempts table, to set userid to the new value.

That is, something like

UPDATE {quiz_attempts} SET userid = $useridtokeep WHERE userid = $useridtogetridof

Except that won't always work, because (quizid, userid, attempt) needs to be unique. That is, if both $useridtokeep and $useridtogetridof have made an attempt 1 at the quiz, then you will need to rename one of them to attempt 2. Probably best to do that according to ORDER BY timestart, or something like that.

 

Then, once you have combined the two sets of attempts, you need to re-compute the final grades. The best way to do that is to call quiz_update_all_final_grades for all quizzes that were affected.

 

Finally, you need to deal with quiz_overrides. Again, the only tricky case is if currently an override exists for both $useridtokeep and $useridtogetridof. You need to decide a way to merge the two records. (Perhaps just throw one away.)

 

Oh, and it is probably a good idea to do

UPDATE {question_attempt_steps} SET userid = $useridtokeep WHERE userid = $useridtogetridof

No problems with unique keys there.

 

Oh, and also

UPDATE {question} SET createdby = $useridtokeep WHERE createdby = $useridtogetridof
UPDATE {question} SET modifiedby = $useridtokeep WHERE modifiedby = $useridtogetridof

Again, no complexity there

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

Re: Handling quiz attempts when merging user profiles

by John Hoopes -

That is all true to be able to merge 2 user accounts information, but what would you do for a quiz that has a limited number of attempts?  

Would you say that it just becomes a manual process?

Average of ratings: Useful (1)
In reply to John Hoopes

Re: Handling quiz attempts when merging user profiles

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

Well, I think the problem of limiited attempts is just like this situation:

  1. Teacher creates quiz that allows 2 attempts.
  2. Student makes 2 attempts.
  3. Teacher changes option to only allow one attempt.

What happens at stage 3 is nothing. No student attempts are deleted.

So, I think you can take the same approach for merging accounts. You just end up with  one student having 'too many' attempts, but it does not matter.

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

Re: Handling quiz attempts when merging user profiles

by Nicolas Dunand -
Picture of Core developers Picture of Plugin developers

After your stage 3, are the quizzes regraded – possibly ignoring the extra, now forbidden, attempt?

In the case of merging users, what would be the effect of quiz_update_all_final_grades? Would it be ignored, as is is not an "allowed" attempt?

In reply to Nicolas Dunand

Re: Handling quiz attempts when merging user profiles

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

If you want answers to detailed questions like this, your best bet is to read the code. That is an accurate description of what happens. My guess might not be accurate. (It counts all attempts. The limit on the number of attempts only has an effect when the student tries to start a new attempt.)

In reply to Tim Hunt

Re: Handling quiz attempts when merging user profiles

by Nicolas Dunand -
Picture of Core developers Picture of Plugin developers

OK Tim, thanks for your reply. I'll have a look at the code and figure it out.

Average of ratings: Useful (1)