MDL-70795 reportbuilder: add interface for creating reports.
Implement elements for creating/editing reports, along with new system report for listing and accompanying JS modules for user interaction. Create "Users" datasource as proof-of-concept. Co-authored-By: Paul Holden <[email protected]>
This commit is contained in:
committed by
Paul Holden
co-authored by
Paul Holden
parent
95967d62d5
commit
22d896e063
@@ -18,6 +18,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder;
|
||||
|
||||
use core_component;
|
||||
use core_plugin_manager;
|
||||
use stdClass;
|
||||
use core_reportbuilder\local\models\report;
|
||||
use core_reportbuilder\local\report\base;
|
||||
@@ -53,6 +55,19 @@ class manager {
|
||||
return new $source($report, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of a report class from the given report ID
|
||||
*
|
||||
* @param int $reportid
|
||||
* @param array $parameters
|
||||
* @return base
|
||||
*/
|
||||
public static function get_report_from_id(int $reportid, array $parameters = []): base {
|
||||
$report = new report($reportid);
|
||||
|
||||
return self::get_report_from_persistent($report, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that report source exists and extends appropriate base classes
|
||||
*
|
||||
@@ -84,4 +99,30 @@ class manager {
|
||||
public static function create_report_persistent(stdClass $reportdata): report {
|
||||
return (new report(0, $reportdata))->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of all valid report sources across the site
|
||||
*
|
||||
* @return array[][] Indexed by [component => [class => name]]
|
||||
*/
|
||||
public static function get_report_datasources(): array {
|
||||
$sources = array();
|
||||
|
||||
$datasources = core_component::get_component_classes_in_namespace(null, 'reportbuilder\\datasource');
|
||||
foreach ($datasources as $class => $path) {
|
||||
if (self::report_source_exists($class, datasource::class) && self::report_source_available($class)) {
|
||||
[$component] = explode('\\', $class);
|
||||
|
||||
if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
|
||||
$componentname = $plugininfo->displayname;
|
||||
} else {
|
||||
$componentname = get_string('site');
|
||||
}
|
||||
|
||||
$sources[$componentname][$class] = call_user_func([$class, 'get_name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $sources;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user