General developer forum

Appropriate ID to use in plugin

 
Picture of Scott Dellinger
Appropriate ID to use in plugin
 

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?

 
Average of ratings: -
Picture of Mark Johnson
Re: Appropriate ID to use in plugin
Core developersParticularly helpful MoodlersPlugin developers
If you are going to create a separate enrolment each time a user takes a course, you could use the enrolment ID? Aside from that, I don't think Moodle has a way of identifying multiple "instances" of a the same user on the same course.
 
Average of ratings: -
Picture of Scott Dellinger
Re: Appropriate ID to use in plugin
 

That could work. Is there a setting to create a new enrolment each time the user takes a course? Where might I find that?

 
Average of ratings: -
Picture of Mark Johnson
Re: Appropriate ID to use in plugin
Core developersParticularly helpful MoodlersPlugin developers

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).

 
Average of ratings: -
Picture of Scott Dellinger
Re: Appropriate ID to use in plugin
 

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.

 
Average of ratings: -
Picture of Mark Johnson
Re: Appropriate ID to use in plugin
Core developersParticularly helpful MoodlersPlugin developers

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.

 
Average of ratings: -