mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-68169 user: Add roles filter
Part of MDL-67743
This commit is contained in:
parent
f14df62d1a
commit
ffc933ad46
1 changed files with 33 additions and 0 deletions
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue