Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core_group

Namespaces

namespace  core\event
  
 
namespace  core_group
  
 
namespace  core_group\customfield
  
 
namespace  core_group\external
  
 
namespace  core_group\hook
  
 
namespace  core_group\output
  
 
namespace  core_group\privacy
  
 
namespace  core_group\reportbuilder\datasource
  
 
namespace  core_group\reportbuilder\local\entities
  
 

Classes

class  autogroup_form
 Auto group form class. More...
 
class  behat_groups
 Groups-related steps definitions. More...
 
class  core\event\group_updated
 Group updated event class. More...
 
class  core\event\grouping_created
 Grouping created event class. More...
 
class  core_group\customfield\group_handler
 
class  core_group\customfield\grouping_handler
 
class  core_group\external\get_groups_for_selector
 
class  core_group\hook\after_group_created
 
class  core_group\hook\after_group_deleted
 
class  core_group\hook\after_group_membership_added
 
class  core_group\hook\after_group_membership_removed
 
class  core_group\hook\after_group_updated
 
class  core_group\output\group_details
 Group details page class. More...
 
class  core_group\output\index_page
 Group index page class. More...
 
class  core_group\output\renderer
 Renderer class. More...
 
class  core_group\output\user_groups_editable
 Class to display list of user groups. More...
 
class  core_group\privacy\provider
 Privacy Subsystem implementation for core_group. More...
 
class  core_group\reportbuilder\datasource\groups
 
class  core_group\reportbuilder\local\entities\group
 
class  core_group\reportbuilder\local\entities\group_member
 
class  core_group\reportbuilder\local\entities\grouping
 
class  core_group\visibility
 Group visibility methods. More...
 
class  core_group_external
 
class  group_form
 Group form class. More...
 
class  grouping_form
 Grouping form class. More...
 
class  groups_import_form
 Groups import form class. More...
 

Functions

 _group_verify_activegroup ($courseid, $groupmode, $groupingid, array $allowedgroups)
 Internal method, sets up $SESSION->activegroup and verifies previous value.
 
 core_group_inplace_editable ($itemtype, $itemid, $newvalue)
 Callback for inplace editable API.
 
 get_group_custom_fields_data (array $groupids)
 Returns custom fields data for provided groups.
 
 get_grouping_custom_fields_data (array $groupingids)
 Returns custom fields data for provided groupings.
 
 groups_add_member ($grouporid, $userorid, $component=null, $itemid=0)
 Adds a specified user to a group.
 
 groups_allgroups_course_menu ($course, $urlroot, $update=false, $activegroup=0)
 Generates html to print menu selector for course level, listing all groups.
 
 groups_assign_grouping ($groupingid, $groupid, $timeadded=null, $invalidatecache=true)
 Assigns group into grouping.
 
 groups_cache_groupdata ($courseid, cache $cache=null)
 Caches group data for a particular course to speed up subsequent requests.
 
 groups_calculate_role_people ($rs, $context)
 Internal function used by groups_get_members_by_role to handle the results of a database query that includes a list of users and possible roles on a course.
 
 groups_create_group ($data, $editform=false, $editoroptions=false)
 Add a new group.
 
 groups_create_grouping ($data, $editoroptions=null)
 Add a new grouping.
 
 groups_delete_group ($grouporid)
 Delete a group best effort, first removing members and links with courses and groupings.
 
 groups_delete_group_members ($courseid, $userid=0, $unused=false)
 Remove all users (or one user) from all groups in course.
 
 groups_delete_grouping ($groupingorid)
 Delete grouping.
 
 groups_delete_groupings ($courseid, $showfeedback=false)
 Delete all groupings from course.
 
 groups_delete_groupings_groups ($courseid, $showfeedback=false)
 Remove all groups from all groupings in course.
 
 groups_delete_groups ($courseid, $showfeedback=false)
 Delete all groups from course.
 
 groups_get_activity_allowed_groups ($cm, $userid=0)
 Gets a list of groups that the user is allowed to access within the specified activity.
 
 groups_get_activity_group ($cm, $update=false, $allowedgroups=null)
 Returns group active in activity, changes the group by default if 'group' page param present.
 
 groups_get_activity_groupmode ($cm, $course=null)
 Returns effective groupmode used in activity, course setting overrides activity setting if groupmodeforce enabled.
 
 groups_get_activity_shared_group_members ($cm, $userid=null)
 Returns users who share group membership with the specified user in the given actiivty.
 
 groups_get_all_groupings ($courseid)
 Gets an array of all groupings in a specified course.
 
 groups_get_all_groups ($courseid, $userid=0, $groupingid=0, $fields='g.*', $withmembers=false, $participationonly=false)
 Gets array of all groups in a specified course (subject to the conditions imposed by the other arguments).
 
 groups_get_course_data ($courseid, cache $cache=null)
 Gets group data for a course.
 
 groups_get_course_group ($course, $update=false, $allowedgroups=null)
 Returns group active in course, changes the group by default if 'group' page param present.
 
 groups_get_course_groupmode ($course)
 Returns effective groupmode used in course.
 
 groups_get_group ($groupid, $fields=' *', $strictness=IGNORE_MISSING, $withcustomfields=false)
 Get the group object.
 
 groups_get_group_by_idnumber ($courseid, $idnumber)
 Returns the groupid of a group with the idnumber specified for the course.
 
 groups_get_group_by_name ($courseid, $name)
 Returns the groupid of a group with the name specified for the course.
 
 groups_get_group_name ($groupid)
 Gets the name of a group with a specified id.
 
 groups_get_grouping ($groupingid, $fields=' *', $strictness=IGNORE_MISSING, $withcustomfields=false)
 Get the grouping object.
 
 groups_get_grouping_by_idnumber ($courseid, $idnumber)
 Returns the groupingid of a grouping with the idnumber specified for the course.
 
 groups_get_grouping_by_name ($courseid, $name)
 Returns the groupingid of a grouping with the name specified for the course.
 
 groups_get_grouping_members ($groupingid, $fields='u.*', $sort='lastname ASC')
 Returns the users in the specified grouping.
 
 groups_get_grouping_name ($groupingid)
 Gets the name of a grouping with a specified id.
 
 groups_get_groups_members ($groupsids, $extrafields=null, $sort='lastname ASC')
 Returns the users in the specified groups.
 
 groups_get_members ($groupid, $fields='u.*', $sort='lastname ASC')
 Returns the users in the specified group.
 
 groups_get_members_by_role (int $groupid, int $courseid, string $fields='u.*', ?string $sort=null, string $extrawheretest='', array $whereorsortparams=[], string $joins='')
 Lists users in a group based on their role on the course.
 
 groups_get_members_ids_sql ($groupids, context $context=null, $groupsjointype=GROUPS_JOIN_ANY)
 Get sql and parameters that will return user ids for a group or groups.
 
 groups_get_members_join ($groupids, $useridcolumn, context $context=null, int $jointype=GROUPS_JOIN_ANY)
 Get sql join to return users in a group.
 
 groups_get_my_groups ()
 Gets array of all groups in current user.
 
 groups_get_names_concat_sql (int $courseid, string $separator=', ')
 Returns array with SQL and parameters returning userids and concatenated group names for given course.
 
 groups_get_possible_roles ($context)
 Obtains a list of the possible roles that group members might come from, on a course.
 
 groups_get_potential_members ($courseid, $roleid=null, $source=null, $orderby='lastname ASC, firstname ASC', $notingroup=null, $onlyactiveenrolments=false, $extrafields=[])
 Gets potential group members for grouping.
 
 groups_get_user_groups (int $courseid, int $userid=0, bool $includehidden=false)
 Returns info about user's groups in course.
 
 groups_group_exists ($groupid)
 Determines if a group with a given groupid exists.
 
 groups_group_visible ($groupid, $course, $cm=null, $userid=null)
 Determine if a given group is visible to user or not in a given context.
 
 groups_has_membership ($cm, $userid=null)
 Determines if current or specified is member of any active group in activity.
 
 groups_is_member ($groupid, $userid=null)
 Determines if the user is a member of the given group.
 
 groups_list_to_menu ($groups)
 Turn an array of groups into an array of menu options.
 
 groups_parse_name ($format, $groupnumber)
 Parse a group name for characters to replace.
 
 groups_print_activity_menu ($cm, $urlroot, $return=false, $hideallparticipants=false)
 Print group menu selector for activity.
 
 groups_print_course_menu ($course, $urlroot, $return=false)
 Print group menu selector for course level.
 
 groups_remove_member ($grouporid, $userorid)
 Deletes the link between the specified user and group.
 
 groups_remove_member_allowed ($grouporid, $userorid)
 Checks whether the current user is permitted (using the normal UI) to remove a specific group member, assuming that they have access to remove group members in general.
 
 groups_sort_menu_options ($allowedgroups, $usergroups)
 Takes user's allowed groups and own groups and formats for use in group selector menu If user has allowed groups + own groups will add to an optgroup Own groups are removed from allowed groups.
 
 groups_sync_with_enrolment ($enrolname, $courseid=0, $gidfield='customint2')
 Synchronises enrolments with the group membership.
 
 groups_unassign_grouping ($groupingid, $groupid, $invalidatecache=true)
 Unassigns group from grouping.
 
 groups_update_group ($data, $editform=false, $editoroptions=false)
 Update group.
 
 groups_update_group_icon ($group, $data, $editform)
 Update the group icon from form data.
 
 groups_update_grouping ($data, $editoroptions=null)
 Update grouping.
 
 groups_user_groups_visible ($course, $userid, $cm=null)
 Determine if the current user can see at least one of the groups of the specified user.
 
 set_groups_messaging (array $groupids, bool $enabled)
 Updates group messaging to enable/disable in bulk.
 

