Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

Analysers base class.

Copyright: 2016 David Monllao {@link http://www.davidmonllao.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 525 lines (18 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: base  - X-Ref

Analysers base class.

__construct($modelid, \core_analytics\local\target\base $target, $indicators, $timesplittings, $options)   X-Ref
Constructor method.

param: int $modelid
param: \core_analytics\local\target\base $target
param: \core_analytics\local\indicator\base[] $indicators
param: \core_analytics\local\time_splitting\base[] $timesplittings
param: array $options
return: void

get_analysables()   X-Ref


get_modelid()   X-Ref
Model id getter.

return: int

get_options()   X-Ref
Options getter.

return: array

get_target()   X-Ref
Returns the analysed target.

return: \core_analytics\local\target\base

get_timesplittings()   X-Ref
Getter for time splittings.

return: \core_analytics\local\time_splitting\base

get_indicators()   X-Ref
Getter for indicators.

return: \core_analytics\local\indicator\base

instantiate_indicators()   X-Ref
Instantiate the indicators.

return: \core_analytics\local\indicator\base[]

provided_sample_data()   X-Ref
Samples data this analyser provides.

return: string[]

get_labelled_data(array $contexts = [])   X-Ref
Returns labelled data (training and evaluation).

param: \context[] $contexts Restrict the analysis to these contexts. No context restrictions if null.
return: \stored_file[]

get_unlabelled_data(array $contexts = [])   X-Ref
Returns unlabelled data (prediction).

param: \context[] $contexts Restrict the analysis to these contexts. No context restrictions if null.
return: \stored_file[]

get_static_data(array $contexts = [])   X-Ref
Returns indicator calculations as an array.

param: \context[] $contexts Restrict the analysis to these contexts. No context restrictions if null.
return: array

check_indicators_requirements()   X-Ref
Checks if the analyser satisfies all the model indicators requirements.

return: void

check_indicator_requirements(\core_analytics\local\indicator\base $indicator)   X-Ref
Checks that this analyser satisfies the provided indicator requirements.

param: \core_analytics\local\indicator\base $indicator
return: true|string[] True if all good, missing requirements list otherwise

add_log($string)   X-Ref
Adds a register to the analysis log.

param: string $string
return: void

get_logs()   X-Ref
Returns the analysis logs.

return: string[]

processes_user_data()   X-Ref
Whether the plugin needs user data clearing or not.

This is related to privacy. Override this method if your analyser samples have any relation
to the 'user' database entity. We need to clean the site from all user-related data if a user
request their data to be deleted from the system. A static::provided_sample_data returning 'user'
is an indicator that you should be returning true.

return: bool

join_sample_user($sampletablealias)   X-Ref
SQL JOIN from a sample to users table.

This function should be defined if static::processes_user_data returns true and it is related to analytics API
privacy API implementation. It allows the analytics API to identify data associated to users that needs to be
deleted or exported.

This function receives the alias of a table with a 'sampleid' field and it should return a SQL join
with static::get_samples_origin and with 'user' table. Note that:
- The function caller expects the returned 'user' table to be aliased as 'u' (defacto standard in moodle).
- You can join with other tables if your samples origin table does not contain a 'userid' field (if that would be
a requirement this solution would be automated for you) you can't though use the following
aliases: 'ap', 'apa', 'aic' and 'am'.

Some examples:

static::get_samples_origin() === 'user':
JOIN {user} u ON {$sampletablealias}.sampleid = u.id

static::get_samples_origin() === 'role_assignments':
JOIN {role_assignments} ra ON {$sampletablealias}.sampleid = ra.userid JOIN {user} u ON u.id = ra.userid

static::get_samples_origin() === 'user_enrolments':
JOIN {user_enrolments} ue ON {$sampletablealias}.sampleid = ue.userid JOIN {user} u ON u.id = ue.userid

param: string $sampletablealias The alias of the table with a sampleid field that will join with this SQL string
return: string

one_sample_per_analysable()   X-Ref
Do this analyser's analysables have 1 single sample each?

Overwrite and return true if your analysables only have
one sample. The insights generated by models using this
analyser will then include the suggested actions in the
notification.

return: bool

context_restriction_support()   X-Ref
Returns an array of context levels that can be used to restrict the contexts used during analysis.

The contexts provided to self::get_analysables_iterator will match these contextlevels.

return: array Array of context levels or an empty array if context restriction is not supported.

potential_context_restrictions(string $query = null)   X-Ref
Returns the possible contexts used by the analyser.

This method uses separate logic for each context level because to iterate through
the list of contexts calling get_context_name for each of them would be expensive
in performance terms.

This generic implementation returns all the contexts in the site for the provided context level.
Overwrite it for specific restrictions in your analyser.

param: string|null $query Context name filter.
return: int[]

get_iterator_sql(string $tablename, int $contextlevel, ?string $action = null, ?string $tablealias = null,array $contexts = [])   X-Ref
Get the sql of a default implementation of the iterator.

This method only works for analysers that return analysable elements which ids map to a context instance ids.

param: string      $tablename    The name of the table
param: int         $contextlevel The context level of the analysable
param: string|null $action
param: string|null $tablealias   The table alias
param: \context[]  $contexts     Only analysables that depend on the provided contexts. All analysables if empty.
return: array                     [0] => sql and [1] => params array

order_sql(?string $fieldname = null, string $order = 'ASC', ?string $tablealias = null)   X-Ref
Returns the order by clause.

param: string|null $fieldname  The field name
param: string      $order      'ASC' or 'DESC'
param: string|null $tablealias The table alias of the field
return: string