Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

(no description)

File Size: 825 lines (25 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: base  - X-Ref

Base class for all reports

__construct(report $report)   X-Ref
Base report constructor

param: report $report

get_report_persistent()   X-Ref
Returns persistent class used when initialising this report

return: report

is_available()   X-Ref
Get the report availability. Sub-classes should override this method to declare themselves unavailable, for example if
they require classes that aren't present due to missing plugin

return: bool

validate()   X-Ref
Perform some basic validation about expected class properties


set_main_table(string $tablename, string $tablealias = '')   X-Ref
Set the main table and alias for the SQL query

param: string $tablename
param: string $tablealias

get_main_table()   X-Ref
Get the main table name

return: string

get_main_table_alias()   X-Ref
Get the alias for the main table

return: string

add_join(string $join, array $params = [], bool $validateparams = true)   X-Ref
Adds report JOIN clause that is always added

param: string $join
param: array $params
param: bool $validateparams Some queries might add non-standard params and validation could fail

get_joins()   X-Ref
Return report JOIN clauses

return: array

add_base_condition_simple(string $fieldname, $fieldvalue)   X-Ref
Define simple "field = value" clause to apply to the report query

param: string $fieldname
param: mixed $fieldvalue

add_base_condition_sql(string $where, array $params = [])   X-Ref
Define more complex/non-empty clause to apply to the report query

param: string $where
param: array $params Note that the param names should be generated by {@see database::generate_param_name}

get_base_condition()   X-Ref
Return base select/params for the report query

return: array [string $select, array $params]

add_entity(entity_base $entity)   X-Ref
Adds given entity, along with it's columns and filters, to the report

param: entity_base $entity

get_entity(string $name)   X-Ref
Returns the entity added to the report from the given entity name

param: string $name
return: entity_base

get_entities()   X-Ref
Returns the list of all the entities added to the report

return: entity_base[]

annotate_entity(string $name, lang_string $title)   X-Ref
Define a new entity for the report

param: string $name
param: lang_string $title

get_entity_title(string $name)   X-Ref
Returns title of given report entity

param: string $name
return: lang_string

add_column(column $column)   X-Ref
Adds a column to the report

param: column $column
return: column

add_column_from_entity(string $uniqueidentifier)   X-Ref
Add given column to the report from an entity

The entity must have already been added to the report before calling this method

param: string $uniqueidentifier
return: column

add_columns_from_entities(array $columns)   X-Ref
Add given columns to the report from one or more entities

Each entity must have already been added to the report before calling this method

param: string[] $columns Unique identifier of each entity column

get_column(string $uniqueidentifier)   X-Ref
Return report column by unique identifier

param: string $uniqueidentifier
return: column|null

get_columns()   X-Ref
Return all available report columns

return: column[]

get_active_columns()   X-Ref
Return all active report columns (by default, all available columns)

return: column[]

get_active_columns_by_alias()   X-Ref
Return all active report columns, keyed by their alias (only active columns in a report would have a valid alias/index)

return: column[]

add_condition(filter $condition)   X-Ref
Adds a condition to the report

param: filter $condition
return: filter

add_condition_from_entity(string $uniqueidentifier)   X-Ref
Add given condition to the report from an entity

The entity must have already been added to the report before calling this method

param: string $uniqueidentifier
return: filter

add_conditions_from_entities(array $conditions)   X-Ref
Add given conditions to the report from one or more entities

Each entity must have already been added to the report before calling this method

param: string[] $conditions Unique identifier of each entity condition

get_condition(string $uniqueidentifier)   X-Ref
Return report condition by unique identifier

param: string $uniqueidentifier
return: filter|null

get_conditions()   X-Ref
Return all available report conditions

return: filter[]

get_active_conditions()   X-Ref
Return all active report conditions (by default, all available conditions)

return: filter[]

get_condition_instances()   X-Ref
Return all active report condition instances

return: filter_base[]

set_condition_values(array $values)   X-Ref
Set the condition values of the report

param: array $values
return: bool

get_condition_values()   X-Ref
Get the condition values of the report

return: array

set_settings_values(array $values)   X-Ref
Set the settings values of the report

param: array $values
return: bool

get_settings_values()   X-Ref
Get the settings values of the report

return: array

add_filter(filter $filter)   X-Ref
Adds a filter to the report

param: filter $filter
return: filter

add_filter_from_entity(string $uniqueidentifier)   X-Ref
Add given filter to the report from an entity

The entity must have already been added to the report before calling this method

param: string $uniqueidentifier
return: filter

add_filters_from_entities(array $filters)   X-Ref
Add given filters to the report from one or more entities

Each entity must have already been added to the report before calling this method

param: string[] $filters Unique identifier of each entity filter

get_filter(string $uniqueidentifier)   X-Ref
Return report filter by unique identifier

param: string $uniqueidentifier
return: filter|null

get_filters()   X-Ref
Return all available report filters

return: filter[]

get_active_filters()   X-Ref
Return all active report filters (by default, all available filters)

return: filter[]

get_filter_instances()   X-Ref
Return all active report filter instances

return: filter_base[]

set_filter_values(array $values)   X-Ref
Set the filter values of the report

param: array $values
return: bool

get_filter_values()   X-Ref
Get the filter values of the report

return: array

get_applied_filter_count()   X-Ref
Return the number of filter instances that are being applied based on the report's filter values (i.e. user has
configured them from their initial "Any value" state)

return: int

set_downloadable(bool $downloadable, string $downloadfilename = 'export')   X-Ref
Set if the report can be downloaded.

param: bool $downloadable
param: string $downloadfilename If the report is downloadable, then a filename should be provided here

is_downloadable()   X-Ref
Get if the report can be downloaded.

return: bool

get_downloadfilename()   X-Ref
Return the downloadable report filename

return: string

get_context()   X-Ref
Returns the report context

return: context

set_default_per_page(int $defaultperpage)   X-Ref
Set the default 'per page' size

param: int $defaultperpage

set_default_no_results_notice(?lang_string $notice)   X-Ref
Set the default lang string for the notice used when no results are found.

param: lang_string|null $notice string, or null to tell the report to omit the notice entirely.
return: void

get_default_no_results_notice()   X-Ref
Get the default lang string for the notice used when no results are found.

return: lang_string|null the lang_string instance or null if the report prefers not to use one.

get_default_per_page()   X-Ref
Default 'per page' size

return: int

add_attributes(array $attributes)   X-Ref
Add report attributes (data-, class, etc.) that will be included in HTML when report is displayed

param: array $attributes
return: self

get_attributes()   X-Ref
Returns the report HTML attributes

return: array