Commit fb073f60 authored by tjhunt's avatar tjhunt
Browse files

adminlib: MDL-19038 lazy-load the list of users in admin_setting_users_with_capability

parent eef76074
......@@ -2161,17 +2161,25 @@ class admin_setting_users_with_capability extends admin_setting_configmultiselec
* @param array $defaultsetting array of usernames
* @param string $capability string capability name.
public function __construct($name, $visiblename, $description, $defaultsetting, $capability) {
function __construct($name, $visiblename, $description, $defaultsetting, $capability) {
$this->capability = $capability;
parent::__construct($name, $visiblename, $description, $defaultsetting, NULL);
function load_choices() {
if (is_array($this->choices)) {
return true;
$users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM),
$capability, ',u.username,u.firstname,u.lastname', 'u.lastname,u.firstname');
$choices = array(
$this->capability, ',u.username,u.firstname,u.lastname', 'u.lastname,u.firstname');
$this->choices = array(
'$@NONE@$' => get_string('nobody'),
'$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($capability)),
'$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($this->capability)),
foreach ($users as $user) {
$choices[$user->username] = fullname($user);
$this->choices[$user->username] = fullname($user);
parent::__construct($name, $visiblename, $description, $defaultsetting, $choices);
return true;
public function get_defaultsetting() {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment