Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
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_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_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. | |
Protected Attributes | |
bool | $available = true |
$available Used to know if column is available to the current user or not | |
column_model | $persistent |
$persistent | |
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']));
string | $name | Internal name of the column |
lang_string | null | $title | Title of the column used in reports (null for blank) |
string | $entityname | Name of the entity this column belongs to. Typically when creating columns within entities this value should be the result of calling { |
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.
array | $attributes |
self |
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 {
callable | $callable | |
mixed | $additionalarguments |
self |
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
string | $sql | SQL query, this may be a simple "tablealias.fieldname" or a complex sub-query that returns only one field |
string | $alias | |
array | $params |
self |
coding_exception |
core_reportbuilder\local\report\column::add_fields | ( | string | $sql, |
array | $params = [] ) |
Add a list of comma-separated fields.
string | $sql | |
array | $params |
self |
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 {
string | $join |
self |
core_reportbuilder\local\report\column::add_joins | ( | array | $joins | ) |
Add multiple join clauses required for this column, passing each to {.
Typically when defining columns in entities, you should pass {
string[] | $joins |
self |
core_reportbuilder\local\report\column::format_value | ( | array | $row | ) |
Return column value based on complete table row.
array | $row |
mixed |
core_reportbuilder\local\report\column::get_aggregation | ( | ) |
Get column aggregation type.
base|null |
core_reportbuilder\local\report\column::get_attributes | ( | ) |
Returns the column HTML attributes.
array |
core_reportbuilder\local\report\column::get_column_alias | ( | ) |
Return an alias for this column (the generated alias of it's first field)
string |
coding_exception |
|
static |
Return the default column value, that being the value of it's first field.
array | $values | |
int | $columntype |
mixed |
core_reportbuilder\local\report\column::get_disabled_aggregation | ( | ) |
Return those aggregations methods explicitly disabled for the column.
array |
core_reportbuilder\local\report\column::get_entity_name | ( | ) |
Get column entity name.
string |
core_reportbuilder\local\report\column::get_fields | ( | ) |
Return array of SQL expressions for each field of this column.
array |
core_reportbuilder\local\report\column::get_groupby_sql | ( | ) |
Return suitable SQL fragment for grouping by the column fields (during aggregation)
array |
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
bool |
core_reportbuilder\local\report\column::get_is_sortable | ( | ) |
Return sortable status of column.
bool |
core_reportbuilder\local\report\column::get_joins | ( | ) |
Return column joins.
string[] |
core_reportbuilder\local\report\column::get_name | ( | ) |
Return column name.
mixed |
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.
array |
core_reportbuilder\local\report\column::get_persistent | ( | ) |
Return column persistent.
mixed |
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.
array |
core_reportbuilder\local\report\column::get_title | ( | ) |
Return column title.
string |
core_reportbuilder\local\report\column::get_type | ( | ) |
Return column type, that being one of the TYPE_* class constants.
int |
core_reportbuilder\local\report\column::get_unique_identifier | ( | ) |
Return unique identifier for this column.
string |
core_reportbuilder\local\report\column::has_custom_title | ( | ) |
Check whether this column has been given a custom title.
bool |
core_reportbuilder\local\report\column::set_aggregation | ( | ?string | $aggregation | ) |
Set column aggregation type.
string | null | $aggregation | Type of aggregation, e.g. 'sum', 'count', etc |
self |
coding_exception | For invalid aggregation type, or one that is incompatible with column type |
core_reportbuilder\local\report\column::set_callback | ( | callable | $callable, |
$additionalarguments = null ) |
Sets column callback.
This will overwrite any previously added callbacks {
callable | $callable | |
mixed | $additionalarguments |
self |
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: {
array | $disabledaggregation | Array of types, e.g. ['min', 'sum'] |
self |
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.
self |
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 {
string | $groupbysql |
self |
core_reportbuilder\local\report\column::set_index | ( | int | $index | ) |
Set the column index within the current report.
int | $index |
self |
core_reportbuilder\local\report\column::set_is_available | ( | bool | $available | ) |
Conditionally set whether the column is available.
bool | $available |
self |
core_reportbuilder\local\report\column::set_is_sortable | ( | bool | $issortable, |
array | $sortfields = [] ) |
Sets the column as sortable.
bool | $issortable | |
array | $sortfields | Define the fields that should be used when the column is sorted, typically a subset of the fields selected for the column, via { |
self |
core_reportbuilder\local\report\column::set_name | ( | string | $name | ) |
Set column name.
string | $name |
self |
core_reportbuilder\local\report\column::set_persistent | ( | column_model | $persistent | ) |
Set column persistent.
column_model | $persistent |
self |
core_reportbuilder\local\report\column::set_title | ( | ?lang_string | $title | ) |
core_reportbuilder\local\report\column::set_type | ( | int | $type | ) |
Set the column type, if not called then the type will be assumed to be {.
The type of a column is used to cast the first column field passed to any callbacks {
int | $type |
self |
coding_exception |