// Get the currently applied filters.
$filtersapplied = optional_param_array('unified-filters', [], PARAM_TEXT);
+$filterwassubmitted = optional_param('unified-filter-submitted', 0, PARAM_BOOL);
// Default group ID.
$groupid = false;
}
}
-// If course supports groups, but the user can't access all groups and there's no group filter set, apply a default group filter.
-if ($groupid !== false && !$canaccessallgroups && !$hasgroupfilter) {
- $filtersapplied[] = USER_FILTER_GROUP . ':' . $groupid;
+// If course supports groups we may need to set a default.
+if ($groupid !== false) {
+ // If we are in a course with visible groups and the user has not submitted anything and does not have
+ // access to all groups, then set a default group. This is the same behaviour in 3.3.
+ if (!$canaccessallgroups && !$filterwassubmitted && $course->groupmode == VISIBLEGROUPS) {
+ $filtersapplied[] = USER_FILTER_GROUP . ':' . $groupid;
+ } else if (!$canaccessallgroups && !$hasgroupfilter && $course->groupmode != VISIBLEGROUPS) {
+ // The user can't access all groups and has not set a group filter in a course where the groups are not visible
+ // then apply a default group filter.
+ $filtersapplied[] = USER_FILTER_GROUP . ':' . $groupid;
+ } else if (!$hasgroupfilter) { // No need for the group id to be set.
+ $groupid = false;
+ }
}
// Manage enrolments.
// Filter options for groups, if available.
if ($course->groupmode != NOGROUPS) {
- if (has_capability('moodle/site:accessallgroups', $context)) {
- // List all groups if the user can access all groups.
+ if (has_capability('moodle/site:accessallgroups', $context) || $course->groupmode == VISIBLEGROUPS) {
+ // List all groups if the user can access all groups, or we are in visible group mode.
$groups = $manager->get_all_groups();
} else {
// Otherwise, just list the groups the user belongs to.