mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-27123 adds a new admin_setting_configmultiselect_modules class
and uses it on the module security page. This saves one DB query per page for users who can see the admin tree in the settings nav.
This commit is contained in:
parent
91787c37e1
commit
7351b54e86
@ -91,14 +91,9 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
'all' => get_string('fulllistofcourses'),
|
||||
'requested' => get_string('requestedcourses'))));
|
||||
$temp->add(new admin_setting_configcheckbox('restrictbydefault', get_string('restrictbydefault', 'admin'), get_string('configrestrictbydefault', 'admin'), 0));
|
||||
if (!$options = $DB->get_records('modules')) {
|
||||
$options = array();
|
||||
}
|
||||
$options2 = array();
|
||||
foreach ($options as $option) {
|
||||
$options2[$option->id] = $option->name;
|
||||
}
|
||||
$temp->add(new admin_setting_configmultiselect('defaultallowedmodules', get_string('defaultallowedmodules', 'admin'), get_string('configdefaultallowedmodules', 'admin'), array(), $options2));
|
||||
$temp->add(new admin_setting_configmultiselect_modules('defaultallowedmodules',
|
||||
get_string('defaultallowedmodules', 'admin'),
|
||||
get_string('configdefaultallowedmodules', 'admin')));
|
||||
$ADMIN->add('security', $temp);
|
||||
|
||||
|
||||
|
@ -7309,3 +7309,38 @@ class admin_setting_configcolourpicker extends admin_setting {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiselect for current modules
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class admin_setting_configmultiselect_modules extends admin_setting_configmultiselect {
|
||||
/**
|
||||
* Calls parent::__construct - note array $choices is not required
|
||||
*/
|
||||
public function __construct($name, $visiblename, $description) {
|
||||
parent::__construct($name, $visiblename, $description, array(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an array of current module choices
|
||||
*
|
||||
* @return bool always return true
|
||||
*/
|
||||
public function load_choices() {
|
||||
if (is_array($this->choices)) {
|
||||
return true;
|
||||
}
|
||||
$this->choices = array();
|
||||
|
||||
global $CFG, $DB;
|
||||
$records = $DB->get_records('modules', array('visible'=>1), 'name');
|
||||
foreach ($records as $record) {
|
||||
if (file_exists("$CFG->dirroot/mod/$record->name/lib.php")) {
|
||||
$this->choices[$record->id] = $record->name;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user