Variables

global core_group\reportbuilder\local\entities::$CFG
 
 $row = array()
 
 $row []
 
const GROUPS_JOIN_ALL 2
 'All' join type, used when filtering by groups (logical AND)
 
const GROUPS_JOIN_ANY 1
 'Any' join type, used when filtering by groups (logical OR)
 
const GROUPS_JOIN_NONE 0
 'None' join type, used when filtering by groups (logical NOT)
 
const GROUPS_VISIBILITY_ALL 0
 All users can see this group and its members.
 
const GROUPS_VISIBILITY_MEMBERS 1
 Members of this group can see this group and other members.
 
const GROUPS_VISIBILITY_NONE 3
 No-one can see this group or its members.
 
const GROUPS_VISIBILITY_OWN 2
 Members of this group can see the group and their own membership, but not each other's membership.
 
 if (!defined( 'MOODLE_INTERNAL'))
 
 if (!defined( 'MOODLE_INTERNAL'))
 
 if (!defined( 'MOODLE_INTERNAL'))
 
const NOGROUPS 0
 Groups not used in course or activity.
 
const SEPARATEGROUPS 1
 Groups used, users do not see other groups.
 
const USERSWITHOUTGROUP -1
 This is for filtering users without any group.
 
const VISIBLEGROUPS 2
 Groups used, students see other groups.
 

Detailed Description

Function Documentation

◆ _group_verify_activegroup()

_group_verify_activegroup ( $courseid,
$groupmode,
$groupingid,
array $allowedgroups )

Internal method, sets up $SESSION->activegroup and verifies previous value.

Parameters
int$courseid
int | string$groupmodeSEPARATEGROUPS, VISIBLEGROUPS or 'aag' (access all groups)
int$groupingid0 means all groups
array$allowedgroupslist of groups user can see

◆ core_group_inplace_editable()

core_group_inplace_editable ( $itemtype,
$itemid,
$newvalue )

Callback for inplace editable API.

Parameters
string$itemtype- Only user_groups is supported.
string$itemid- Userid and groupid separated by a :
string$newvalue- json encoded list of groupids.
Return values
core\output\inplace_editable

◆ get_group_custom_fields_data()

get_group_custom_fields_data ( array $groupids)

Returns custom fields data for provided groups.

Parameters
array$groupidsa list of group IDs to provide data for.
Return values
core_customfield\data_controller[]

◆ get_grouping_custom_fields_data()

get_grouping_custom_fields_data ( array $groupingids)

Returns custom fields data for provided groupings.

Parameters
array$groupingidsa list of group IDs to provide data for.
Return values
core_customfield\data_controller[]

◆ groups_add_member()

groups_add_member ( $grouporid,
$userorid,
$component = null,
$itemid = 0 )

Adds a specified user to a group.

Parameters
mixed$grouporidThe group id or group object
mixed$useroridThe user id or user object
string$componentOptional component name e.g. 'enrol_imsenterprise'
int$itemidOptional itemid associated with component
Return values
boolTrue if user added successfully or the user is already a member of the group, false otherwise.

◆ groups_allgroups_course_menu()

groups_allgroups_course_menu ( $course,
$urlroot,
$update = false,
$activegroup = 0 )

Generates html to print menu selector for course level, listing all groups.

Note: This api does not do any group mode check use groups_print_course_menu() instead if you want proper checks.

Parameters
stdclass$coursecourse object.
string | moodle_url$urlrootreturn address. Accepts either a string or a moodle_url.
bool$updateset this to true to update current active group based on the group param.
int$activegroupChange group active to this group if $update set to true.
Return values
stringhtml or void

