Handling quiz attempts when merging user profiles

Handling quiz attempts when merging user profiles

Luis de Vasconcelos -
回帖数:6
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
回复Luis de Vasconcelos

Re: Handling quiz attempts when merging user profiles

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 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

回复Tim Hunt

Re: Handling quiz attempts when merging user profiles

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?

回复John Hoopes

Re: Handling quiz attempts when merging user profiles

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 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.

回复Tim Hunt

Re: Handling quiz attempts when merging user profiles

Nicolas Dunand -
Core developers的头像 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?

回复Nicolas Dunand

Re: Handling quiz attempts when merging user profiles

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 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.)

回复Tim Hunt

Re: Handling quiz attempts when merging user profiles

Nicolas Dunand -
Core developers的头像 Plugin developers的头像

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