mirror of
https://github.com/moodle/moodle.git
synced 2025-03-28 03:22:38 +01:00
Merge branch 'MDL-76690' of https://github.com/paulholden/moodle
This commit is contained in:
commit
44db44564e
@ -22,6 +22,7 @@ use core_plugin_manager;
|
||||
use MoodleQuickForm;
|
||||
use stdClass;
|
||||
use core\output\notification;
|
||||
use core_reportbuilder\external\custom_report_audience_cards_exporter;
|
||||
use core_reportbuilder\local\helpers\database;
|
||||
use core_reportbuilder\local\models\audience;
|
||||
use core_reportbuilder\report_access_exception;
|
||||
@ -48,7 +49,8 @@ abstract class base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an existing instance of audience with persistent
|
||||
* Creates an instance of audience type, with persistent. Typically by loading an existing record, however in the absence of
|
||||
* specified classname (in the case of {@see custom_report_audience_cards_exporter}) we create one based on the current class
|
||||
*
|
||||
* @param int $id
|
||||
* @param null|stdClass $record
|
||||
@ -56,9 +58,9 @@ abstract class base {
|
||||
*/
|
||||
final public static function instance(int $id = 0, ?stdClass $record = null): ?self {
|
||||
$persistent = new audience($id, $record);
|
||||
// Needed for get_audience_types() method.
|
||||
|
||||
// Populate persistent classname automatically if not set (e.g. when not loading an existing instance).
|
||||
if (!$classname = $persistent->get('classname')) {
|
||||
// Use the called class name.
|
||||
$classname = get_called_class();
|
||||
$persistent->set('classname', $classname);
|
||||
}
|
||||
|
@ -255,66 +255,10 @@ class audience {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of audiences types in the system.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function get_audience_types(): array {
|
||||
$sources = [];
|
||||
|
||||
$audiences = core_component::get_component_classes_in_namespace(null, 'reportbuilder\\audience');
|
||||
foreach ($audiences as $class => $path) {
|
||||
$audienceclass = $class::instance();
|
||||
if (is_subclass_of($class, base::class) && $audienceclass->user_can_add()) {
|
||||
$componentname = $audienceclass->get_component_displayname();
|
||||
$sources[$componentname][$class] = $audienceclass->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
return $sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the audiences types the current user can add to, organised by categories.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @deprecated since Moodle 4.1 - please do not use this function any more, {@see custom_report_audience_cards_exporter}
|
||||
*/
|
||||
public static function get_all_audiences_menu_types(): array {
|
||||
debugging('The function ' . __FUNCTION__ . '() is deprecated, please do not use it any more. ' .
|
||||
'See \'custom_report_audience_cards_exporter\' class for replacement', DEBUG_DEVELOPER);
|
||||
|
||||
$menucardsarray = [];
|
||||
$notavailablestr = get_string('notavailable', 'moodle');
|
||||
|
||||
$audiencetypes = self::get_audience_types();
|
||||
$audiencetypeindex = 0;
|
||||
foreach ($audiencetypes as $categoryname => $audience) {
|
||||
$menucards = [
|
||||
'name' => $categoryname,
|
||||
'key' => 'index' . ++$audiencetypeindex,
|
||||
];
|
||||
|
||||
foreach ($audience as $classname => $name) {
|
||||
$class = $classname::instance();
|
||||
$title = $class->is_available() ? get_string('addaudience', 'core_reportbuilder', $class->get_name()) :
|
||||
$notavailablestr;
|
||||
$menucard['title'] = $title;
|
||||
$menucard['name'] = $class->get_name();
|
||||
$menucard['disabled'] = !$class->is_available();
|
||||
$menucard['identifier'] = get_class($class);
|
||||
$menucard['action'] = 'add-audience';
|
||||
$menucards['items'][] = $menucard;
|
||||
}
|
||||
|
||||
// Order audience types on each category alphabetically.
|
||||
core_collator::asort_array_of_arrays_by_key($menucards['items'], 'name');
|
||||
$menucards['items'] = array_values($menucards['items']);
|
||||
|
||||
$menucardsarray[] = $menucards;
|
||||
}
|
||||
|
||||
return $menucardsarray;
|
||||
#[\core\attribute\deprecated('custom_report_audience_cards_exporter', since: '4.1', final: true)]
|
||||
public static function get_all_audiences_menu_types() {
|
||||
\core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]);
|
||||
}
|
||||
}
|
||||
|
@ -416,42 +416,11 @@ class report {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available columns for a given report
|
||||
*
|
||||
* @param report_model $persistent
|
||||
* @return array
|
||||
*
|
||||
* @deprecated since Moodle 4.1 - please do not use this function any more, {@see custom_report_column_cards_exporter}
|
||||
*/
|
||||
public static function get_available_columns(report_model $persistent): array {
|
||||
debugging('The function ' . __FUNCTION__ . '() is deprecated, please do not use it any more. ' .
|
||||
'See \'custom_report_column_cards_exporter\' class for replacement', DEBUG_DEVELOPER);
|
||||
|
||||
$available = [];
|
||||
|
||||
$report = manager::get_report_from_persistent($persistent);
|
||||
|
||||
// Get current report columns.
|
||||
foreach ($report->get_columns() as $column) {
|
||||
$entityname = $column->get_entity_name();
|
||||
$entitytitle = $column->get_title();
|
||||
if (!array_key_exists($entityname, $available)) {
|
||||
$available[$entityname] = [
|
||||
'name' => (string) $report->get_entity_title($entityname),
|
||||
'key' => $entityname,
|
||||
'items' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$available[$entityname]['items'][] = [
|
||||
'name' => $entitytitle,
|
||||
'identifier' => $column->get_unique_identifier(),
|
||||
'title' => get_string('addcolumn', 'core_reportbuilder', $entitytitle),
|
||||
'action' => 'report-add-column'
|
||||
];
|
||||
}
|
||||
|
||||
return array_values($available);
|
||||
#[\core\attribute\deprecated('custom_report_column_cards_exporter', since: '4.1', final: true)]
|
||||
public static function get_available_columns() {
|
||||
\core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,6 +6,9 @@ Information provided here is intended especially for developers.
|
||||
* The following external methods now return tags data relevant to each custom report:
|
||||
- `core_reportbuilder_list_reports`
|
||||
- `core_reportbuilder_retrieve_report`
|
||||
* The following previously deprecated local helper methods have been removed and can no longer be used:
|
||||
- `audience::get_all_audiences_menu_types`
|
||||
- `report::get_available_columns`
|
||||
|
||||
=== 4.4 ===
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user