mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-64777 analytics: Add method to load all model definitions
This commit is contained in:
parent
01d620ee67
commit
1297fa4156
@ -683,6 +683,43 @@ class manager {
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of all the models declared anywhere in this Moodle installation.
|
||||
*
|
||||
* Models defined by the core and core subsystems come first, followed by those provided by plugins.
|
||||
*
|
||||
* @return array indexed by the frankenstyle component
|
||||
*/
|
||||
public static function load_default_models_for_all_components(): array {
|
||||
|
||||
$tmp = [];
|
||||
|
||||
foreach (\core_component::get_component_list() as $type => $components) {
|
||||
foreach (array_keys($components) as $component) {
|
||||
if ($loaded = static::load_default_models_for_component($component)) {
|
||||
$tmp[$type][$component] = $loaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
if ($loaded = static::load_default_models_for_component('core')) {
|
||||
$result['core'] = $loaded;
|
||||
}
|
||||
|
||||
if (!empty($tmp['core'])) {
|
||||
$result += $tmp['core'];
|
||||
unset($tmp['core']);
|
||||
}
|
||||
|
||||
foreach ($tmp as $components) {
|
||||
$result += $components;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the declaration of prediction models according the syntax expected in the component's db folder.
|
||||
*
|
||||
|
@ -172,6 +172,20 @@ class analytics_manager_testcase extends advanced_testcase {
|
||||
$this->assertSame([], \core_analytics\manager::load_default_models_for_component('foo_bar2776327736558'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the {@link \core_analytics\manager::load_default_models_for_all_components()} implementation.
|
||||
*/
|
||||
public function test_load_default_models_for_all_components() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$models = \core_analytics\manager::load_default_models_for_all_components();
|
||||
|
||||
$this->assertTrue(is_array($models['core']));
|
||||
$this->assertNotEmpty($models['core']);
|
||||
$this->assertNotEmpty($models['core'][0]['target']);
|
||||
$this->assertNotEmpty($models['core'][0]['indicators']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the successful execution of the {@link \core_analytics\manager::validate_models_declaration()}.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user