$return = new moodle_url('/admin/settings.php', array('section' => 'manageformats'));
-$allplugins = plugin_manager::instance()->get_plugins();
-$formatplugins = $allplugins['format'];
+$formatplugins = plugin_manager::instance()->get_plugins_of_type('format');
$sortorder = array_flip(array_keys($formatplugins));
if (!isset($formatplugins[$formatname])) {
if (parent::is_related($query)) {
return true;
}
- $allplugins = plugin_manager::instance()->get_plugins();
- $formats = $allplugins['format'];
+ $formats = plugin_manager::instance()->get_plugins_of_type('format');
foreach ($formats as $format) {
if (strpos($format->component, $query) !== false ||
strpos(textlib::strtolower($format->displayname), $query) !== false) {
$return = $OUTPUT->heading(new lang_string('courseformats'), 3, 'main');
$return .= $OUTPUT->box_start('generalbox formatsui');
- $allplugins = plugin_manager::instance()->get_plugins();
- $formats = $allplugins['format'];
+ $formats = plugin_manager::instance()->get_plugins_of_type('format');
// display strings
$txt = get_strings(array('settings', 'name', 'enable', 'disable', 'up', 'down', 'default', 'delete'));
unset($settings);
require_once("$CFG->libdir/pluginlib.php");
-$allplugins = plugin_manager::instance()->get_plugins();
-foreach ($allplugins['tinymce'] as $plugin) {
+foreach (plugin_manager::instance()->get_plugins_of_type('tinymce') as $plugin) {
$plugin->load_settings($ADMIN, 'editortinymce', $hassiteconfig);
}
return $this->reorder_plugin_types(get_plugin_types($fullpaths));
}
+ /**
+ * Returns list of known plugins of the given type
+ *
+ * This method returns the subset of the tree returned by {@link self::get_plugins()}.
+ * If the given type is not known, empty array is returned.
+ *
+ * @param string $type plugin type, e.g. 'mod' or 'workshopallocation'
+ * @param bool $disablecache force reload, cache can be used otherwise
+ * @return array (string)plugin name (e.g. 'workshop') => corresponding subclass of {@link plugininfo_base}
+ */
+ public function get_plugins_of_type($type, $disablecache=false) {
+
+ $plugins = $this->get_plugins($disablecache);
+
+ if (!isset($plugins[$type])) {
+ return array();
+ }
+
+ return $plugins[$type];
+ }
+
/**
* Returns a tree of known plugins and information about them
*
return $this->pluginsinfo;
}
+ /**
+ * Returns list of all known subplugins of the given plugin
+ *
+ * For plugins that do not provide subplugins (i.e. there is no support for it),
+ * empty array is returned.
+ *
+ * @param string $component full component name, e.g. 'mod_workshop'
+ * @param bool $disablecache force reload, cache can be used otherwise
+ * @return array (string) component name (e.g. 'workshopallocation_random') => subclass of {@link plugininfo_base}
+ */
+ public function get_subplugins_of_plugin($component, $disablecache=false) {
+
+ $pluginfo = $this->get_plugin_info($component, $disablecache);
+
+ if (is_null($pluginfo)) {
+ return array();
+ }
+
+ $subplugins = $this->get_subplugins($disablecache);
+
+ if (!isset($subplugins[$pluginfo->component])) {
+ return array();
+ }
+
+ $list = array();
+
+ foreach ($subplugins[$pluginfo->component] as $subdata) {
+ foreach ($this->get_plugins_of_type($subdata->type) as $subpluginfo) {
+ $list[$subpluginfo->component] = $subpluginfo;
+ }
+ }
+
+ return $list;
+ }
+
/**
* Returns list of plugins that define their subplugins and the information
* about them from the db/subplugins.php file.
}
/**
+ * Returns information about the known plugin, or null
+ *
* @param string $component frankenstyle component name.
+ * @param bool $disablecache force reload, cache can be used otherwise
* @return plugininfo_base|null the corresponding plugin information.
*/
- public function get_plugin_info($component) {
+ public function get_plugin_info($component, $disablecache=false) {
list($type, $name) = $this->normalize_component($component);
- $plugins = $this->get_plugins();
+ $plugins = $this->get_plugins($disablecache);
if (isset($plugins[$type][$name])) {
return $plugins[$type][$name];
} else {
$this->assertTrue($pluginman instanceof testable_plugin_manager);
}
+ public function test_get_plugins_of_type() {
+ $pluginman = testable_plugin_manager::instance();
+ $mods = $pluginman->get_plugins_of_type('mod');
+ $this->assertEquals('array', gettype($mods));
+ $this->assertEquals(2, count($mods));
+ $this->assertTrue($mods['foo'] instanceof testable_plugininfo_mod);
+ $this->assertTrue($mods['bar'] instanceof testable_plugininfo_mod);
+ $foolishes = $pluginman->get_plugins_of_type('foolish');
+ $this->assertEquals(1, count($foolishes));
+ $this->assertTrue($foolishes['frog'] instanceof testable_pluginfo_foolish);
+ $unknown = $pluginman->get_plugins_of_type('muhehe');
+ $this->assertSame(array(), $unknown);
+ }
+
public function test_get_plugins() {
$pluginman = testable_plugin_manager::instance();
$plugins = $pluginman->get_plugins();
+ $this->assertEquals('array', gettype($plugins));
$this->assertTrue(isset($plugins['mod']['foo']));
$this->assertTrue(isset($plugins['mod']['bar']));
$this->assertTrue(isset($plugins['foolish']['frog']));
$this->assertTrue($plugins['foolish']['frog'] instanceof testable_pluginfo_foolish);
}
+ public function test_get_subplugins_of_plugin() {
+ $pluginman = testable_plugin_manager::instance();
+ $this->assertSame(array(), $pluginman->get_subplugins_of_plugin('mod_missing'));
+ $this->assertSame(array(), $pluginman->get_subplugins_of_plugin('mod_bar'));
+ $foosubs = $pluginman->get_subplugins_of_plugin('mod_foo');
+ $this->assertEquals('array', gettype($foosubs));
+ $this->assertEquals(1, count($foosubs));
+ $this->assertTrue($foosubs['foolish_frog'] instanceof testable_pluginfo_foolish);
+ }
+
public function test_get_subplugins() {
$pluginman = testable_plugin_manager::instance();
$subplugins = $pluginman->get_subplugins();
* Additional (optional) param $onlyactive has been added to get_enrolled_users, count_enrolled_users
functions to get information for only active (excluding suspended enrolments) users. Included two
helper functions extract_suspended_users, get_suspended_userids to extract suspended user information.
+* The plugin_manager class now provides two new helper methods for getting information
+ about known plugins: get_plugins_of_type() and get_subplugins_of_plugin().
Database (DML) layer:
* $DB->sql_empty() is deprecated, you have to use sql parameters with empty values instead,