Skip to content

Commit

Permalink
Merge branch 'MDL-76815' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Feb 23, 2023
2 parents 9f31d4c + b3a50f4 commit 5a896a7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use core_collator;
use core_component;
use core_plugin_manager;
use renderer_base;
use core_reportbuilder\local\audiences\base;

Expand Down Expand Up @@ -52,15 +51,8 @@ protected function get_other_values(renderer_base $output): array {
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,
Expand Down
32 changes: 24 additions & 8 deletions reportbuilder/classes/local/audiences/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;

Expand Down Expand Up @@ -89,11 +90,27 @@ final public static function create(int $reportid, array $configdata): self {
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]
Expand All @@ -104,15 +121,14 @@ abstract public function get_sql(string $usertablealias): array;
* 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();
}

/**
Expand Down
10 changes: 1 addition & 9 deletions reportbuilder/classes/local/helpers/audience.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;

Expand Down Expand Up @@ -242,14 +241,7 @@ private static function get_audience_types(): array {
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();
}
}
Expand Down
1 change: 1 addition & 0 deletions reportbuilder/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===

Expand Down

0 comments on commit 5a896a7

Please sign in to comment.