Enrol user to course and group with the API

Enrol user to course and group with the API

by Davíð Baldursson -
Number of replies: 2

Hi

Right now I am trying to enrol a user to a course and a specific group within that course with the API.

Is that possible? 

RIght now I can enrol the user to the course no problem but I don't know how to enroll the user to a group also.


Relevant code is this

$plugin_instance = $DB->get_record("enrol", array('courseid'=>$return_data["user2"],     'enrol'=>'manual'));

$plugin = enrol_get_plugin('manual');

$plugin->enrol_user($plugin_instance, $return_data["user1"], $plugin_instance->roleid);



Average of ratings: Useful (1)
In reply to Davíð Baldursson

Re: Enrol user to course and group with the API

by Darko Miletić -

For enrolling user in a course there is a complete example here:

https://moodle.org/mod/forum/discuss.php?d=266496#p1152283


In reply to Darko Miletić

Re: Enrol user to course and group with the API

by Davíð Baldursson -

The code I posted works fine for enrolling student to the course, what i need is to assign the student to a group within that course. More specifically, how do I use the groups_add_member() function ? or is that not available anymore?