From ffc933ad468aa8010d1ea9a9444ba264af95e476 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 3 Apr 2020 15:00:42 +0800 Subject: [PATCH] MDL-68169 user: Add roles filter Part of MDL-67743 --- user/classes/output/participants_filter.php | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) 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. * -- 2.43.0