Merge branch 'MDL-61891-33' of git://github.com/andrewnicols/moodle into MOODLE_33_STABLE

This commit is contained in:
David Monllao
2018-04-23 11:55:40 +02:00
3 changed files with 35 additions and 52 deletions
+1 -26
View File
@@ -66,23 +66,6 @@ class provider implements
static::call_plugin_method('export_plagiarism_user_data', [$userid, $context, $subcontext, $linkarray]);
}
/**
* Checks whether the component's provider class implements the specified interface.
* This can either be implemented directly, or by implementing a descendant (extension) of the specified interface.
*
* @param string $component the frankenstyle component name.
* @param string $interface the name of the interface we want to check.
* @return bool True if an implementation was found, false otherwise.
*/
protected static function component_implements($providerclass, $interface) {
if (class_exists($providerclass)) {
$rc = new \ReflectionClass($providerclass);
return $rc->implementsInterface($interface);
}
return false;
}
/**
* Deletes all user content for a context in all plagiarism plugins.
*
@@ -110,14 +93,6 @@ class provider implements
*/
protected static function call_plugin_method($methodname, $params) {
// Note: Even if plagiarism is _now_ disabled, there may be legacy data to export.
$plugins = \core_component::get_plugin_list('plagiarism');
foreach (array_keys($plugins) as $plugin) {
$component = "plagiarism_{$plugin}";
$classname = manager::get_provider_classname_for_component($component);
if (static::component_implements($classname, plagiarism_provider::class)) {
// This plagiarism plugin implements the plagiarism_provider.
component_class_callback($classname, $methodname, $params);
}
}
\core_privacy\manager::plugintype_class_callback('plagiarism', plagiarism_provider::class, $methodname, $params);
}
}
+1 -26
View File
@@ -83,23 +83,6 @@ class provider implements
static::call_plugin_method('delete_portfolio_for_user', [$userid, $context]);
}
/**
* Checks whether the component's provider class implements the specified interface.
* This can either be implemented directly, or by implementing a descendant (extension) of the specified interface.
*
* @param string $providerclass the provider class name.
* @param string $interface the name of the interface we want to check.
* @return bool True if an implementation was found, false otherwise.
*/
protected static function component_implements($providerclass, $interface) {
if (class_exists($providerclass)) {
$rc = new \ReflectionClass($providerclass);
return $rc->implementsInterface($interface);
}
return false;
}
/**
* Internal method for looping through all of the portfolio plugins and calling a method.
*
@@ -108,14 +91,6 @@ class provider implements
*/
protected static function call_plugin_method($methodname, $params) {
// Note: Even if portfolio is _now_ disabled, there may be legacy data to export.
$plugins = \core_component::get_plugin_list('portfolio');
foreach (array_keys($plugins) as $plugin) {
$component = "portfolio_{$plugin}";
$classname = manager::get_provider_classname_for_component($component);
if (static::component_implements($classname, portfolio_provider::class)) {
// This portfolio plugin implements the portfolio_provider.
component_class_callback($classname, $methodname, $params);
}
}
\core_privacy\manager::plugintype_class_callback('portfolio', portfolio_provider::class, $methodname, $params);
}
}
+33
View File
@@ -346,4 +346,37 @@ class manager {
}
return false;
}
/**
* Call the named method with the specified params on any plugintype implementing the relevant interface.
*
* @param string $plugintype The plugingtype to check
* @param string $interface The interface to implement
* @param string $methodname The method to call
* @param array $params The params to call
*/
public static function plugintype_class_callback(string $plugintype, string $interface, string $methodname, array $params) {
$components = \core_component::get_plugin_list($plugintype);
foreach (array_keys($components) as $component) {
static::component_class_callback("{$plugintype}_{$component}", $interface, $methodname, $params);
}
}
/**
* Call the named method with the specified params on the supplied component if it implements the relevant interface on its provider.
*
* @param string $component The component to call
* @param string $interface The interface to implement
* @param string $methodname The method to call
* @param array $params The params to call
* @return mixed
*/
public static function component_class_callback(string $component, string $interface, string $methodname, array $params) {
$classname = static::get_provider_classname_for_component($component);
if (class_exists($classname) && is_subclass_of($classname, $interface)) {
return component_class_callback($classname, $methodname, $params);
}
return null;
}
}