Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 403]

(no description)

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

Defines 1 class


Class: filter  - X-Ref

Class to represent a report filter

__construct(string $filterclass,string $name,lang_string $header,string $entityname,string $fieldsql = '',array $fieldparams = [])   X-Ref
Filter constructor

param: string $filterclass Filter type class to use, must extend {@see base} filter class
param: string $name Internal name of the filter
param: lang_string $header Title of the filter used in reports
param: string $entityname Name of the entity this filter belongs to. Typically when creating filters within entities
param: string $fieldsql SQL clause to use for filtering, {@see set_field_sql}
param: array $fieldparams

get_filter_class()   X-Ref
Get filter class path

return: string

get_name()   X-Ref
Get filter name

return: string

get_header()   X-Ref
Return header

return: string

set_header(lang_string $header)   X-Ref
Set header

return: self
param: lang_string $header

get_entity_name()   X-Ref
Return filter entity name

return: string

get_unique_identifier()   X-Ref
Return unique identifier for this filter

return: string

get_joins()   X-Ref
Return joins

return: string[]

add_join(string $join)   X-Ref
Add join clause required for this filter to join to existing tables/entities

This is necessary in the case where {@see set_field_sql} is selecting data from a table that isn't otherwise queried

return: self
param: string $join

add_joins(array $joins)   X-Ref
Add multiple join clauses required for this filter, passing each to {@see add_join}

Typically when defining filters in entities, you should pass {@see \core_reportbuilder\local\report\base::get_joins} to
this method, so that all entity joins are included in the report when your filter is used in it

return: self
param: string[] $joins

get_field_sql()   X-Ref
Get SQL expression for the field

return: string

get_field_params()   X-Ref
Get the SQL params for the field being filtered

return: array

get_field_sql_and_params(int $index = 0)   X-Ref
Retrieve SQL expression and parameters for the field

return: array [$sql, [...$params]]
param: int $index

set_field_sql(string $sql, array $params = [])   X-Ref
Set the SQL expression for the field that is being filtered. It will be passed to the filter class

return: self
param: string $sql
param: array $params

get_is_available()   X-Ref
Return available state of the filter for the current user

return: bool

set_is_available(bool $available)   X-Ref
Conditionally set whether the filter is available. For instance the filter may be added to a report with the
expectation that only some users are able to see it

return: self
param: bool $available

set_options($options)   X-Ref
Set the options for the filter in the format that the filter class expected (e.g. the "select" filter expects an array)

This method should only be used if the options do not require any calculations/queries, in which
case {@see set_options_callback} should be used. For performance, {@see get_string} shouldn't be used either, use of
{@see lang_string} is instead encouraged

return: self
param: mixed $options

set_options_callback(callable $callback)   X-Ref
Set the options for the filter to be returned by a callback (that receives no arguments) in the format that the filter
class expects

return: self
param: callable $callback

get_options()   X-Ref
Get the options for the filter, returning via the the previously set options or generated via defined options callback

return: mixed

set_limited_operators(array $limitoperators)   X-Ref
Set a limited subset of operators that should be used for the filter, refer to each filter class to find defined
operator constants

return: self
param: array $limitoperators Simple array of operator values

restrict_limited_operators(array $operators)   X-Ref
Filter given operators to include only those previously defined by {@see set_limited_operators}

return: array
param: array $operators All operators as defined by the filter class

set_persistent(filter_model $persistent)   X-Ref
Set filter persistent

return: self
param: filter_model $persistent

get_persistent()   X-Ref
Return filter persistent

return: filter_model|null