How to restore a user's quiz attempts and grades after he/she has accidentally unenrolled himself/herself?
When a user is unenrolled, their grade history is not deleted. If a user is unenrolled accidentally, their grades can be restored by going to Administration > Course administration > Users > Enrolled users, clicking 'Enrol users' and making sure that the 'Recover user's old grades if possible' checkbox is ticked in the enrolment options before re-enrolling the user.
Users enrolled with methods other than manual (such as self enrolment) will have their grades restored depending on the value of “recovergradesdefault” in Administration > Site administration > Grades > General settings. Further, once the user re-enrolls in the course, their grade in every graded activity may need to be restored manually, for example, by using the “regrade selected attempts” option in a Quiz.