Constructor
mr_db_table
__construct
(string $table)
-
string
$table: The table this model represents
Determine if a column exists in the table
boolean
column_exists
(string $name)
-
string
$name: The column name
Convert an object or an array of objects into mr_db_records
Example:
mixed
convert
(mixed $records)
-
mixed
$records: Can be an object, an array of objects, or false
Delete a row from the table
void
delete
(string $id)
-
string
$id: The record ID to delete
Get a row from the table
mixed
get
(int $id)
-
int
$id: The record ID to get
Get meta column data for the table
array
get_columns
()
Get the default for a column
mixed
get_column_default
(string|object $column)
-
string|object
$column: The column name or the column object from get_metacolumn(s)
Get meta data for a specific column
object
get_metacolumn
($name $name)
Get meta column data for the table
array
get_metacolumns
()
Get the table's name
string
get_name
()
Generate a record model for this table
mr_db_record
record
([
mixed $default =
NULL], [
boolean $trustcolumns =
false])
-
mixed
$default: Default record attributes
-
boolean
$trustcolumns: If true, then checks for column exists are bypassed. Only use when performance is an issue (EG: processing hundreds of thousands) and that you KNOW all columns are correct
Save data to the table
-
mixed
$data: Array or object of record data
Route calls to Moodle's lib/dmllib.php functions
You can call the following lib/dmllib.php functions through this class. Pass all parameters as normal except omit the first parameter which is the table name. All methods return their same value as in lib/dmllib.php except when noted otherwise.
- get_record (Returns a mr_db_record)
- get_record_select (Returns a mr_db_record)
- get_records (Returns an array of mr_db_record)
- get_records_select (Returns an array of mr_db_record)
- get_records_list (Returns an array of mr_db_record)
- count_records
- count_records_select
- delete_records
- delete_records_select
- get_field
- get_field_select
- get_records_menu
- get_records_select_menu
- record_exists
- record_exists_select
- set_field
- set_field_select
Examples:
<?php
$records = $table->get_records(); // Gets all records in the table
$record = $table->get_record('field', $value); // Get record from table
$count = $table->count_records();
?>
mixed
__call
(string $name, array $arguments)
-
string
$name: The function name
-
array
$arguments: The arguements to pass, exclude the table name!
Display table name if casted to a string
string
__toString
()