diff --git a/user/classes/output/participants_filter.php b/user/classes/output/participants_filter.php index 12dddd63dcd..21c1ec003ab 100644 --- a/user/classes/output/participants_filter.php +++ b/user/classes/output/participants_filter.php @@ -66,6 +66,10 @@ class participants_filter implements renderable, templatable { $filtertypes[] = $filtertype; } + if ($filtertype = $this->get_roles_filter()) { + $filtertypes[] = $filtertype; + } + return $filtertypes; } @@ -98,6 +102,35 @@ class participants_filter implements renderable, templatable { ); } + /** + * Get data for the roles filter. + * + * @return stdClass|null + */ + protected function get_roles_filter(): ?stdClass { + $roles = []; + $roles += [-1 => get_string('noroles', 'role')]; + $roles += get_viewable_roles($this->context); + + if (has_capability('moodle/role:assign', $this->context)) { + $roles += get_assignable_roles($this->context, ROLENAME_ALIAS); + } + + return $this->get_filter_object( + 'roles', + get_string('roles', 'core_role'), + false, + true, + null, + array_map(function($id, $title) { + return (object) [ + 'value' => $id, + 'title' => $title, + ]; + }, array_keys($roles), array_values($roles)) + ); + } + /** * Export the renderer data in a mustache template friendly format. *