MDL-68169 user: Add roles filter

Part of MDL-67743
This commit is contained in:
Andrew Nicols 2020-04-03 15:00:42 +08:00
parent f14df62d1a
commit ffc933ad46

View file

@ -66,6 +66,10 @@ class participants_filter implements renderable, templatable {
$filtertypes[] = $filtertype; $filtertypes[] = $filtertype;
} }
if ($filtertype = $this->get_roles_filter()) {
$filtertypes[] = $filtertype;
}
return $filtertypes; 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. * Export the renderer data in a mustache template friendly format.
* *