Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
core_analytics\manager Class Reference

Analytics basic actions manager. More...

Static Public Member Functions

static add_builtin_models ()
 Used to be used to add models included with the Moodle core.
 
static cached_models_with_insights (\context $context, int $newmodelid=null)
 Returns the models that generated insights in the provided context.
 
static check_can_list_insights (\context $context, bool $return=false)
 Checks that the user can list that context insights.
 
static check_can_manage_models ()
 Checks that the user can manage models.
 
static cleanup ()
 Cleans up analytics db tables that do not directly depend on analysables that may have been deleted.
 
static create_declared_model (array $definition)
 Create the defined model.
 
static default_mlbackend ()
 Default system backend.
 
static get_all_indicators ()
 Return all system indicators.
 
static get_all_models ($enabled=false, $trained=false, $predictioncontext=false)
 Returns all system models that match the provided filters.
 
static get_all_prediction_processors ()
 Return all system predictions processors.
 
static get_all_targets ()
 Return all targets in the system.
 
static get_all_time_splittings ()
 Get all available time splitting methods.
 
static get_analytics_logstore ()
 Returns the logstore used for analytics.
 
static get_declared_target_and_indicators_instances (array $definition)
 Given a model definition, return actual target and indicators instances.
 
static get_enabled_time_splitting_methods ()
 
static get_indicator ($fullclassname)
 Returns an instance of the provided indicator.
 
static get_indicator_calculations ($analysable, $starttime, $endtime, $samplesorigin)
 Returns this analysable calculations during the provided period.
 
static get_models_with_insights (\context $context)
 Returns the models with insights at the provided context.
 
static get_potential_context_restrictions (?array $contextlevels=null, string $query=null)
 Return the context restrictions that can be applied to the provided context levels.
 
static get_prediction ($predictionid, $requirelogin=false)
 Returns a prediction.
 
static get_predictions_processor ($predictionclass=false, $checkisready=true)
 Returns the provided predictions processor class.
 
static get_predictions_processor_name (\core_analytics\predictor $predictionsprocessor)
 Returns the name of the provided predictions processor.
 
static get_target ($fullclassname)
 Returns the specified target.
 
static get_time_splitting ($fullclassname)
 Returns a time splitting method by its classname.
 
static get_time_splitting_methods_for_evaluation (bool $all=false)
 Returns the time-splitting methods for model evaluation.
 
static is_analytics_enabled ()
 Is analytics enabled globally?
 
static is_mlbackend_used ($plugin)
 Whether the provided plugin is used by any model.
 
static is_valid ($fullclassname, $baseclass)
 Returns whether a time splitting method is valid or not.
 
static load_default_models_for_all_components ()
 Return the list of all the models declared anywhere in this Moodle installation.
 
static load_default_models_for_component (string $componentname)
 Return the list of models declared by the given component.
 
static model_declaration_identifier (array $model)
 Returns a string uniquely representing the given model declaration.
 
static reset_prediction_processors ()
 Resets the cached prediction processors.
 
static update_default_models_for_component (string $componentname)
 Check that all the models declared by the component are up to date.
 
static validate_models_declaration (array $models)
 Validate the declaration of prediction models according the syntax expected in the component's db folder.
 

Public Attributes

const ANALYTICS_FILENAME = 'db/analytics.php'
 Name of the file where components declare their models.
 
const DEFAULT_MLBACKEND = '\mlbackend_php\processor'
 Default mlbackend.
 

Static Protected Attributes

static core_analytics local indicator base[] $allindicators = null
 
static core_analytics local target base[] $alltargets = null
 
static core_analytics local time_splitting base[] $alltimesplittings = null
 
static core_analytics predictor[] $predictionprocessors = []
 

Detailed Description

Analytics basic actions manager.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ add_builtin_models()

static core_analytics\manager::add_builtin_models ( )
static

Used to be used to add models included with the Moodle core.

Deprecated
Deprecated since Moodle 3.7 (MDL-61667) - Use lib/db/analytics.php instead.
Todo
Remove this method in Moodle 3.11 (MDL-65186).
Return values
void

◆ cached_models_with_insights()

