Public Member Functions | |
commit ($updateObj=false) | |
Save this object's attributes to a record in the database. | |
copy ($asNew=false) | |
Attempts to make a copy of this object. | |
fromDB ($rep) | |
Populate this object based on a link or representation stored in a foreign database field. | |
getConstraintForPrimaryKey ($skipStorageCheck=false) | |
Get a constraints array that uniquely specifies this object by its primary key. | |
getFormatted ($field, $format) | |
Retrieves a DATE/TIME field and formats it. | |
getPrimaryKey () | |
Retrieves primary key attribute name for this object. | |
getTableName () | |
Retrieves name of table this object represents. | |
getXML ($options=array()) | |
Overridden getXML() more specific for database classes. | |
isDatabaseAttribute ($attrName) | |
Determines if given attribute is one that should go into the database. | |
populate ($constraints, $multi=false) | |
Populate this object's attributes from a record in the database. | |
populateFromResults ($results) | |
Populates this object from query results. | |
populateFromResultsMulti ($results, $mapping=null, $as=null) | |
Populates this object from query results. | |
setFormatted ($field, $newValue) | |
Updates a DATE/TIME field and formats according to what DB requires. | |
toDB () | |
Provide a link to or representation of this object for storage in a foreign database field. | |
Static Public Member Functions | |
static | isDatabaseAttributeStatic ($info) |
Determines if a given attribute is one that should go into the database. | |
Protected Member Functions | |
onDelete () | |
Callback that is invoked during a DELETE operation. | |
onDeleteFinish () | |
Callback that is invoked after a DELETE operation. | |
onInsert ($what) | |
Callback that is invoked during an INSERT operation. | |
onInsertFinish () | |
Callback that is invoked after an INSERT operation. | |
onUpdate ($what) | |
Callback that is invoked during an UPDATE operation. | |
onUpdateFinish () | |
Callback that is invoked after an UPDATE operation. |
This class provides the object-relational mapping (ORM) for an object that will be read from/written to a database. Extend this object to inherit functions for finding/loading/saving your object to/from the database.
This class inherits from SModel2 all features needed to manage a set of attributes, but the functions in this class are specific to using a database for storage.
This is an abstract class that should be extended by model classes that map to actual database tables. When extending this class, you should immediately define static variables that define your database, table, and attributes:
Updated 2/26/09
SDatabaseModel::commit | ( | $ | updateObj = false |
) |
Save this object's attributes to a record in the database.
The database model commit function does the following:
Reimplemented from SModel2.
Reimplemented in View_SDRResourceDetails, and View_SDRResourceMinimal.
SDatabaseModel::copy | ( | $ | asNew = false |
) |
Attempts to make a copy of this object.
See SModel2::copy() for more. For database objects, this may be tricky because committing back to the DB may not be straightforward. The primary key is not copied if it is not an array since it may be auto-increment and thus should not be copied, but should be left alone.
$asNew | [boolean]: if true, pretend this object was never in the DB |
Reimplemented from SModel2.
SDatabaseModel::fromDB | ( | $ | rep | ) |
Populate this object based on a link or representation stored in a foreign database field.
$rep | [string]: The link/representation of the object |
SDatabaseModel::getConstraintForPrimaryKey | ( | $ | skipStorageCheck = false |
) |
Get a constraints array that uniquely specifies this object by its primary key.
$skipStorageCheck | [boolean]: do not use |
SDatabaseModel::getFormatted | ( | $ | field, | |
$ | format | |||
) |
Retrieves a DATE/TIME field and formats it.
$field | [string]: name of field to retrieve | |
$format | [string]: strftime()-compatible string to format the field's value with |
SDatabaseModel::getPrimaryKey | ( | ) |
Retrieves primary key attribute name for this object.
SDatabaseModel::getTableName | ( | ) |
Retrieves name of table this object represents.
SDatabaseModel::getXML | ( | $ | options = array() |
) |
Overridden getXML() more specific for database classes.
All that this method does different is have the root node name default to the table name
$options | [array]: array of options that control how XML is generated (see parent class) |
Reimplemented from SModel2.
SDatabaseModel::isDatabaseAttribute | ( | $ | attrName | ) |
Determines if given attribute is one that should go into the database.
See isDatabaseAttributeStatic().
$attrName | [string]: name of attribute to check |
static SDatabaseModel::isDatabaseAttributeStatic | ( | $ | info | ) | [static] |
Determines if a given attribute is one that should go into the database.
Attributes that go into the database are those which are not objects and are not marked as COMMIT_NOSOURCE and are not arrays.
$info | [array]: attribute information (as would come from getAttributeInfo()) |
SDatabaseModel::onDelete | ( | ) | [protected] |
Callback that is invoked during a DELETE operation.
This method is called after the row has been deleted successfully from the database, but before the transaction has completed. If it returns false, the transaction is cancelled. This method is to be used by derived classes to implement any special functionality that must take place when an object is being deleted, such as deleting, or preparing for deletion, external files. Note that this method is only called after the successful deletion of a row, not after the whole transaction succeeds. It is thus probably best to use onDeleteFinish() to do final cleanup activities as it is called after the transaction succeeds.
SDatabaseModel::onDeleteFinish | ( | ) | [protected] |
Callback that is invoked after a DELETE operation.
This method is called when a transaction that involves this object getting deleted is complete. The database is updated and committed, so this method cannot be used to cancel a pending DELETE. It should be used to clean up any external resources associated with this object.
SDatabaseModel::onInsert | ( | $ | what | ) | [protected] |
Callback that is invoked during an INSERT operation.
This method is called after the INSERT query succeeds, but before the DB transaction is committed.
$what | [array]: attributes and new values that will be inserted into the DB |
SDatabaseModel::onInsertFinish | ( | ) | [protected] |
Callback that is invoked after an INSERT operation.
This method is called after the database transaction is complete and committed. The object is fully updated with new attributes and a primary key from mysql_insert_id, if needed.
SDatabaseModel::onUpdate | ( | $ | what | ) | [protected] |
Callback that is invoked during an UPDATE operation.
This method is called after the UPDATE query succeeds, but before the DB transaction is committed.
$what | [array]: attributes and new values that will be update in the DB |
SDatabaseModel::onUpdateFinish | ( | ) | [protected] |
Callback that is invoked after an UPDATE operation.
This method is called after the database transaction is complete and committed. The object is fully updated and needs no further changes.
SDatabaseModel::populate | ( | $ | constraints, | |
$ | multi = false | |||
) |
Populate this object's attributes from a record in the database.
The database model populate function will:
$constraints | [array]: A set of search constraints to locate a database row | |
$multi | [boolean]: if true, use getListBaseMulti() to grab a JOINed result set |
SDatabaseModel::populateFromResults | ( | $ | results | ) |
Populates this object from query results.
This allows you to populate this object using a custom query. All of the attributes relevant to this object must be named as they would be named in this object. That is, if this object has an attribute called 'foo', then the result attribute should also be called 'foo'. This is different from populateFromResultsMulti().
The results array must be two dimensional: a list of rows, each row being an associative array of attribute => value pairs. This is the same format as returned by DBI2::query()->toArray().
$results | [array]: results array (described above) |
SDatabaseModel::populateFromResultsMulti | ( | $ | results, | |
$ | mapping = null , |
|||
$ | as = null | |||
) |
Populates this object from query results.
This allows you to populate this object using a custom query. All of the attributes relevant to this object must be named 'TABLE_ATTRIBUTE' (e.g. 'MyTable_ATTR_id') This is different from populateFromResults().
The results array must be two dimensional: a list of rows, each row being an associative array of attribute => value pairs. This is the same format as returned by DBI2::query()->toArray().
$results | [array]: results array (described above) | |
$mapping | [array]: maps table and attribute aliases (comes from SQuery::getMapping()) | |
$as | [string]: alias of the table from which to populate this object |
SDatabaseModel::setFormatted | ( | $ | field, | |
$ | newValue | |||
) |
Updates a DATE/TIME field and formats according to what DB requires.
$field | [string]: name of field to update | |
$newValue | [string]: some type of time/date-indicating string that will be converged to standard DB format |
SDatabaseModel::toDB | ( | ) |
Provide a link to or representation of this object for storage in a foreign database field.
Override this function to return a value that will represent or link to this object. By default, it returns the object's primary key -- to be stored as a foreign key during a commit by another object.