## Class mr_db_table

Description

MR DB Table

Table abstraction.

- author: Mark Nielsen
- example: See this class in action

Located in /db/table.php (line 40)

Variable Summary
string $table
Method Summary
mr_db_table __construct (string $table)
boolean column_exists (string $name)
mixed convert (mixed $records)
void delete (string $id)
mixed get (int $id)
array get_columns ()
mixed get_column_default (string|object $column)
object get_metacolumn ($name $name)
array get_metacolumns ()
string get_name ()
mr_db_record record ([mixed $default = NULL], [boolean $trustcolumns = false])
mr_db_record save (mixed $data)
mixed __call (string $name, array $arguments)
string __toString ()
Variables
string $table (line 46)

The name of the table

- access: protected

Methods
Constructor __construct (line 53)

Constructor

- access: public

mr_db_table __construct (string $table)

- string $table: The table this model represents

column_exists (line 200)

Determine if a column exists in the table

- throws: coding_exception
- access: public

boolean column_exists (string $name)

- string $name: The column name

convert (line 238)

Convert an object or an array of objects into mr_db_records

Example:

1. <?php
2. $table = new mr_db_table('tablename');
3. $table->convert(get_record(...));
4. $table->convert(get_records(...));
5. ?>

- access: public

mixed convert (mixed $records)

- mixed $records: Can be an object, an array of objects, or false

delete (line 292)

Delete a row from the table

- throws: coding_exception
- access: public

void delete (string $id)

- string $id: The record ID to delete

get (line 281)

Get a row from the table

- access: public

mixed get (int $id)

- int $id: The record ID to get

get_columns (line 159)

Get meta column data for the table

- throws: coding_exception
- access: public

array get_columns ()
get_column_default (line 211)

Get the default for a column

- throws: coding_exception
- access: public

mixed get_column_default (string|object $column)

- string|object $column: The column name or the column object from get_metacolumn(s)

get_metacolumn (line 170)

Get meta data for a specific column

- throws: coding_exception
- access: public

object get_metacolumn ($name $name)

- $name $name

get_metacolumns (line 184)

Get meta column data for the table

- throws: coding_exception
- access: public

array get_metacolumns ()
get_name (line 149)

Get the table's name

- access: public

string get_name ()
record (line 260)

Generate a record model for this table

- access: public

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 (line 271)

Save data to the table

- throws: coding_exception
- access: public

mr_db_record save (mixed $data)

- mixed $data: Array or object of record data

__call (line 110)

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:

1. <?php
2. $table = new mr_db_table('tablename');
3. $records = $table->get_records(); // Gets all records in the table
4. $record = $table->get_record('field', $value); // Get record from table
5. $count = $table->count_records();
6. ?>

- see: mr_db_record
- throws: coding_exception
- access: public

mixed __call (string $name, array $arguments)

- string $name: The function name
- array $arguments: The arguements to pass, exclude the table name!

__toString (line 62)

Display table name if casted to a string

- access: public

string __toString ()

Documentation generated on Thu, 28 Jun 2012 16:33:51 -0700 by phpDocumentor 1.4.3