class enrol_support

internal  
 

Utility functions for Moodle course enrolments.

Methods

static user_enrolment|null
get_enrol(int $courseid, int $userid)

Retrieves a user's enrolment record in a specific course.

static array
get_enrol_cohorts(int $courseid, int $userid)

Retrieves all cohort enrolments for a user in a course.

static bool
user_is_enrolled(int $courseid, int $userid)

Checks if a user is currently enrolled in a specific course.

static bool
enrol_user(int $courseid, int $userid, int $roleid = 5)

Enrols a user into a course with a specific role.

Details

at line 44
static user_enrolment|null get_enrol(int $courseid, int $userid)

Retrieves a user's enrolment record in a specific course.

Parameters

int $courseid

Course ID

int $userid

User ID

Return Value

user_enrolment|null

the user enrolment entity or null if not found

Exceptions

dml_exception

at line 68
static array get_enrol_cohorts(int $courseid, int $userid)

Retrieves all cohort enrolments for a user in a course.

Parameters

int $courseid

Course ID

int $userid

User ID

Return Value

array

records with id, name, idnumber from cohort table

Exceptions

dml_exception

at line 96
static bool user_is_enrolled(int $courseid, int $userid)

Checks if a user is currently enrolled in a specific course.

Parameters

int $courseid

Course ID

int $userid

User ID

Return Value

bool

True if the user is enrolled, false otherwise

at line 112
static bool enrol_user(int $courseid, int $userid, int $roleid = 5)

Enrols a user into a course with a specific role.

Parameters

int $courseid

Course ID

int $userid

User ID

int $roleid

Role ID (default: 5 - student)

Return Value

bool

True if the user has been successfully enrolled

Exceptions

moodle_exception