I'm creating a block plugin that adds my ID verification/proctoring product to a course/quiz/etc and I'm not sure which ID would be best for me to use to uniquely identify the user/course combination.
For example, the course ID won't work, as multiple users could enrol in the same course. Similarly, the user id won't work, as a user can enrol in multiple courses. A combination of the user and course ID won't work, as the same user could take the same course more than once.
Does anyone have any suggestions?
That could work. Is there a setting to create a new enrolment each time the user takes a course? Where might I find that?
I'm not sure how you're conceptualising "each time a user takes a course". Do you mean each time they visit a course page? In our case, it would be each time a user enrols on a a particular module of their degree (although we actually have a separate Moodle course for each time a module runs, so a user would never take the same exact one twice).
Ideally, I'd like to have the user complete the course (all activities in the course), then the next time they want to take the course, a new enrolment is created. I've been doing some research and it appears I'm not the only one, but I've never found any evidence that anyone ever got it working.
Ok, I don't think you can do something like this with the existing settings. There's 2 main issues here; I dont think you can make enrolments end automatically when a course is completed, and completion is linked to a user and course or course module, rather than an enrolment.
One possibility would be to create a plugin with an event listener, which listens for the core\event\course_completed event. When this event is received for the course in question, it could reset the completion data for that user on that course, and remove their enrolment. Next time the visit the course, they would need to re-enrol. This wouldn't remove any other data that they've submitted to course modules on the course, though.