static core_analytics\manager::cached_models_with_insights ( \context $context,
int $newmodelid = null )
static

Returns the models that generated insights in the provided context.

It can also be used to add new models to the context.

Note that if you use this function with $newmodelid is the caller responsibility to ensure that the provided model id generated insights for the provided context.

Exceptions
coding_exception
Parameters
context$context
int | null$newmodelidA new model to add to the list of models with insights in the provided context.
Return values
int[]

◆ check_can_list_insights()

static core_analytics\manager::check_can_list_insights ( \context $context,
bool $return = false )
static

Checks that the user can list that context insights.

Exceptions
required_capability_exception
Parameters
context$context
bool$returnThe method returns a bool if true.
Return values
void

◆ check_can_manage_models()

static core_analytics\manager::check_can_manage_models ( )
static

Checks that the user can manage models.

Exceptions
required_capability_exception
Return values
void

◆ create_declared_model()

static core_analytics\manager::create_declared_model ( array $definition)
static

Create the defined model.

Parameters
array$definitionSee self::validate_models_declaration() for the syntax.
Return values
core_analytics\model

◆ default_mlbackend()

static core_analytics\manager::default_mlbackend ( )
static

Default system backend.

Return values
string

◆ get_all_indicators()

static core_analytics\manager::get_all_indicators ( )
static

Return all system indicators.

Return values
core_analytics\local\indicator\base[]

◆ get_all_models()

static core_analytics\manager::get_all_models ( $enabled = false,
$trained = false,
$predictioncontext = false )
static

Returns all system models that match the provided filters.

Parameters
bool$enabled
bool$trained
context | false$predictioncontext
Return values
core_analytics\model[]

◆ get_all_prediction_processors()

static core_analytics\manager::get_all_prediction_processors ( )
static

Return all system predictions processors.

Return values
core_analytics\predictor[]

◆ get_all_targets()

static core_analytics\manager::get_all_targets ( )
static

Return all targets in the system.

Return values
core_analytics\local\target\base[]

◆ get_all_time_splittings()

static core_analytics\manager::get_all_time_splittings ( )
static

Get all available time splitting methods.

Return values
core_analytics\local\time_splitting\base[]

◆ get_analytics_logstore()

static core_analytics\manager::get_analytics_logstore ( )
static

Returns the logstore used for analytics.

Return values
core\log\sql_reader|falseFalse if no log stores are enabled.

◆ get_declared_target_and_indicators_instances()

static core_analytics\manager::get_declared_target_and_indicators_instances ( array $definition)
static

Given a model definition, return actual target and indicators instances.

Parameters
array$definitionSee self::validate_models_declaration() for the syntax.
Return values
array[0] => target instance, [1] => array of indicators instances

◆ get_enabled_time_splitting_methods()

static core_analytics\manager::get_enabled_time_splitting_methods ( )
static
Deprecated
since Moodle 3.7 use get_time_splitting_methods_for_evaluation instead

◆ get_indicator()

static core_analytics\manager::get_indicator ( $fullclassname)
static

Returns an instance of the provided indicator.

Parameters
string$fullclassname
Return values
core_analytics\local\indicator\base|falseFalse if it is not valid.

◆ get_indicator_calculations()

static core_analytics\manager::get_indicator_calculations ( $analysable,
$starttime,
$endtime,
$samplesorigin )
static

Returns this analysable calculations during the provided period.

Parameters
core_analytics\analysable$analysable
int$starttime
int$endtime
string$samplesoriginThe samples origin as sampleid is not unique across models.
Return values
array

◆ get_models_with_insights()

static core_analytics\manager::get_models_with_insights ( \context $context)
static

Returns the models with insights at the provided context.

Note that this method is used for display purposes. It filters out models whose insights are not linked from the reports page.

Parameters
context$context
Return values
core_analytics\model[]

◆ get_potential_context_restrictions()

static core_analytics\manager::get_potential_context_restrictions ( ?array $contextlevels = null,
string $query = null )
static

Return the context restrictions that can be applied to the provided context levels.

Exceptions
coding_exception
Parameters
array | null$contextlevelsThe list of context levels provided by the analyser. Null if all of them.
string | null$query
Return values
arrayAssociative array with contextid as key and the short version of the context name as value.

