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]

Base class for representing a column.

Copyright: 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 431 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: column_base  - X-Ref

Base class for representing a column.

__construct(view $qbank)   X-Ref
Constructor.

param: view $qbank the question bank view we are helping to render.

init()   X-Ref
A chance for subclasses to initialise themselves, for example to load lang strings,
without having to override the constructor.


set_as_heading()   X-Ref
Set the column as heading


is_extra_row()   X-Ref
Check if the column is an extra row of not.


has_preference()   X-Ref
Check if the row has an extra preference to view/hide.


get_preference_key()   X-Ref
Get if the preference key of the row.


get_preference()   X-Ref
Get if the preference of the row.


display_header()   X-Ref
Output the column header cell.


get_title_tip()   X-Ref
Use this when get_title() returns
something very short, and you want a longer version as a tool tip.

return: string a fuller version of the name.

help_icon()   X-Ref
If you return a help icon here, it is shown in the column header after the title.

return: \help_icon|null help icon to show, if required.

make_sort_link($sort, $title, $tip, $defaultreverse = false)   X-Ref
Get a link that changes the sort order, and indicates the current sort state.

param: string $sort the column to sort on.
param: string $title the link text.
param: string $tip the link tool-tip text. If empty, defaults to title.
param: bool $defaultreverse whether the default sort order for this column is descending, rather than ascending.
return: string

get_sort_icon($reverse)   X-Ref
Get an icon representing the corrent sort state.

param: bool $reverse sort is descending, not ascending.
return: string HTML image tag.

display($question, $rowclasses)   X-Ref
Output this column.

param: object $question the row from the $question table, augmented with extra information.
param: string $rowclasses CSS class names that should be applied to this row of output.

display_start($question, $rowclasses)   X-Ref
Output the opening column tag.  If it is set as heading, it will use <th> tag instead of <td>

param: \stdClass $question
param: string $rowclasses

get_classes()   X-Ref
The CSS classes to apply to every cell in this column.

return: string

get_column_name()   X-Ref
Get the name of this column. This must be unique.
When using the inherited class to make many columns from one parent,
ensure each instance returns a unique value.

return: string The unique name;

get_extra_classes()   X-Ref
Any extra class names you would like applied to every cell in this column.

return: array

display_end($question, $rowclasses)   X-Ref
Output the closing column tag

param: object $question
param: string $rowclasses

get_extra_joins()   X-Ref
Return an array 'table_alias' => 'JOIN clause' to bring in any data that
this column required.

The return values for all the columns will be checked. It is OK if two
columns join in the same table with the same alias and identical JOIN clauses.
If to columns try to use the same alias with different joins, you get an error.
The only table included by default is the question table, which is aliased to 'q'.

It is importnat that your join simply adds additional data (or NULLs) to the
existing rows of the query. It must not cause additional rows.

return: array 'table_alias' => 'JOIN clause'

get_required_fields()   X-Ref
Use table alias 'q' for the question table, or one of the
ones from get_extra_joins. Every field requested must specify a table prefix.

return: array fields required.

get_required_statistics_fields()   X-Ref
If this column requires any aggregated statistics, it should declare that here.

This is those statistics can be efficiently loaded in bulk.

The statistics are all loaded just before load_additional_data is called on each column.
The values are then available from $this->qbank->get_aggregate_statistic(...);

return: string[] the names of the required statistics fields. E.g. ['facility'].

load_additional_data(array $questions)   X-Ref
If this column needs extra data (e.g. tags) then load that here.

The extra data should be added to the question object in the array.
Probably a good idea to check that another column has not already
loaded the data you want.

param: \stdClass[] $questions the questions that will be displayed, indexed by question id.

load_question_tags(array $questions)   X-Ref
Load the tags for each question.

Helper that can be used from {@see load_additional_data()};

param: array $questions

is_sortable()   X-Ref
Can this column be sorted on? You can return either:
+ false for no (the default),
+ a field name, if sorting this column corresponds to sorting on that datbase field.
+ an array of subnames to sort on as follows
return [
'firstname' => ['field' => 'uc.firstname', 'title' => get_string('firstname')],
'lastname' => ['field' => 'uc.lastname', 'title' => get_string('lastname')],
];
As well as field, and field, you can also add 'revers' => 1 if you want the default sort
order to be DESC.

return: mixed as above.

sortorder($reverse)   X-Ref
Helper method for building sort clauses.

param: bool $reverse whether the normal direction should be reversed.
return: string 'ASC' or 'DESC'

sort_expression($reverse, $subsort)   X-Ref
Sorts the expressions.

param: bool $reverse Whether to sort in the reverse of the default sort order.
param: string $subsort if is_sortable returns an array of subnames, then this will be
return: string some SQL to go in the order by clause.