Merge branch 'MDL-59831_master' of git://github.com/markn86/moodle
authorDavid Monllao <davidm@moodle.com>
Tue, 12 Sep 2017 06:07:52 +0000 (08:07 +0200)
committerDavid Monllao <davidm@moodle.com>
Tue, 12 Sep 2017 06:07:52 +0000 (08:07 +0200)
user/index.php
user/renderer.php
user/templates/unified_filter.mustache

index 3b1961c..d556a4b 100644 (file)
@@ -103,6 +103,7 @@ echo $OUTPUT->heading(get_string('participants'));
 
 // 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;
@@ -168,9 +169,19 @@ foreach ($filtersapplied as $filter) {
     }
 }
 
-// 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.
index b7986d4..d881f0c 100644 (file)
@@ -265,8 +265,8 @@ class core_user_renderer extends plugin_renderer_base {
 
         // 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.
index a656247..6b650fa 100644 (file)
@@ -58,6 +58,7 @@
             <option value="{{value}}" {{#selected}}selected="selected"{{/selected}}>{{{label}}}</option>
         {{/filteroptions}}
     </select>
+    <input type="hidden" name="unified-filter-submitted" value="1">
     <input type="submit" class="btn btn-primary" id="user-filter-button" value={{#quote}}{{#str}}filter{{/str}}{{/quote}}>
 </form>
 {{#js}}