This commit is contained in:
Andrew Nicols
2023-02-23 09:14:03 +08:00
4 changed files with 27 additions and 26 deletions
@@ -20,7 +20,6 @@ namespace core_reportbuilder\external;
use core_collator;
use core_component;
use core_plugin_manager;
use renderer_base;
use core_reportbuilder\local\audiences\base;
@@ -52,15 +51,8 @@ class custom_report_audience_cards_exporter extends custom_report_menu_cards_exp
continue;
}
// The name of each card will be the component the audience belongs to.
[$component] = explode('\\', $class);
if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
$componentname = $plugininfo->displayname;
} else {
$componentname = get_string('site');
}
// New menu card per component.
$componentname = $audience->get_component_displayname();
if (!array_key_exists($componentname, $menucards)) {
$menucards[$componentname] = [
'name' => $componentname,
+24 -8
View File
@@ -22,6 +22,7 @@ use core_plugin_manager;
use MoodleQuickForm;
use stdClass;
use core\output\notification;
use core_reportbuilder\local\helpers\database;
use core_reportbuilder\local\models\audience;
use core_reportbuilder\report_access_exception;
@@ -89,11 +90,27 @@ abstract class base {
return $instance;
}
/**
* Return display name of the component the audience belongs to
*
* @return string
*/
final public function get_component_displayname(): string {
[$component] = explode('\\', get_class($this));
if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
return $plugininfo->displayname;
}
// Return generic site text for those audiences belonging to core subsystems.
return get_string('site');
}
/**
* Helps to build SQL to retrieve users that matches the current audience
*
* Implementations must use api::generate_alias() for table/column aliases
* and api::generate_param_name() for named parameters
* Implementations must use {@see database::generate_alias} and {@see database::generate_param_name} for table/column
* aliases and parameter names
*
* @param string $usertablealias
* @return array array of three elements [$join, $where, $params]
@@ -104,15 +121,14 @@ abstract class base {
* Returns string for audience category.
*
* @return string
*
* @deprecated since Moodle 4.2 - please do not use this function any more, {@see get_component_displayname}
*/
final public function get_category(): string {
[$component] = explode('\\', get_class($this));
debugging('The function ' . __FUNCTION__ . '() is deprecated, please do not use it any more. ' .
'See class \'get_component_displayname\' method for replacement', DEBUG_DEVELOPER);
if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
return $plugininfo->displayname;
}
return get_string('site');
return $this->get_component_displayname();
}
/**
@@ -23,7 +23,6 @@ use context;
use context_system;
use core_collator;
use core_component;
use core_plugin_manager;
use core_reportbuilder\local\audiences\base;
use core_reportbuilder\local\models\audience as audience_model;
@@ -242,14 +241,7 @@ class audience {
foreach ($audiences as $class => $path) {
$audienceclass = $class::instance();
if (is_subclass_of($class, base::class) && $audienceclass->user_can_add()) {
[$component] = explode('\\', $class);
if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
$componentname = $plugininfo->displayname;
} else {
$componentname = get_string('site');
}
$componentname = $audienceclass->get_component_displayname();
$sources[$componentname][$class] = $audienceclass->get_name();
}
}
+1
View File
@@ -16,6 +16,7 @@ Information provided here is intended especially for developers.
during tests
* The `datasource_stress_test_columns` test helper now enables sorting on those columns that support it
* The `create_[column|filter|condition]` test generator methods now allow for setting all persistent properties
* The `get_category` method of the base audience class has been deprecated, callers should instead use `get_component_displayname`
=== 4.1 ===