* @param int $courseid The course id
* @param int $groupid The groupid, 0 means all groups and USERSWITHOUTGROUP no group
* @param int $accesssince The time since last access, 0 means any time
- * @param int $roleid The role id, 0 means all roles
+ * @param int $roleid The role id, 0 means all roles and -1 no roles
* @param int $enrolid The enrolment id, 0 means all enrolment methods will be returned.
* @param int $statusid The user enrolment status, -1 means all enrolments regardless of the status will be returned, if allowed.
* @param string|array $search The search that was performed, empty means perform no search
list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($context->get_parent_context_ids(true),
SQL_PARAMS_NAMED, 'relatedctx');
- $wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $relatedctxsql)";
- $params = array_merge($params, array('roleid' => $roleid), $relatedctxparams);
+ // Get users without any role.
+ if ($roleid == -1) {
+ $wheres[] = "u.id NOT IN (SELECT userid FROM {role_assignments} WHERE contextid $relatedctxsql)";
+ $params = array_merge($params, $relatedctxparams);
+ } else {
+ $wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $relatedctxsql)";
+ $params = array_merge($params, array('roleid' => $roleid), $relatedctxparams);
+ }
}
if (!empty($search)) {
}
$criteria = get_string('role');
- $roleoptions = [];
+ $roleoptions = $this->format_filter_option(USER_FILTER_ROLE, $criteria, -1, get_string('noroles', 'role'));
foreach ($roles as $id => $role) {
$roleoptions += $this->format_filter_option(USER_FILTER_ROLE, $criteria, $id, $role);
}
| Group: Group A | Student 1 | Student 2 | | Student 3 | XX-IGNORE-XX |
| Group: Group B | Student 2 | | | Student 1 | Student 3 |
+ @javascript
+ Scenario: Filter users who have no role in a course
+ Given I log in as "teacher1"
+ And I am on "Course 1" course homepage
+ And I navigate to course participants
+ And I click on "Student 1's role assignments" "link"
+ And I click on ".form-autocomplete-selection [aria-selected=true]" "css_element"
+ And I press key "27" in the field "Student 1's role assignments"
+ And I click on "Save changes" "link"
+ When I open the autocomplete suggestions list
+ And I click on "Role: No roles" item in the autocomplete list
+ Then I should see "Student 1" in the "participants" "table"
+ And I should not see "Student 2" in the "participants" "table"
+ And I should not see "Student 3" in the "participants" "table"
+ And I should not see "Student 4" in the "participants" "table"
+ And I should not see "Teacher 1" in the "participants" "table"
+
@javascript
Scenario: Multiple filters applied
Given I log in as "teacher1"