Differences Between: [Versions 400 and 403] [Versions 401 and 403] [Versions 402 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: | 476 lines (16 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
column_base:: (28 methods):
from_column_name()
set_as_heading()
is_extra_row()
has_preference()
get_preference_key()
get_preference()
display_header()
get_title_tip()
help_icon()
make_sort_link()
get_sort_icon()
display()
display_start()
get_classes()
get_column_name()
get_column_id()
get_extra_classes()
get_default_width()
display_end()
get_extra_joins()
get_required_fields()
get_required_statistics_fields()
load_additional_data()
load_question_tags()
is_sortable()
sortorder()
sort_expression()
display_preview()
Class: column_base - X-Ref
Base class for representing a column.from_column_name(view $view, string $columnname) X-Ref |
Return an instance of this column, based on the column name. In the case of the base class, we don't actually use the column name since the class represents one specific column. However, sub-classes may use the column name as an additional constructor to the parameter. param: view $view Question bank view param: string $columnname The column name for this instance, as returned by {@see get_column_name()} return: column_base An instance of this class. |
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(array $columnactions = [], string $width = '') X-Ref |
Output the column header cell. param: column_action_base[] $columnactions A list of column actions to include in the header. param: string $width A CSS width property value. |
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($sortname, $title, $tip, $defaultreverse = false) X-Ref |
Get a link that changes the sort order, and indicates the current sort state. param: string $sortname 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_column_id() X-Ref |
Return a unique ID for this column object. This is constructed using the class name and get_column_name(), which must be unique. The combination of these attributes allows the object to be reconstructed, by splitting the ID into its constituent parts then calling {@see from_column_name()}, like this: [$class, $columnname] = explode(column_base::ID_SEPARATOR, $columnid, 2); $column = $class::from_column_name($qbank, $columnname); Including 2 as the $limit parameter for explode() is a good idea for safely, in case a plugin defines a column with the ID_SEPARATOR in the column name. return: string The column ID. |
get_extra_classes() X-Ref |
Any extra class names you would like applied to every cell in this column. return: array |
get_default_width() X-Ref |
Return the default column width in pixels. return: int |
display_end($question, $rowclasses) X-Ref |
Output the closing column tag param: object $question param: string $rowclasses |
get_extra_joins() X-Ref |
No description |
get_required_fields() X-Ref |
No description |
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. |
display_preview(\stdClass $question, string $rowclasses) X-Ref |
Output the column with an example value. By default, this will call $this->display() using whatever dummy data is passed in. Columns can override this to provide example output without requiring valid data. param: \stdClass $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. |