Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_reportbuilder\local\report\column Class Reference

Public Member Functions

 __construct (string $name, ?lang_string $title, string $entityname)
 Column constructor.
 
 add_attributes (array $attributes)
 Add column attributes (data-, class, etc.) that will be included in HTML when column is displayed.
 
 add_callback (callable $callable, $additionalarguments=null)
 Adds column callback (in the case there are multiple, they will be called iteratively - the result of each passed along to the next in the chain)
 
 add_field (string $sql, string $alias='', array $params=[])
 Adds a field to be queried from the database that is necessary for this column.
 
 add_fields (string $sql, array $params=[])
 Add a list of comma-separated fields.
 
 add_join (string $join)
 Add join clause required for this column to join to existing tables/entities.
 
 add_joins (array $joins)
 Add multiple join clauses required for this column, passing each to {.
 
 format_value (array $row)
 Return column value based on complete table row.
 
 get_aggregation ()
 Get column aggregation type.
 
 get_attributes ()
 Returns the column HTML attributes.
 
 get_column_alias ()
 Return an alias for this column (the generated alias of it's first field)
 
 get_disabled_aggregation ()
 Return those aggregations methods explicitly disabled for the column.
 
 get_entity_name ()
 Get column entity name.
 
 get_fields ()
 Return array of SQL expressions for each field of this column.
 
 get_groupby_sql ()
 Return suitable SQL fragment for grouping by the column fields (during aggregation)
 
 get_is_available ()
 Return available state of the column for the current user.
 
 get_is_deprecated ()
 Return deprecated state of the column.
 
 get_is_deprecated_message ()
 Return deprecated message of the column.
 
 get_is_sortable ()
 Return sortable status of column.
 
 get_joins ()
 Return column joins.
 
 get_name ()
 Return column name.
 
 get_params ()
 Return column parameters, prefixed by the current index to allow the column to be added multiple times to a report.
 
 get_persistent ()
 Return column persistent.
 
 get_sort_fields ()
 Return fields to use for sorting of the column, where available the field aliases will be returned.
 
 get_title ()
 Return column title.
 
 get_type ()
 Return column type, that being one of the TYPE_* class constants.
 
 get_unique_identifier ()
 Return unique identifier for this column.
 
 has_custom_title ()
 Check whether this column has been given a custom title.
 
 set_aggregation (?string $aggregation)
 Set column aggregation type.
 
 set_callback (callable $callable, $additionalarguments=null)
 Sets column callback.
 
 set_disabled_aggregation (array $disabledaggregation)
 Set disabled aggregation methods for the column.
 
 set_disabled_aggregation_all ()
 Disable all aggregation methods for the column, for instance when current database can't aggregate fields that contain sub-queries.
 
 set_groupby_sql (string $groupbysql)
 Define suitable SQL fragment for grouping by the columns fields.
 
 set_index (int $index)
 Set the column index within the current report.
 
 set_is_available (bool $available)
 Conditionally set whether the column is available.
 
 set_is_deprecated (string $deprecatedmessage='')
 Set deprecated state of the column, in which case it will still be shown when already present in existing reports but won't be available for selection in the report editor.
 
 set_is_sortable (bool $issortable, array $sortfields=[])
 Sets the column as sortable.
 
 set_name (string $name)
 Set column name.
 
 set_persistent (column_model $persistent)
 Set column persistent.
 
 set_title (?lang_string $title)
 Set column title.
 
 set_type (int $type)
 Set the column type, if not called then the type will be assumed to be {.
 

Static Public Member Functions

static get_default_value (array $values, int $columntype)
 Return the default column value, that being the value of it's first field.
 

Public Attributes

int const TYPE_BOOLEAN = 4
 Column type is boolean.
 
int const TYPE_FLOAT = 5
 Column type is float.
 
int const TYPE_INTEGER = 1
 Column type is integer.
 
int const TYPE_LONGTEXT = 6
 Column type is long text.
 
int const TYPE_TEXT = 2
 Column type is text.
 
int const TYPE_TIMESTAMP = 3
 Column type is timestamp.
 

Protected Attributes

bool $available = true
 $available Used to know if column is available to the current user or not
 
bool $deprecated = false
 $deprecated
 
string $deprecatedmessage
 $deprecatedmessage
 
column_model $persistent
 $persistent
 

Constructor & Destructor Documentation

◆ __construct()

core_reportbuilder\local\report\column::__construct ( string $name,
?lang_string $title,
string $entityname )

Column constructor.

For better readability use chainable methods, for example:

$report->add_column( (new column('name', new lang_string('name'), 'user')) ->add_join('left join {table} t on t.id = p.tableid') ->add_field('t.name') ->add_callback([format\class, 'format_string']));

Parameters
string$nameInternal name of the column
lang_string | null$titleTitle of the column used in reports (null for blank)
string$entitynameName of the entity this column belongs to. Typically when creating columns within entities this value should be the result of calling {
See also
get_entity_name}, however if creating columns inside reports directly it should be the name of the entity as passed to {
core_reportbuilder\local\report\base\annotate_entity}

Member Function Documentation

◆ add_attributes()

core_reportbuilder\local\report\column::add_attributes ( array $attributes)

Add column attributes (data-, class, etc.) that will be included in HTML when column is displayed.

Parameters
array$attributes
Return values
self

◆ add_callback()

core_reportbuilder\local\report\column::add_callback ( callable $callable,
$additionalarguments = null )

Adds column callback (in the case there are multiple, they will be called iteratively - the result of each passed along to the next in the chain)

The callback should implement the following signature (where $value is the first column field, $row is all column fields, $additionalarguments are those passed to this method, and $aggregation indicates the current aggregation type being applied to the column):

function($value, stdClass $row, $additionalarguments, ?string $aggregation): string

The type of the $value parameter passed to the callback is determined by calling {

See also
set_type}, this type is preserved if the column is part of a report source and is being aggregated. For entities that can be left joined to a report, the first argument of the callback must be nullable (as it should also be if the first column field is itself nullable).
Parameters
callable$callable
mixed$additionalarguments
Return values
self

◆ add_field()

core_reportbuilder\local\report\column::add_field ( string $sql,
string $alias = '',
array $params = [] )

Adds a field to be queried from the database that is necessary for this column.

Multiple fields can be added per column, this method may be called several times. Field aliases must be unique inside any given column, but there will be no conflicts if the same aliases are used in other columns in the same report

Parameters
string$sqlSQL query, this may be a simple "tablealias.fieldname" or a complex sub-query that returns only one field
string$alias
array$params
Return values
self
Exceptions
coding_exception

◆ add_fields()

core_reportbuilder\local\report\column::add_fields ( string $sql,
array $params = [] )

Add a list of comma-separated fields.

Parameters
string$sql
array$params
Return values
self

◆ add_join()

core_reportbuilder\local\report\column::add_join ( string $join)

Add join clause required for this column to join to existing tables/entities.

This is necessary in the case where {

See also
add_field} is selecting data from a table that isn't otherwise queried
Parameters
string$join
Return values
self

◆ add_joins()

core_reportbuilder\local\report\column::add_joins ( array $joins)

Add multiple join clauses required for this column, passing each to {.

See also
add_join}

Typically when defining columns in entities, you should pass {

See also
core_reportbuilder\local\report\base\get_joins} to this method, so that all entity joins are included in the report when your column is added to it
Parameters
string[]$joins
Return values
self

◆ format_value()

core_reportbuilder\local\report\column::format_value ( array $row)

Return column value based on complete table row.

Parameters
array$row
Return values
mixed

◆ get_aggregation()

core_reportbuilder\local\report\column::get_aggregation ( )

Get column aggregation type.

Return values
base|null

◆ get_attributes()

core_reportbuilder\local\report\column::get_attributes ( )

Returns the column HTML attributes.

Return values
array

◆ get_column_alias()

core_reportbuilder\local\report\column::get_column_alias ( )

Return an alias for this column (the generated alias of it's first field)

Return values
string
Exceptions
coding_exception

◆ get_default_value()

static core_reportbuilder\local\report\column::get_default_value ( array $values,
int $columntype )
static

Return the default column value, that being the value of it's first field.

Parameters
array$values
int$columntype
Return values
mixed

◆ get_disabled_aggregation()

core_reportbuilder\local\report\column::get_disabled_aggregation ( )

Return those aggregations methods explicitly disabled for the column.

Return values
array

◆ get_entity_name()

core_reportbuilder\local\report\column::get_entity_name ( )

Get column entity name.

Return values
string

◆ get_fields()

core_reportbuilder\local\report\column::get_fields ( )

Return array of SQL expressions for each field of this column.

Return values
array

◆ get_groupby_sql()

core_reportbuilder\local\report\column::get_groupby_sql ( )

Return suitable SQL fragment for grouping by the column fields (during aggregation)

Return values
array

◆ get_is_available()

core_reportbuilder\local\report\column::get_is_available ( )

Return available state of the column for the current user.

For instance the column may be added to a report with the expectation that only some users are able to see it

Return values
bool

◆ get_is_deprecated()

core_reportbuilder\local\report\column::get_is_deprecated ( )

Return deprecated state of the column.

Return values
bool

◆ get_is_deprecated_message()

core_reportbuilder\local\report\column::get_is_deprecated_message ( )

Return deprecated message of the column.

Return values
string

◆ get_is_sortable()

core_reportbuilder\local\report\column::get_is_sortable ( )

Return sortable status of column.

Return values
bool

◆ get_joins()

core_reportbuilder\local\report\column::get_joins ( )

Return column joins.

Return values
string[]

◆ get_name()

core_reportbuilder\local\report\column::get_name ( )

Return column name.

Return values
mixed

◆ get_params()

core_reportbuilder\local\report\column::get_params ( )

Return column parameters, prefixed by the current index to allow the column to be added multiple times to a report.

Return values
array

◆ get_persistent()

core_reportbuilder\local\report\column::get_persistent ( )

Return column persistent.

Return values
mixed

◆ get_sort_fields()

core_reportbuilder\local\report\column::get_sort_fields ( )

Return fields to use for sorting of the column, where available the field aliases will be returned.

Return values
array

◆ get_title()

core_reportbuilder\local\report\column::get_title ( )

Return column title.

Return values
string

◆ get_type()

core_reportbuilder\local\report\column::get_type ( )

Return column type, that being one of the TYPE_* class constants.

Return values
int

◆ get_unique_identifier()

core_reportbuilder\local\report\column::get_unique_identifier ( )

Return unique identifier for this column.

Return values
string

◆ has_custom_title()

core_reportbuilder\local\report\column::has_custom_title ( )

Check whether this column has been given a custom title.

Return values
bool

◆ set_aggregation()

core_reportbuilder\local\report\column::set_aggregation ( ?string $aggregation)

Set column aggregation type.

Parameters
string | null$aggregationType of aggregation, e.g. 'sum', 'count', etc
Return values
self
Exceptions
coding_exceptionFor invalid aggregation type, or one that is incompatible with column type

◆ set_callback()

core_reportbuilder\local\report\column::set_callback ( callable $callable,
$additionalarguments = null )

Sets column callback.

This will overwrite any previously added callbacks {

See also
add_callback}
Parameters
callable$callable
mixed$additionalarguments
Return values
self

◆ set_disabled_aggregation()

core_reportbuilder\local\report\column::set_disabled_aggregation ( array $disabledaggregation)

Set disabled aggregation methods for the column.

Typically only those methods suitable for the current column type are available: {

See also
aggregation\get_column_aggregations}, however in some cases we may want to disable specific methods
Parameters
array$disabledaggregationArray of types, e.g. ['min', 'sum']
Return values
self

◆ set_disabled_aggregation_all()

core_reportbuilder\local\report\column::set_disabled_aggregation_all ( )

Disable all aggregation methods for the column, for instance when current database can't aggregate fields that contain sub-queries.

Return values
self

◆ set_groupby_sql()

core_reportbuilder\local\report\column::set_groupby_sql ( string $groupbysql)

Define suitable SQL fragment for grouping by the columns fields.

This will be returned from {

See also
get_groupby_sql} if set
Parameters
string$groupbysql
Return values
self

◆ set_index()

core_reportbuilder\local\report\column::set_index ( int $index)

Set the column index within the current report.

Parameters
int$index
Return values
self

◆ set_is_available()

core_reportbuilder\local\report\column::set_is_available ( bool $available)

Conditionally set whether the column is available.

Parameters
bool$available
Return values
self

◆ set_is_deprecated()

core_reportbuilder\local\report\column::set_is_deprecated ( string $deprecatedmessage = '')

Set deprecated state of the column, in which case it will still be shown when already present in existing reports but won't be available for selection in the report editor.

Parameters
string$deprecatedmessage
Return values
self

◆ set_is_sortable()

core_reportbuilder\local\report\column::set_is_sortable ( bool $issortable,
array $sortfields = [] )

Sets the column as sortable.

Parameters
bool$issortable
array$sortfieldsDefine the fields that should be used when the column is sorted, typically a subset of the fields selected for the column, via {
See also
add_field}. If omitted then the first selected field is used
Return values
self

◆ set_name()

core_reportbuilder\local\report\column::set_name ( string $name)

Set column name.

Parameters
string$name
Return values
self

◆ set_persistent()

core_reportbuilder\local\report\column::set_persistent ( column_model $persistent)

Set column persistent.

Parameters
column_model$persistent
Return values
self

◆ set_title()

core_reportbuilder\local\report\column::set_title ( ?lang_string $title)

Set column title.

Parameters
lang_string | null$title
Return values
self

◆ set_type()

core_reportbuilder\local\report\column::set_type ( int $type)

Set the column type, if not called then the type will be assumed to be {.

See also
TYPE_TEXT}

The type of a column is used to cast the first column field passed to any callbacks {

See also
add_callback} as well as the aggregation options available for the column
Parameters
int$type
Return values
self
Exceptions
coding_exception

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