class role_support

internal  
 

Utility functions for Moodle roles and assignments.

Methods

static array
get_role_options(context|null $coursecontext = null, array $excluderoles = ['guest'])

Retrieves assignable roles as an options list [roleid => label].

static array
get_roles_options()

Retrieves roles options for the current course.

static bool
isteacher(int $userid)

Checks if a user has a teacher role in any enrolled course.

static bool|stdClass
get_teacher(int $courseid)

Retrieves a teacher user record for a specific course.

Details

at line 44
static array get_role_options(context|null $coursecontext = null, array $excluderoles = ['guest'])

Retrieves assignable roles as an options list [roleid => label].

Parameters

context|null $coursecontext

optional course context to filter assignable roles

array $excluderoles

List of role shortnames to exclude

Return Value

array

Map of role ID to localized name

at line 68
static array get_roles_options()

Retrieves roles options for the current course.

Return Value

array

Map of role ID to localized name

at line 86
static bool isteacher(int $userid)

Checks if a user has a teacher role in any enrolled course.

Parameters

int $userid

User ID

Return Value

bool

True if teacher, false otherwise

at line 123
static bool|stdClass get_teacher(int $courseid)

Retrieves a teacher user record for a specific course.

Tries to find role by shortname prioritizing 'editingteacher' and, if not found, falls back to 'teacher'. Avoids using numeric indexes from get_all_roles() as they can vary between installations.

Parameters

int $courseid

Course ID

Return Value

bool|stdClass

the user record or false if none found

Exceptions

dml_exception