{jcomments on}Overview

 

Properties

JTable::_tbl

 

JTable::_tbl_key

 

JTable::_db

 

JTable::_trackAssets

 

JTable::access

 

Methods

JTable::__construct($table, $key, $db)

JTable::__construct is the default object constructor for the JTable class.

Psuedo code

  1. sets the internal variables for the name of the table ("_tbl"), the table key ("_tbl_key") and the database driver for the session ("_db") using the passed parameters;
  2. get the array of fields for the table from the database using JTable::getFields and indirectly JDatabaseDriver::getTableColumns to return an array of column names and their respective types in the form of an associative array mapping the field name to the type {name::string → type};
  3. for each field, ensure that the JTable instance has a property of the same name; and
  4. perform certain asset tracking, access control configuration.

JTable::delete($pk = null)

JTable::delete deletes either the row of the database table to which the relevant JTable instance ("this JTable instance") relates, or the row with the primary key given by the parameter $pk.

PSUEDO CODE

  1. notify observers using the "onBeforeDelete" event;
  2. ascertain the primary key of the relevant database table row either by reference to this JTable instance, or  passed parameter $pk
  3. create and initialise a JDatabaseQuery object containing the SQL delete statement containing a reference to the relevant primary key fieldname and value;
  4. if asset tracking is enabled, load and delete the asset using [asset class]::loadByName, [asset class]::delete;
  5. set the query object for the relevant JDatabaseDriver instance using JDatabaseDriver::setQuery;
  6. execute the query using JDatabaseDriver::execute;
  7. notify observers using the "onAfterDelete" event; and
  8. return true.

Events

JTable::delete notifies observers using the "onBeforeDelete" and "onAfterDelete" events.

JTable::load($keys = null, $reset = true)

JTable::load queries the database table using the primary key and binds the fields to the relevant JTable instance ("this JTable instance").

Psuedo code

  1. notify observers using the "onBeforeLoad" event;
  2. populates an array of type {key::string → value} and uses this in the formation of an appropriate SQL query using a JDatabaseQuery object;
  3. sets the query object for the relevant JDatabaseDriver instance using JDatabaseDriver::setQuery; and
  4. executes the query and obtains from the first row of the resultset an associative array of type {fieldname::string → value} (the "fieldname → value map") using JDatabaseDriver::loadAssoc and indirectly JDatabaseDriver::fetchAssoc;
  5. copies the values provided by the fieldname → value map to the properties of this JTable instance using JTable::bind;
  6. notify observers using the "onAfterLoad" event; and
  7. returns true if the required row of the underlying table was found, and returns false if not.

EVENTS

JTable::load notifies observers using the "onBeforeLoad" and "onAfterLoad" events.

Exceptions

JTable::save($src, $orderingFilter = '', $ignore = '')

JTable::save copies the contents of a source associative array of type {fieldname::string → value} (the "source fieldname → value map") to the relevant JTable instance ("this JTable instance"), performs some checks and stores the properties of this JTable instance to the underlying table.

Pseudo code

  1. copies the values of the source fieldname → value map to this JTable instance using JTable::bind;
  2. checks this JTable instance using JTable::check;
  3. stores the properties of this JTable instance using JTable::store;
  4. attempts to check in (or unlock) the relevant row if it was checked out (locked) using JTable::checkin;
  5. if an ordering filter is set, attempts to re-order the rows in the rows in the table based on the filter and value using JTable::reorder; and
  6. returns true.

 JTable::store($updateNulls = false)

JTable::store updates the database table row with the contents of the row represented by the relevant JTable instance ("this JTable instance").

PSUEDO CODE

  1. notifies observers using the "onBeforeStore" event;
  2. <asset logic>
  3. if a primary key exists for this JTable instance
  4. update the relevant database table row using JDatabaseDriver::updateObject passing this JTable instance as a parameter, the properties of which match the fields of the database table, and the fieldname of the primary key;
  5. else
  6. insert a new database table row using JDatabaseDriver::insertObject passing this JTable instance as a parameter, the properties of which match the fields of the database table, and the fieldname of the primary key;
  7. end if
  8. <further asset logic>
  9. notifies observers using the "onAfterStore" event; and
  10. returns the result.

Events

JTable::store notifies observers using the "onBeforeStore" and "onAfterStore" events.