Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Helpers and methods relating to DML tables.

Copyright: 2019 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 133 lines (4 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

table:: (5 methods):
  __construct()
  get_from_sql()
  get_fieldlist()
  get_field_select()
  extract_from_result()


Class: table  - X-Ref

Helpers and methods relating to DML tables.

__construct(string $tablename, string $tablealias, string $fieldprefix)   X-Ref
Constructor for the table class.

param: string  $tablename The name of the table that this instance represents.
param: string  $tablealias The alias to use when selecting the table
param: string  $fieldprefix The prefix to use when selecting fields.

get_from_sql()   X-Ref
Get the from TABLE ALIAS part of the FROM/JOIN string.

return: string

get_fieldlist()   X-Ref
Get the list of fields in a table for use in preloading fields.

return: array       The list of columns in a table. The array key is the column name with an applied prefix.

get_field_select()   X-Ref
Get the SELECT SQL to select a set of columns for this table.

This function is intended to be used in combination with extract_from_result().

return: string      The SQL to use in the SELECT

extract_from_result(stdClass $result)   X-Ref
Extract fields from the specified result. The fields are removed from the original object.

This function is intended to be used in combination with get_field_select().

param: stdClass    $result The result retrieved from the database with fields to be extracted
return: stdClass    The extracted result