◆ groups_assign_grouping()

groups_assign_grouping ( $groupingid,
$groupid,
$timeadded = null,
$invalidatecache = true )

Assigns group into grouping.

Parameters
intgroupingid
intgroupid
int$timeaddedThe time the group was added to the grouping.
bool$invalidatecacheIf set to true the course group cache and the user group cache will be invalidated as well.
Return values
booltrue or exception

◆ groups_cache_groupdata()

groups_cache_groupdata ( $courseid,
cache $cache = null )

Caches group data for a particular course to speed up subsequent requests.

Parameters
int$courseidThe course id to cache data for.
cache$cacheThe cache if it has already been initialised. If not a new one will be created.
Return values
stdClassA data object containing groups, groupings, and mappings.

◆ groups_calculate_role_people()

groups_calculate_role_people ( $rs,
$context )

Internal function used by groups_get_members_by_role to handle the results of a database query that includes a list of users and possible roles on a course.

Parameters
moodle_recordset$rsThe record set (may be false)
int$contextID of course context
Return values
arrayAs described in groups_get_members_by_role

◆ groups_create_group()

groups_create_group ( $data,
$editform = false,
$editoroptions = false )

Add a new group.

Parameters
stdClass$datagroup properties
stdClass$editform
array$editoroptions
Return values
intid of group or throws an exception on error
Exceptions
moodle_exception

◆ groups_create_grouping()

groups_create_grouping ( $data,
$editoroptions = null )

Add a new grouping.

Parameters
stdClass$datagrouping properties
array$editoroptions
Return values
intid of grouping or throws an exception on error
Exceptions
moodle_exception

◆ groups_delete_group()

groups_delete_group ( $grouporid)

Delete a group best effort, first removing members and links with courses and groupings.

Removes group avatar too.

Parameters
mixed$grouporidThe id of group to delete or full group object
Return values
boolTrue if deletion was successful, false otherwise

◆ groups_delete_group_members()

groups_delete_group_members ( $courseid,
$userid = 0,
$unused = false )

Remove all users (or one user) from all groups in course.

Parameters
int$courseid
int$userid0 means all users
bool$unused- formerly $showfeedback, is no longer used.
Return values
boolsuccess

◆ groups_delete_grouping()

groups_delete_grouping ( $groupingorid)

Delete grouping.

Parameters
int$groupingorid
Return values
boolsuccess

◆ groups_delete_groupings()

groups_delete_groupings ( $courseid,
$showfeedback = false )

Delete all groupings from course.

Parameters
int$courseid
bool$showfeedback
Return values
boolsuccess

◆ groups_delete_groupings_groups()

groups_delete_groupings_groups ( $courseid,
$showfeedback = false )

Remove all groups from all groupings in course.

Parameters
int$courseid
bool$showfeedback
Return values
boolsuccess

◆ groups_delete_groups()

groups_delete_groups ( $courseid,
$showfeedback = false )

Delete all groups from course.

Parameters
int$courseid
bool$showfeedback
Return values
boolsuccess

◆ groups_get_activity_allowed_groups()

groups_get_activity_allowed_groups ( $cm,
$userid = 0 )

Gets a list of groups that the user is allowed to access within the specified activity.

Parameters
stdClass | cm_info$cmCourse-module
int$useridUser ID (defaults to current user)
Return values
arrayAn array of group objects, or false if none

◆ groups_get_activity_group()

groups_get_activity_group ( $cm,
$update = false,
$allowedgroups = null )

Returns group active in activity, changes the group by default if 'group' page param present.

Parameters
stdClass | cm_info$cmcourse module object
bool$updatechange active group if group param submitted
array$allowedgroupslist of groups user may access (INTERNAL, to be used only from groups_print_activity_menu())
Return values
mixedfalse if groups not used, int if groups used, 0 means all groups (access must be verified in SEPARATE mode)

◆ groups_get_activity_groupmode()

groups_get_activity_groupmode ( $cm,
$course = null )

Returns effective groupmode used in activity, course setting overrides activity setting if groupmodeforce enabled.

If $cm is an instance of cm_info it is easier to use $cm->effectivegroupmode

Parameters
cm_info | stdClass$cmthe course module object. Only the ->course and ->groupmode need to be set.
stdClass$courseobject optional course object to improve perf
Return values
intgroup mode

◆ groups_get_activity_shared_group_members()

groups_get_activity_shared_group_members ( $cm,
$userid = null )