◆ get_prediction()

static core_analytics\manager::get_prediction ( $predictionid,
$requirelogin = false )
static

Returns a prediction.

Parameters
int$predictionid
bool$requirelogin
Return values
arrayarray($model, $prediction, $context)

◆ get_predictions_processor()

static core_analytics\manager::get_predictions_processor ( $predictionclass = false,
$checkisready = true )
static

Returns the provided predictions processor class.

Parameters
false | string$predictionclassReturns the system default processor if false
bool$checkisready
Return values
core_analytics\predictor

◆ get_predictions_processor_name()

static core_analytics\manager::get_predictions_processor_name ( \core_analytics\predictor $predictionsprocessor)
static

Returns the name of the provided predictions processor.

Parameters
core_analytics\predictor$predictionsprocessor
Return values
string

◆ get_target()

static core_analytics\manager::get_target ( $fullclassname)
static

Returns the specified target.

Parameters
mixed$fullclassname
Return values
core_analytics\local\target\base|falseFalse if it is not valid

◆ get_time_splitting()

static core_analytics\manager::get_time_splitting ( $fullclassname)
static

Returns a time splitting method by its classname.

Parameters
string$fullclassname
Return values
core_analytics\local\time_splitting\base|falseFalse if it is not valid.

◆ get_time_splitting_methods_for_evaluation()

static core_analytics\manager::get_time_splitting_methods_for_evaluation ( bool $all = false)
static

Returns the time-splitting methods for model evaluation.

Parameters
bool$allReturn all the time-splitting methods that can potentially be used for evaluation or the default ones.
Return values
core_analytics\local\time_splitting\base[]

◆ is_analytics_enabled()

static core_analytics\manager::is_analytics_enabled ( )
static

Is analytics enabled globally?

return bool

◆ is_mlbackend_used()

static core_analytics\manager::is_mlbackend_used ( $plugin)
static

Whether the provided plugin is used by any model.

Parameters
string$plugin
Return values
bool

◆ is_valid()

static core_analytics\manager::is_valid ( $fullclassname,
$baseclass )
static

Returns whether a time splitting method is valid or not.

Parameters
string$fullclassname
string$baseclass
Return values
bool

◆ load_default_models_for_all_components()

static core_analytics\manager::load_default_models_for_all_components ( )
static

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 values
arrayindexed by the frankenstyle component

◆ load_default_models_for_component()

static core_analytics\manager::load_default_models_for_component ( string $componentname)
static

Return the list of models declared by the given component.

Parameters
string$componentnameThe name of the component to load models for.
Exceptions
coding_exceptionException thrown in case of invalid syntax.
Return values
arrayThe $models description array.

◆ model_declaration_identifier()

static core_analytics\manager::model_declaration_identifier ( array $model)
static

Returns a string uniquely representing the given model declaration.

Parameters
array$modelModel declaration
Return values
stringcomplying with PARAM_ALPHANUM rules and starting with an 'id' prefix

◆ reset_prediction_processors()

static core_analytics\manager::reset_prediction_processors ( )
static

Resets the cached prediction processors.

Return values
null

◆ update_default_models_for_component()

static core_analytics\manager::update_default_models_for_component ( string $componentname)
static

Check that all the models declared by the component are up to date.

This is intended to be called during the installation / upgrade to automatically create missing models.

Parameters
string$componentnameThe name of the component to load models for.
Return values
arraycore_analytics\model[] List of actually created models.

◆ validate_models_declaration()

static core_analytics\manager::validate_models_declaration ( array $models)
static

Validate the declaration of prediction models according the syntax expected in the component's db folder.

The expected structure looks like this:

[ [ 'target' => 'fully\qualified\name\of\the\target\class', 'indicators' => [ 'fully\qualified\name\of\the\first\indicator', 'fully\qualified\name\of\the\second\indicator', ], 'timesplitting' => 'optional\name\of\the\time_splitting\class', 'enabled' => true, ], ];

Parameters
array$modelsList of declared models.
Exceptions
coding_exceptionException thrown in case of invalid syntax.

The documentation for this class was generated from the following file: