Skip to main content
Version: master

Moodle 4.4 developer update

This page highlights the important changes that are coming in Moodle 4.4 for developers.

Enrolment

Support for multiple instances in csv course upload

It is now possible to upload a CSV file with multiple enrol instances of the same type in same course. This is useful for example when you want to enrol users in a course using two different cohorts.

To support this, a new method has been added to allow the UI to locate existing enrolment instances:

/**
* Finds matching instances for a given course.
*
* @param array $enrolmentdata enrolment data.
* @param int $courseid Course ID.
* @return stdClass|null Matching instance
*/
public function find_instance(
array $enrolmentdata,
int $courseid,
) : ?stdClass;

If your enrolment plugins supports multiple instances within the same course, you should implement this method.

Format of the CSV file

Each line of the CSV should only have data for one enrolment instance.

best-example.csv
shortname,fullname,category_idnumber,enrolment_1,enrolment_1_role,enrolment_1_cohortidnumber
C1,Course 1,CAT1,cohort,student,CV1
C1,Course 1,CAT1,cohort,teacher,CV4
danger

If a single line format is used, only the final enrolment instance will be updated. For example in the following example only the second enrolment instance will be updated:

not-recommended-example.csv
shortname,fullname,category,summary,enrolment_1,enrolment_1_role,enrolment_2,enrolment_2_role
shortname,fullname,category,summary,cohort,student,cohort,teacher

Previous versions