Returns users who share group membership with the specified user in the given actiivty.

Parameters
stdClass | cm_info$cmcourse module
int$useriduser id (empty for current user)
Return values
arraya list of user
Since
Moodle 3.3

◆ groups_get_all_groupings()

groups_get_all_groupings ( $courseid)

Gets an array of all groupings in a specified course.

This value is cached for a single course (so you can call it repeatedly for the same course without a performance penalty).

Parameters
int$courseidreturn all groupings from course with this courseid
Return values
arrayReturns an array of the grouping objects (empty if none)

◆ groups_get_all_groups()

groups_get_all_groups ( $courseid,
$userid = 0,
$groupingid = 0,
$fields = 'g.*',
$withmembers = false,
$participationonly = false )

Gets array of all groups in a specified course (subject to the conditions imposed by the other arguments).

If a user does not have moodle/course:viewhiddengroups, the list of groups and members will be restricted based on the visibility setting of each group.

Parameters
int$courseidThe id of the course.
int | int[]$useridoptional user id or array of ids, returns only groups continaing one or more of those users.
int$groupingidoptional returns only groups in the specified grouping.
string$fieldsdefaults to g.*. This allows you to vary which fields are returned. If $groupingid is specified, the groupings_groups table will be available with alias gg. If $userid is specified, the groups_members table will be available as gm.
bool$withmembersif true return an extra field members (int[]) which is the list of userids that are members of each group. For this to work, g.id (or g.*) must be included in $fields. In this case, the final results will always be an array indexed by group id.
bool$participationonlyOnly return groups where the participation field is true.
Return values
arrayreturns an array of the group objects (unless you have done something very weird with the $fields option).

◆ groups_get_course_data()

groups_get_course_data ( $courseid,
cache $cache = null )

Gets group data for a course.

This returns an object with the following properties:

  • groups : An array of all the groups in the course.
  • groupings : An array of all the groupings within the course.
  • mappings : An array of group to grouping mappings.
Parameters
int$courseidThe course id to get data for.
cache$cacheThe cache if it has already been initialised. If not a new one will be created.
Return values
stdClass

◆ groups_get_course_group()

groups_get_course_group ( $course,
$update = false,
$allowedgroups = null )

Returns group active in course, changes the group by default if 'group' page param present.

Parameters
stdClass$coursecourse bject
bool$updatechange active group if group param submitted
array$allowedgroupslist of groups user may access (INTERNAL, to be used only from groups_print_course_menu())
Return values
mixedfalse if groups not used, int if groups used, 0 means all groups (access must be verified in SEPARATE mode)

◆ groups_get_course_groupmode()

groups_get_course_groupmode ( $course)

Returns effective groupmode used in course.

Parameters
stdClass$coursecourse object.
Return values
intgroup mode

◆ groups_get_group()

groups_get_group ( $groupid,
$fields = '*',
$strictness = IGNORE_MISSING,
$withcustomfields = false )

Get the group object.

Parameters
int$groupidID of the group.
string$fields(default is all fields)
int$strictness(IGNORE_MISSING - default)
Return values
bool|stdClassgroup object or false if not found
Exceptions
dml_exception

◆ groups_get_group_by_idnumber()

groups_get_group_by_idnumber ( $courseid,
$idnumber )

Returns the groupid of a group with the idnumber specified for the course.

Group idnumbers should be unique within course

Parameters
int$courseidThe id of the course
string$idnumberidnumber of group
Return values
stdClass|falsegroup object

◆ groups_get_group_by_name()

groups_get_group_by_name ( $courseid,
$name )

Returns the groupid of a group with the name specified for the course.

Group names should be unique in course

Parameters
int$courseidThe id of the course
string$namename of group (without magic quotes)
Return values
int\$groupid

◆ groups_get_group_name()

groups_get_group_name ( $groupid)

Gets the name of a group with a specified id.

Before output, you should call {

See also
format_string} on the result
Parameters
int$groupidThe id of the group
Return values
stringThe name of the group

◆ groups_get_grouping()

groups_get_grouping ( $groupingid,
$fields = '*',
$strictness = IGNORE_MISSING,
$withcustomfields = false )

Get the grouping object.

Parameters
int$groupingidID of the group.
string$fields
int$strictness(IGNORE_MISSING - default)
Return values
stdClassgroup object

◆ groups_get_grouping_by_idnumber()

groups_get_grouping_by_idnumber ( $courseid,
$idnumber )

