I am trying to add the condition of maximum members for self-enrolment to a group by enrollment key in Moodle.
Generally you create a course and then a self-enrolment instance for your course, then if you have multiple groups within your course you create your groups and create enrolment keys for your groups. Students will use the enrolment key for their associated groups and automatically get enrolled in the right group. So far everything works fine.
Now my groups have maximum capacity but Moodle does not have a feature to check this. Anyone with the enrolment key gets into the group.
I have added a custom field to my groups called Maximum Members. In this field I store the maximum number of members for the group.
I need to make changes in Moodle self-enrolment logic so whenever a user tries to enroll using an enrolment key the number in Maximum Members is compared to current number of members in the group and then enrolment is either allowed or rejected.
I have got familiar with where things are happening (/enrol/self/locallib.php) and I have found this function enrol_self_check_group_enrolment_key($courseid, $enrolpassword)
How can I add the above condition? Basically getting the current number of members in the group and compare with my group’s custom field (Max members) before allowing enrolment. Otherwise an error message is returned. Thank you