Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Files | |
file | autogroup_form.php |
Auto group form. | |
file | behat_groups.php |
Behat groups-related steps definitions. | |
file | externallib.php |
External groups API. | |
file | group_details.php |
Group details page. | |
file | group_form.php |
A form for the creation and editing of groups. | |
file | group_updated.php |
Group updated event. | |
file | grouping_created.php |
Grouping created event. | |
file | grouping_form.php |
A form for creating and editing groupings. | |
file | grouplib.php |
file | import_form.php |
A form for group import. | |
file | index_page.php |
Group index page. | |
file | lib.php |
Extra library for groups and groupings. | |
file | renderer.php |
Renderers. | |
file | tabs.php |
Prints navigation tabs. | |
file | user_groups_editable.php |
Contains class core_group::output::user_groups_editable. | |
Namespaces | |
namespace | core\event |
| |
namespace | core_group\output |
| |
namespace | core_group\privacy |
| |
Classes | |
class | autogroup_form |
Auto group form class. More... | |
class | behat_groups |
class | core\event\group_updated |
Group updated event class. More... | |
class | core\event\grouping_created |
Grouping created event class. More... | |
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_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. More... | |
core_group_inplace_editable ($itemtype, $itemid, $newvalue) | |
Callback for inplace editable API. More... | |
groups_add_member ($grouporid, $userorid, $component=null, $itemid=0) | |
Adds a specified user to a group. More... | |
groups_allgroups_course_menu ($course, $urlroot, $update=false, $activegroup=0) | |
Generates html to print menu selector for course level, listing all groups. More... | |
groups_assign_grouping ($groupingid, $groupid, $timeadded=null, $invalidatecache=true) | |
Assigns group into grouping. More... | |
groups_cache_groupdata ($courseid, cache $cache=null) | |
Caches group data for a particular course to speed up subsequent requests. More... | |
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. More... | |
groups_create_group ($data, $editform=false, $editoroptions=false) | |
Add a new group. More... | |
groups_create_grouping ($data, $editoroptions=null) | |
Add a new grouping. More... | |
groups_delete_group ($grouporid) | |
Delete a group best effort, first removing members and links with courses and groupings. More... | |
groups_delete_group_members ($courseid, $userid=0, $unused=false) | |
Remove all users (or one user) from all groups in course. More... | |
groups_delete_grouping ($groupingorid) | |
Delete grouping. More... | |
groups_delete_groupings ($courseid, $showfeedback=false) | |
Delete all groupings from course. More... | |
groups_delete_groupings_groups ($courseid, $showfeedback=false) | |
Remove all groups from all groupings in course. More... | |
groups_delete_groups ($courseid, $showfeedback=false) | |
Delete all groups from course. More... | |
groups_get_activity_allowed_groups ($cm, $userid=0) | |
groups_get_activity_group ($cm, $update=false, $allowedgroups=null) | |
groups_get_activity_groupmode ($cm, $course=null) | |
groups_get_activity_shared_group_members ($cm, $userid=null) | |
Returns users who share group membership with the specified user in the given actiivty. More... | |
groups_get_all_groupings ($courseid) | |
groups_get_all_groups ($courseid, $userid=0, $groupingid=0, $fields='g.*', $withmembers=false) | |
groups_get_course_data ($courseid, cache $cache=null) | |
Gets group data for a course. More... | |
groups_get_course_group ($course, $update=false, $allowedgroups=null) | |
groups_get_course_groupmode ($course) | |
groups_get_group ($groupid, $fields=' *', $strictness=IGNORE_MISSING) | |
groups_get_group_by_idnumber ($courseid, $idnumber) | |
groups_get_group_by_name ($courseid, $name) | |
groups_get_group_name ($groupid) | |
groups_get_grouping ($groupingid, $fields=' *', $strictness=IGNORE_MISSING) | |
groups_get_grouping_by_idnumber ($courseid, $idnumber) | |
groups_get_grouping_by_name ($courseid, $name) | |
groups_get_grouping_members ($groupingid, $fields='u.*', $sort='lastname ASC') | |
groups_get_grouping_name ($groupingid) | |
groups_get_groups_members ($groupsids, $extrafields=null, $sort='lastname ASC') | |
Returns the users in the specified groups. More... | |
groups_get_members ($groupid, $fields='u.*', $sort='lastname ASC') | |
groups_get_members_by_role ($groupid, $courseid, $fields='u.*', $sort=null, $extrawheretest='', $whereorsortparams=array()) | |
Lists users in a group based on their role on the course. More... | |
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. More... | |
groups_get_members_join ($groupids, $useridcolumn, context $context=null, int $jointype=GROUPS_JOIN_ANY) | |
Get sql join to return users in a group. More... | |
groups_get_my_groups () | |
groups_get_possible_roles ($context) | |
Obtains a list of the possible roles that group members might come from, on a course. More... | |
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. More... | |
groups_get_user_groups ($courseid, $userid=0) | |
groups_group_exists ($groupid) | |
groups_group_visible ($groupid, $course, $cm=null, $userid=null) | |
Determine if a given group is visible to user or not in a given context. More... | |
groups_has_membership ($cm, $userid=null) | |
groups_is_member ($groupid, $userid=null) | |
groups_list_to_menu ($groups) | |
Turn an array of groups into an array of menu options. More... | |
groups_parse_name ($format, $groupnumber) | |
Parse a group name for characters to replace. More... | |
groups_print_activity_menu ($cm, $urlroot, $return=false, $hideallparticipants=false) | |
groups_print_course_menu ($course, $urlroot, $return=false) | |
groups_remove_member ($grouporid, $userorid) | |
Deletes the link between the specified user and group. More... | |
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. More... | |
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. More... | |
groups_sync_with_enrolment ($enrolname, $courseid=0, $gidfield='customint2') | |
Synchronises enrolments with the group membership. More... | |
groups_unassign_grouping ($groupingid, $groupid, $invalidatecache=true) | |
Unassigns group from grouping. More... | |
groups_update_group ($data, $editform=false, $editoroptions=false) | |
Update group. More... | |
groups_update_group_icon ($group, $data, $editform) | |
Update the group icon from form data. More... | |
groups_update_grouping ($data, $editoroptions=null) | |
Update grouping. More... | |
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. More... | |
Variables | |
$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) | |
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. | |
_group_verify_activegroup | ( | $courseid, | |
$groupmode, | |||
$groupingid, | |||
array | $allowedgroups | ||
) |
Internal method, sets up $SESSION->activegroup and verifies previous value.
int | $courseid | |
int | string | $groupmode | SEPARATEGROUPS, VISIBLEGROUPS or 'aag' (access all groups) |
int | $groupingid | 0 means all groups |
array | $allowedgroups | list of groups user can see |
core_group_inplace_editable | ( | $itemtype, | |
$itemid, | |||
$newvalue | |||
) |
Callback for inplace editable API.
string | $itemtype | - Only user_groups is supported. |
string | $itemid | - Userid and groupid separated by a : |
string | $newvalue | - json encoded list of groupids. |
core::output::inplace_editable |
groups_add_member | ( | $grouporid, | |
$userorid, | |||
$component = null , |
|||
$itemid = 0 |
|||
) |
Adds a specified user to a group.
mixed | $grouporid | The group id or group object |
mixed | $userorid | The user id or user object |
string | $component | Optional component name e.g. 'enrol_imsenterprise' |
int | $itemid | Optional itemid associated with component |
bool | True if user added successfully or the user is already a member of the group, false otherwise. |
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.
stdclass | $course | course object. |
string | moodle_url | $urlroot | return address. Accepts either a string or a moodle_url. |
bool | $update | set this to true to update current active group based on the group param. |
int | $activegroup | Change group active to this group if $update set to true. |
string | html or void |
groups_assign_grouping | ( | $groupingid, | |
$groupid, | |||
$timeadded = null , |
|||
$invalidatecache = true |
|||
) |
Assigns group into grouping.
int | groupingid | |
int | groupid | |
int | $timeadded | The time the group was added to the grouping. |
bool | $invalidatecache | If set to true the course group cache and the user group cache will be invalidated as well. |
bool | true or exception |
groups_cache_groupdata | ( | $courseid, | |
cache | $cache = null |
||
) |
Caches group data for a particular course to speed up subsequent requests.
int | $courseid | The course id to cache data for. |
cache | $cache | The cache if it has already been initialised. If not a new one will be created. |
stdClass | A data object containing groups, groupings, and mappings. |
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.
moodle_recordset | $rs | The record set (may be false) |
int | $context | ID of course context |
array | As described in groups_get_members_by_role |
groups_create_group | ( | $data, | |
$editform = false , |
|||
$editoroptions = false |
|||
) |
Add a new group.
stdClass | $data | group properties |
stdClass | $editform | |
array | $editoroptions |
id | of group or false if error |
groups_create_grouping | ( | $data, | |
$editoroptions = null |
|||
) |
Add a new grouping.
stdClass | $data | grouping properties |
array | $editoroptions |
id | of grouping or false if error |
groups_delete_group | ( | $grouporid | ) |
Delete a group best effort, first removing members and links with courses and groupings.
Removes group avatar too.
mixed | $grouporid | The id of group to delete or full group object |
bool | True if deletion was successful, false otherwise |
groups_delete_group_members | ( | $courseid, | |
$userid = 0 , |
|||
$unused = false |
|||
) |
Remove all users (or one user) from all groups in course.
int | $courseid | |
int | $userid | 0 means all users |
bool | $unused | - formerly $showfeedback, is no longer used. |
bool | success |
groups_delete_grouping | ( | $groupingorid | ) |
Delete grouping.
int | $groupingorid |
bool | success |
groups_delete_groupings | ( | $courseid, | |
$showfeedback = false |
|||
) |
Delete all groupings from course.
int | $courseid | |
bool | $showfeedback |
bool | success |
groups_delete_groupings_groups | ( | $courseid, | |
$showfeedback = false |
|||
) |
Remove all groups from all groupings in course.
int | $courseid | |
bool | $showfeedback |
bool | success |
groups_delete_groups | ( | $courseid, | |
$showfeedback = false |
|||
) |
Delete all groups from course.
int | $courseid | |
bool | $showfeedback |
bool | success |
groups_get_activity_shared_group_members | ( | $cm, | |
$userid = null |
|||
) |
Returns users who share group membership with the specified user in the given actiivty.
stdClass | cm_info | $cm | course module |
int | $userid | user id (empty for current user) |
array | a list of user |
groups_get_course_data | ( | $courseid, | |
cache | $cache = null |
||
) |
Gets group data for a course.
This returns an object with the following properties:
int | $courseid | The course id to get data for. |
cache | $cache | The cache if it has already been initialised. If not a new one will be created. |
stdClass |
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.
array | $groupsids | The list of groups ids to check |
array | $extrafields | extra fields to be included in result |
int | $sort | optional sorting of returned users |
array|bool | Returns an array of the users for the specified group or false if no users or an error returned. |
groups_get_members_by_role | ( | $groupid, | |
$courseid, | |||
$fields = 'u.*' , |
|||
$sort = null , |
|||
$extrawheretest = '' , |
|||
$whereorsortparams = array() |
|||
) |
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.
int | $groupid | |
int | $courseid | Course ID (should match the group's course) |
string | $fields | List of fields from user table prefixed with u, default 'u.*' |
string | $sort | SQL ORDER BY clause, default (when null passed) is what comes from users_order_by_sql. |
string | $extrawheretest | extra SQL conditions ANDed with the existing where clause. |
array | $whereorsortparams | any parameters required by $extrawheretest (named parameters). |
array | Complex array as described above |
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.
int | array | $groupids | Where this is an array of multiple groups, it will match on members of any of the groups |
context | $context | Course context or a context within a course. Mandatory when $groupid = USERSWITHOUTGROUP |
int | $groupsjointype | Join type logic used. Defaults to 'Any' (logical OR). |
array($sql,$params) |
coding_exception | if empty or invalid context submitted when $groupid = USERSWITHOUTGROUP |
groups_get_members_join | ( | $groupids, | |
$useridcolumn, | |||
context | $context = null , |
||
int | $jointype = GROUPS_JOIN_ANY |
||
) |
Get sql join to return users in a group.
int | array | $groupids | The groupids, 0 or [] means all groups and USERSWITHOUTGROUP no group |
string | $useridcolumn | The column of the user id from the calling SQL, e.g. u.id |
context | $context | Course context or a context within a course. Mandatory when $groupids includes USERSWITHOUTGROUP |
int | $jointype | Join type logic used. Defaults to 'Any' (logical OR). |
core::dml::sql_join | Contains joins, wheres, params |
coding_exception | if empty or invalid context submitted when $groupid = USERSWITHOUTGROUP |
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.
context | $context | Context of course |
Array | of role ID integers, or false if error/none. |
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.
int | $courseid | The id of the course |
int | $roleid | The role to select users from |
mixed | $source | restrict to cohort, grouping or group id |
string | $orderby | The column to sort users by |
int | $notingroup | restrict to users not in existing groups |
bool | $onlyactiveenrolments | restrict to users who have an active enrolment in the course |
array | $extrafields | Extra user fields to return |
array | An array of the users |
groups_group_visible | ( | $groupid, | |
$course, | |||
$cm = null , |
|||
$userid = null |
|||
) |
Determine if a given group is visible to user or not in a given context.
int | $groupid | Group id to test. 0 for all groups. |
stdClass | $course | Course object. |
stdClass | $cm | Course module object. |
int | $userid | user id to test against. Defaults to $USER. |
boolean | true if visible, false otherwise |
groups_list_to_menu | ( | $groups | ) |
Turn an array of groups into an array of menu options.
array | $groups | of group objects. |
array | groupid => formatted group name. |
groups_parse_name | ( | $format, | |
$groupnumber | |||
) |
Parse a group name for characters to replace.
string | $format | The format a group name will follow |
int | $groupnumber | The number of the group to be used in the parsed format string |
string | the parsed format string |
groups_remove_member | ( | $grouporid, | |
$userorid | |||
) |
Deletes the link between the specified user and group.
mixed | $grouporid | The group id or group object |
mixed | $userorid | The user id or user object |
bool | True if deletion was successful, false otherwise |
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.
mixed | $grouporid | The group id or group object |
mixed | $userorid | The user id or user object |
bool | True if permitted, false otherwise |
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.
array | $allowedgroups | All groups user is allowed to see |
array | $usergroups | Groups user belongs to |
array |
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 .
string | $enrolname | name of enrolment method without prefix |
int | $courseid | course id where sync needs to be performed (0 for all courses) |
string | $gidfield | name of the field in 'enrol' table that stores group id |
array | Returns the list of removed and added users. Each record contains fields: userid, enrolid, courseid, groupid, groupname |
groups_unassign_grouping | ( | $groupingid, | |
$groupid, | |||
$invalidatecache = true |
|||
) |
Unassigns group from grouping.
int | groupingid | |
int | groupid | |
bool | $invalidatecache | If set to true the course group cache and the user group cache will be invalidated as well. |
bool | success |
groups_update_group | ( | $data, | |
$editform = false , |
|||
$editoroptions = false |
|||
) |
Update group.
stdClass | $data | group properties (with magic quotes) |
stdClass | $editform | |
array | $editoroptions |
bool | true or exception |
groups_update_group_icon | ( | $group, | |
$data, | |||
$editform | |||
) |
Update the group icon from form data.
stdClass | $group | group information |
stdClass | $data | |
stdClass | $editform |
groups_update_grouping | ( | $data, | |
$editoroptions = null |
|||
) |
Update grouping.
stdClass | $data | grouping properties (with magic quotes) |
array | $editoroptions |
bool | true or exception |
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.
stdClass | $course | Course object. |
int | $userid | user id to check against. |
stdClass | $cm | Course module object. Optional, just for checking at activity level instead course one. |
boolean | true if visible, false otherwise |
$row[] |