Returns the groupingid of a grouping with the idnumber specified for the course.

Grouping names should be unique within course

Parameters
int$courseidThe id of the course
string$idnumberidnumber of the group
Return values
stdClass|falsegrouping object

◆ groups_get_grouping_by_name()

groups_get_grouping_by_name ( $courseid,
$name )

Returns the groupingid of a grouping with the name specified for the course.

Grouping names should be unique in course

Parameters
int$courseidThe id of the course
string$namename of group (without magic quotes)
Return values
int\$groupid

◆ groups_get_grouping_members()

groups_get_grouping_members ( $groupingid,
$fields = 'u.*',
$sort = 'lastname ASC' )

Returns the users in the specified grouping.

Parameters
int$groupingidThe groupingid to get the users for
string$fieldsThe fields to return
string$sortoptional sorting of returned users
Return values
array|boolReturns an array of the users for the specified group or false if no users or an error returned.

◆ groups_get_grouping_name()

groups_get_grouping_name ( $groupingid)

Gets the name of a grouping with a specified id.

Before output, you should call {

See also
format_string} on the result
Parameters
int$groupingidThe id of the grouping
Return values
stringThe name of the grouping

◆ groups_get_groups_members()

groups_get_groups_members ( $groupsids,
$extrafields = null,
$sort = 'lastname ASC' )

Returns the users in the specified groups.

This function does not return complete user objects by default. It returns the user_picture basic fields.

Parameters
array$groupsidsThe list of groups ids to check
array$extrafieldsextra fields to be included in result
int$sortoptional sorting of returned users
Return values
array|boolReturns an array of the users for the specified group or false if no users or an error returned.
Since
Moodle 3.3

◆ groups_get_members()

groups_get_members ( $groupid,
$fields = 'u.*',
$sort = 'lastname ASC' )

Returns the users in the specified group.

Parameters
int$groupidThe groupid to get the users for
int$fieldsThe fields to return
int$sortoptional sorting of returned users
Return values
arrayReturns an array of the users for the specified group

◆ groups_get_members_by_role()

groups_get_members_by_role ( int $groupid,
int $courseid,
string $fields = 'u.*',
?string $sort = null,
string $extrawheretest = '',
array $whereorsortparams = [],
string $joins = '' )

Lists users in a group based on their role on the course.

Returns false if there's an error or there are no users in the group. Otherwise returns an array of role ID => role data, where role data includes: (role) $id, $shortname, $name $users: array of objects for each user which include the specified fields Users who do not have a role are stored in the returned array with key '-' and pseudo-role details (including a name, 'No role'). Users with multiple roles, same deal with key '*' and name 'Multiple roles'. You can find out which roles each has by looking in the $roles array of the user object.

