Was working on porting
MDL-23848 to head and came across a couple of bugs within get_enrolled_sql.
In this case $groupid is only made use of if the caller also specificed a $withcapabaility, i.e. if you supply a blank $withcapability then $groupid is ignored.
I'm not 100% sure if this is an error or not, it may be intended functionality, or maybe required functionality?
I'll leave that up to you being the master of enrolments