Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 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

param: lang_string $header
return: self

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

param: string $join
return: self

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

param: string[] $joins
return: self

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

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

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

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

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

param: bool $available
return: self

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

param: mixed $options
return: self

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

param: callable $callback
return: self

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

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

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

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

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

param: filter_model $persistent
return: self

get_persistent()   X-Ref
Return filter persistent

return: filter_model|null