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:
John Beedell 2011-04-11 11:22:32 +01:00 committed by Tim Hunt
parent 91787c37e1
commit 7351b54e86
2 changed files with 38 additions and 8 deletions

View File

@ -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);

View File

@ -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;
}
}