Parameters
int$groupid
int$courseidCourse ID (should match the group's course)
string$fieldsList of fields from user table (prefixed with u) and joined tables, default 'u.*'
string | null$sortSQL ORDER BY clause, default (when null passed) is what comes from users_order_by_sql.
string$extrawheretestextra SQL conditions ANDed with the existing where clause.
array$whereorsortparamsany parameters required by $extrawheretest or $joins (named parameters).
string$joinsany joins required to get the specified fields.
Return values
arrayComplex array as described above

◆ groups_get_members_ids_sql()

groups_get_members_ids_sql ( $groupids,
context $context = null,
$groupsjointype = GROUPS_JOIN_ANY )

Get sql and parameters that will return user ids for a group or groups.

Parameters
int | array$groupidsWhere this is an array of multiple groups, it will match on members of any of the groups
context$contextCourse context or a context within a course. Mandatory when $groupid = USERSWITHOUTGROUP
int$groupsjointypeJoin type logic used. Defaults to 'Any' (logical OR).
Return values
array($sql,$params)
Exceptions
coding_exceptionif empty or invalid context submitted when $groupid = USERSWITHOUTGROUP

◆ groups_get_members_join()

groups_get_members_join ( $groupids,
$useridcolumn,
context $context = null,
int $jointype = GROUPS_JOIN_ANY )

Get sql join to return users in a group.

Parameters
int | array$groupidsThe groupids, 0 or [] means all groups and USERSWITHOUTGROUP no group
string$useridcolumnThe column of the user id from the calling SQL, e.g. u.id
context$contextCourse context or a context within a course. Mandatory when $groupids includes USERSWITHOUTGROUP
int$jointypeJoin type logic used. Defaults to 'Any' (logical OR).
Return values
core\dml\sql_joinContains joins, wheres, params
Exceptions
coding_exceptionif empty or invalid context submitted when $groupid = USERSWITHOUTGROUP

◆ groups_get_my_groups()

groups_get_my_groups ( )

Gets array of all groups in current user.

Since
Moodle 2.5
Return values
arrayReturns an array of the group objects.

◆ groups_get_names_concat_sql()

groups_get_names_concat_sql ( int $courseid,
string $separator = ',
'  )

Returns array with SQL and parameters returning userids and concatenated group names for given course.

This function uses 'gn[0-9]+_' prefix for table names and parameters

Parameters
int$courseid
string$separator
Return values
array[$sql, $params]

◆ groups_get_possible_roles()

groups_get_possible_roles ( $context)

Obtains a list of the possible roles that group members might come from, on a course.

Generally this includes only profile roles.

Parameters
context$contextContext of course
Return values
Arrayof role ID integers, or false if error/none.

◆ groups_get_potential_members()

groups_get_potential_members ( $courseid,
$roleid = null,
$source = null,
$orderby = 'lastname ASC,
firstname ASC' ,
$notingroup = null,
$onlyactiveenrolments = false,
$extrafields = [] )

Gets potential group members for grouping.

Parameters
int$courseidThe id of the course
int$roleidThe role to select users from
mixed$sourcerestrict to cohort, grouping or group id
string$orderbyThe column to sort users by
int$notingrouprestrict to users not in existing groups
bool$onlyactiveenrolmentsrestrict to users who have an active enrolment in the course
array$extrafieldsExtra user fields to return
Return values
arrayAn array of the users

◆ groups_get_user_groups()

groups_get_user_groups ( int $courseid,
int $userid = 0,
bool $includehidden = false )

Returns info about user's groups in course.

Parameters
int$courseid
int$userid$USER if not specified
bool$includehiddenInclude groups with GROUP_VISIBILITY_NONE that the user is a member of, but is not allowed to see themselves. Use this parameter with care - it is the responsibility of the calling code to ensure these groups are not exposed to the user, as this could have privacy implications.
Return values
arrayArray[groupingid][groupid] including grouping id 0 which means all groups

◆ groups_group_exists()

groups_group_exists ( $groupid)

Determines if a group with a given groupid exists.

Parameters
int$groupidThe groupid to check for
Return values
boolTrue if the group exists, false otherwise or if an error occurred.

◆ groups_group_visible()

groups_group_visible ( $groupid,
$course,
$cm = null,
$userid = null )

Determine if a given group is visible to user or not in a given context.

Since
Moodle 2.6
Parameters
int$groupidGroup id to test. 0 for all groups.
stdClass$courseCourse object.
stdClass$cmCourse module object.
int$useriduser id to test against. Defaults to $USER.
Return values
booleantrue if visible, false otherwise

◆ groups_has_membership()

groups_has_membership ( $cm,
$userid = null )

Determines if current or specified is member of any active group in activity.

@staticvar array $cache

Parameters
stdClass | cm_info$cmcourse module object
int$useridid of user, null means $USER->id
Return values
booltrue if user member of at least one group used in activity

◆ groups_is_member()

groups_is_member ( $groupid,
$userid = null )

Determines if the user is a member of the given group.

If $userid is null, use the global object.

Parameters
int$groupidThe group to check for membership.
int$useridThe user to check against the group.
Return values
boolTrue if the user is a member, false otherwise.

◆ groups_list_to_menu()

groups_list_to_menu ( $groups)

Turn an array of groups into an array of menu options.

Parameters
array$groupsof group objects.
Return values
arraygroupid => formatted group name.

◆ groups_parse_name()

groups_parse_name ( $format,
$groupnumber )

Parse a group name for characters to replace.

Parameters
string$formatThe format a group name will follow
int$groupnumberThe number of the group to be used in the parsed format string
Return values
stringthe parsed format string

◆ groups_print_activity_menu()

groups_print_activity_menu ( $cm,
$urlroot,
$return = false,
$hideallparticipants = false )

Print group menu selector for activity.

Parameters
stdClass | cm_info$cmcourse module object
string | moodle_url$urlrootreturn address that users get to if they choose an option; should include any parameters needed, e.g. "$CFG->wwwroot/mod/forum/view.php?id=34"
bool$returnreturn as string instead of printing
bool$hideallparticipantsIf true, this prevents the 'All participants' option from appearing in cases where it normally would. This is intended for use only by activities that cannot display all groups together. (Note that selecting this option does not prevent groups_get_activity_group from returning 0; it will still do that if the user has chosen 'all participants' in another activity, or not chosen anything.)
Return values
mixedvoid or string depending on $return param

◆ groups_print_course_menu()

groups_print_course_menu ( $course,
$urlroot,
$return = false )

Print group menu selector for course level.

Parameters
stdClass$coursecourse object
mixed$urlrootreturn address. Accepts either a string or a moodle_url
bool$returnreturn as string instead of printing
Return values
mixedvoid or string depending on $return param

◆ groups_remove_member()

groups_remove_member ( $grouporid,
$userorid )

Deletes the link between the specified user and group.

Parameters
mixed$grouporidThe group id or group object
mixed$useroridThe user id or user object
Return values
boolTrue if deletion was successful, false otherwise

◆ groups_remove_member_allowed()

groups_remove_member_allowed ( $grouporid,
$userorid )

Checks whether the current user is permitted (using the normal UI) to remove a specific group member, assuming that they have access to remove group members in general.

For automatically-created group member entries, this checks with the relevant plugin to see whether it is permitted. The default, if the plugin doesn't provide a function, is true.

For other entries (and any which have already been deleted/don't exist) it just returns true.

Parameters
mixed$grouporidThe group id or group object
mixed$useroridThe user id or user object
Return values
boolTrue if permitted, false otherwise

◆ groups_sort_menu_options()

groups_sort_menu_options ( $allowedgroups,
$usergroups )

Takes user's allowed groups and own groups and formats for use in group selector menu If user has allowed groups + own groups will add to an optgroup Own groups are removed from allowed groups.

Parameters
array$allowedgroupsAll groups user is allowed to see
array$usergroupsGroups user belongs to
Return values
array

◆ groups_sync_with_enrolment()

groups_sync_with_enrolment ( $enrolname,
$courseid = 0,
$gidfield = 'customint2' )

Synchronises enrolments with the group membership.

Designed for enrolment methods provide automatic synchronisation between enrolled users and group membership, such as enrol_cohort and enrol_meta .

Parameters
string$enrolnamename of enrolment method without prefix
int$courseidcourse id where sync needs to be performed (0 for all courses)
string$gidfieldname of the field in 'enrol' table that stores group id
Return values
arrayReturns the list of removed and added users. Each record contains fields: userid, enrolid, courseid, groupid, groupname

◆ groups_unassign_grouping()

groups_unassign_grouping ( $groupingid,
$groupid,
$invalidatecache = true )

Unassigns group from grouping.

Parameters
intgroupingid
intgroupid
bool$invalidatecacheIf set to true the course group cache and the user group cache will be invalidated as well.
Return values
boolsuccess

◆ groups_update_group()

groups_update_group ( $data,
$editform = false,
$editoroptions = false )

Update group.

Parameters
stdClass$datagroup properties (with magic quotes)
stdClass$editform
array$editoroptions
Return values
booltrue or exception

◆ groups_update_group_icon()

groups_update_group_icon ( $group,
$data,
$editform )

Update the group icon from form data.

Parameters
stdClass$groupgroup information
stdClass$data
stdClass$editform

◆ groups_update_grouping()

groups_update_grouping ( $data,
$editoroptions = null )

Update grouping.

Parameters
stdClass$datagrouping properties (with magic quotes)
array$editoroptions
Return values
booltrue or exception

◆ groups_user_groups_visible()

groups_user_groups_visible ( $course,
$userid,
$cm = null )

Determine if the current user can see at least one of the groups of the specified user.

Parameters
stdClass$courseCourse object.
int$useriduser id to check against.
stdClass$cmCourse module object. Optional, just for checking at activity level instead course one.
Return values
booleantrue if visible, false otherwise
Since
Moodle 2.9

◆ set_groups_messaging()

set_groups_messaging ( array $groupids,
bool $enabled )

Updates group messaging to enable/disable in bulk.

Parameters
array$groupidsarray of group id numbers.
bool$enabledif true, enables messaging else disables messaging

Variable Documentation

◆ $row

$row[]
Initial value:
= new tabobject('groups',
new moodle_url('/group/index.php', array('id' => $courseid)),
get_string('groups'))
Class for creating and manipulating urls.
Definition weblib.php:263
Stores one tab.
Definition outputcomponents.php:3984

◆ GROUPS_VISIBILITY_NONE

const GROUPS_VISIBILITY_NONE 3

No-one can see this group or its members.

Members of the group will not know they are in the group.