class group_support

internal  
 

Utility functions for Moodle groups.

Methods

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

Retrieves groups that a user belongs to within a course.

static array
get_group_options(context|null $coursecontext = null)

Retrieves options for group selection [name => name].

static bool
is_member(int $groupid, int $userid)

Checks if a specific user is a member of a group.

static bool
add_member(int $groupid, int $userid)

Adds a user to a group.

static int|null
create_group(int $courseid, string $groupname, string $idnumber = '', string $description = '')

Creates a new group in a course.

static bool|int
get_group_by_name(int $courseid, string $groupname)

Retrieves a group ID by its name within a specific course.

static bool
add_user_in_group(int $courseid, int $userid, string $groupname)

Ensures a user is in a group, creating the group if necessary.

Details

at line 47
static array get_groups(int $courseid, int $userid)

Retrieves groups that a user belongs to within a course.

Parameters

int $courseid

Course ID

int $userid

User ID

Return Value

array

list of group records

at line 72
static array get_group_options(context|null $coursecontext = null)

Retrieves options for group selection [name => name].

Parameters

context|null $coursecontext

optional course context to filter groups

Return Value

array

Map of group name to group name

at line 109
static bool is_member(int $groupid, int $userid)

Checks if a specific user is a member of a group.

Parameters

int $groupid

Group ID

int $userid

User ID

Return Value

bool

True if member, false otherwise

at line 122
static bool add_member(int $groupid, int $userid)

Adds a user to a group.

Parameters

int $groupid

Group ID

int $userid

User ID

Return Value

bool

True on success, false otherwise

at line 143
static int|null create_group(int $courseid, string $groupname, string $idnumber = '', string $description = '')

Creates a new group in a course.

Parameters

int $courseid

Course ID

string $groupname

Group name

string $idnumber

optional idnumber

string $description

optional description (HTML)

Return Value

int|null

the created group ID or null on failure

at line 165
static bool|int get_group_by_name(int $courseid, string $groupname)

Retrieves a group ID by its name within a specific course.

Parameters

int $courseid

Course ID

string $groupname

Group name

Return Value

bool|int

Group ID or false if not found

at line 181
static bool add_user_in_group(int $courseid, int $userid, string $groupname)

Ensures a user is in a group, creating the group if necessary.

Parameters

int $courseid

Course ID

int $userid

User ID

string $groupname

Group name

Return Value

bool

True if the user was confirmed/added to the group, false on failures