MDL-35260 Course formats may have settings, be enabled, disabled and uninstalled
This commit is contained in:
@@ -3362,3 +3362,61 @@ class plugininfo_webservice extends plugininfo_base {
|
||||
array('sesskey' => sesskey(), 'action' => 'uninstall', 'webservice' => $this->name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for course formats
|
||||
*/
|
||||
class plugininfo_format extends plugininfo_base {
|
||||
|
||||
/**
|
||||
* Gathers and returns the information about all plugins of the given type
|
||||
*
|
||||
* @param string $type the name of the plugintype, eg. mod, auth or workshopform
|
||||
* @param string $typerootdir full path to the location of the plugin dir
|
||||
* @param string $typeclass the name of the actually called class
|
||||
* @return array of plugintype classes, indexed by the plugin name
|
||||
*/
|
||||
public static function get_plugins($type, $typerootdir, $typeclass) {
|
||||
global $CFG;
|
||||
$formats = parent::get_plugins($type, $typerootdir, $typeclass);
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
$order = get_sorted_course_formats();
|
||||
$sortedformats = array();
|
||||
foreach ($order as $formatname) {
|
||||
$sortedformats[$formatname] = $formats[$formatname];
|
||||
}
|
||||
return $sortedformats;
|
||||
}
|
||||
|
||||
public function get_settings_section_name() {
|
||||
return 'formatsetting' . $this->name;
|
||||
}
|
||||
|
||||
public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
|
||||
global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them
|
||||
$ADMIN = $adminroot; // also may be used in settings.php
|
||||
$section = $this->get_settings_section_name();
|
||||
|
||||
$settings = null;
|
||||
if ($hassiteconfig && file_exists($this->full_path('settings.php'))) {
|
||||
$settings = new admin_settingpage($section, $this->displayname,
|
||||
'moodle/site:config', $this->is_enabled() === false);
|
||||
include($this->full_path('settings.php')); // this may also set $settings to null
|
||||
}
|
||||
if ($settings) {
|
||||
$ADMIN->add($parentnodename, $settings);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_enabled() {
|
||||
return !get_config($this->component, 'disabled');
|
||||
}
|
||||
|
||||
public function get_uninstall_url() {
|
||||
if ($this->name !== get_config('moodlecourse', 'format') && $this->name !== 'site') {
|
||||
return new moodle_url('/admin/courseformats.php',
|
||||
array('sesskey' => sesskey(), 'action' => 'uninstall', 'format' => $this->name));
|
||||
}
|
||||
return parent::get_uninstall_url();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user