moodle 3 - add cohort to course programmatically?

moodle 3 - add cohort to course programmatically?

by marcel montel -
Number of replies: 4

Is the only way to assign a cohort sync to a course via the UI?, i was hoping that i could use webservices to do this, or maybe im getting it wrong, is there another way to to a

Our courses are single activity so they are quite a few.  every academy (could be 100)


When i create a academy in our system i create a cohort through webservices
When i create a user in an academy that user gets added to the cohort

I would then want to be able to add the cohort to 1-30 > courses..

Please advise, can the same be achieved in some other way? categories?, groups seems to be out of the questions since they are local to a course instance.


Average of ratings: -
In reply to marcel montel

Re: moodle 3 - add cohort to course programmatically?

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Write a plugin (admin tool) that would listen to the course_created event and automatically add an instance of cohort enrolment to it.

In reply to Marina Glancy

Re: moodle 3 - add cohort to course programmatically?

by marcel montel -

I guess that is the way to do, but more importantly write a webservice  that allows for enrollolling a given cohort in a course.


I am not super proficient in php, but i guess with some Help i can find out what has to be done. Any pointers are welcome 

In reply to marcel montel

Re: moodle 3 - add cohort to course programmatically?

by marcel montel -

solved, i ended up writing a webservice for it.

In reply to marcel montel

Re: moodle 3 - add cohort to course programmatically?

by Kevin Bruton -

Could you please share the webservice you created as I would like to implement it as well?

I would suggest opening an issue in tracker so it can be added to Moodle Core, as I believe it would be a great improvement for Moodle and for everyone!