SDatabaseModel Class Reference
[Database Objects]

A generic model object that is populated/committed to a database. More...

Inheritance diagram for SDatabaseModel:

Inheritance graph
[legend]

List of all members.

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.
 finishDelete ($status)
 Completes the DELETE operation at the end of the transaction.
 finishInsert ($status)
 Completes the INSERT operation at the end of the transaction.
 finishUpdate ($status)
 Completes the UPDATE operation at the end of the transaction.
 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.
 populateWith (&$row, $mapping=null, $as=null)
 Initialize this object with data from a JOIN.
 prepareUpdate ($isUpdate)
 Grabs attributes to be committed, among other things.
 registerDBI ($DBI)
 Register this object's DBI@ with the parent class.
 registerPrimaryKey ($primaryKey, $isAuto=true)
 Register this object's primary key name with the parent class.
 registerTableName ($tableName)
 Register this object's table name with the parent class.
 setAttrsFromDBResult ($dbResult)
 Set this object's attributes from a DBResult object.
 setAttrsFromMultiDBResult ($dbResult, $mapping=null, $as=null)
 Set this object's attributes from a DBResult object.

Static Protected Member Functions

static getListBase ($DBI, $constraints, $limit, $order, $count, $objClass, $asObjects=true, $extraJoins=array(), $groupBy=array(), $extraAttrs=array())
 Do the bulk of the work for getList() requests.
static getListBaseMulti ($DBI, $constraints, $limit, $order, $count, $objClass, $asObjects=true, $depth=1, $extraJoins=array(), $groupBy=array(), $extraAttrs=array(), $extraTables=array())
 Retrieves list of objects using JOINs.


Detailed Description

A generic model object that is populated/committed to a database.

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:

Date:
Started 2/9/09

Updated 2/26/09

Author:
Joel Feiner <jfeiner@shodor.org>

Jonathan Stuart-Moore <jwsm@shodor.org>

Definition at line 31 of file SDatabaseModel.php5.


Member Function Documentation

SDatabaseModel::commit ( updateObj = false  ) 

Save this object's attributes to a record in the database.

The database model commit function does the following:

  • Check if the object is valid
    • If the object isStored() (there is already a DB row for the object):
      • Use the object's $primaryKey attribute to find our row in $tableName
      • Begin a database transaction (if one is not in progress)
      • If the object is marked for deletion:
        • Delete the database row, but don't commit the transaction
        • Call onDelete(), which is a callback that derived classes can implement to perform additional processing during a DELETE operation
        • Commit the transaction and return true
      • Check for any attributes that are objects or foreign keys, and commit() those objects (this is done in the prepareUpdate() method)
      • Write an UPDATE query that only changes $currentValues (no need to modify $baseValues, as their values have not changed) in our DB row
      • Run the query on $DBI
    • If the object !isStored() (there's no record of it yet in the DB):
      • Check for any attributes that are objects, and commit() those objects (this is done in the prepareUpdate() method)
      • Write an INSERT query to save all values returned from getValues() (base values overridden by current values)
      • Run the query on $DBI
      • Set the $primaryKey attribute value to the mysql_insert_id
  • Pass on the list of attributes that need to have their 'commit' flag reset after an INSERT
    • Return true/false for success/failure
    Later, the DBI will call the finishUpdate(), finishInsert() or finishDelete() method, depending on the query, which will actually update the object and its attribute 'commit' flags, but only if the transaction succeeded. This way, if the transaction fails, we will not have objects lying around in an invalid state.

Returns:
[bool]: True on success; false on error

Reimplemented from SModel2.

Reimplemented in View_SDRResourceDetails, and View_SDRResourceMinimal.

Definition at line 370 of file SDatabaseModel.php5.

References finishDelete(), finishInsert(), finishUpdate(), getConstraintForPrimaryKey(), getPrimaryKey(), getTableName(), SObject::hasError(), SModel2::isMarkedForDeletion(), SModel2::isStored(), SModel2::isValid(), onDelete(), onInsert(), onUpdate(), prepareUpdate(), and SObject::setError().

Referenced by CSERDuser::addcomment(), CSERDreview::addcomment(), AuthUser::addConfirmEmail(), AuthEmailTemplate::addEmailHeader(), AuthPermission::addGenGroupToPermission(), AuthGenGroup::addGenGroupToPermission(), AuthUser::addResetPassword(), CSERDreview::addresponse(), CSERDquestion::addresponse(), CSERDuser::addreview(), CSERDsubject::addreviewSubject(), CSERDreview::addreviewSubject(), SDRValue::addSDRDateValue(), SDRValue::addSDRFieldValue(), SDRField::addSDRFieldValue(), SDRValue::addSDRIntValue(), SDRProject::addSDRProjectField(), SDRField::addSDRProjectField(), SDRProject::addSDRResource(), SDRVersionCache::addSDRResourceCache(), SDRResource::addSDRResourceProject(), SDRProject::addSDRResourceProject(), SDRSearchWord::addSDRSearchWordCount(), SDRResource::addSDRSearchWordCount(), SDRField::addSDRSearchWordCount(), SDRValue::addSDRTextValue(), SDRResource::addSDRVersion(), SDRAgent::addSDRVersion(), SDRVersion::addSDRVersionCache(), SDRResource::addSDRVersionCache(), SDRVersion::addSDRVersionFieldValue(), SDRValue::addSDRVersionFieldValue(), SDRField::addSDRVersionFieldValue(), AuthHashType::addUser(), AuthUser::addUserConfig(), CSERDuser::adduserDetail(), CSERDdetail::adduserDetail(), CSERDuser::adduserLoginLog(), CSERDuser::adduserPageviewLog(), AuthUser::addUserToGenGroup(), AuthGenGroup::addUserToGenGroup(), AuthUser::addUserToPermission(), AuthPermission::addUserToPermission(), AuthUser::addUserToProject(), AuthProject::addUserToProject(), SDRAgent::agentFromCSERDUser(), SDRAgent::agentFromS2User(), SDRAgent::agentFromSUser(), SDRVersion::createVersion(), SDRField::findOrAddField(), SDRProjectField::findOrAddProjectField(), SDRValue::findOrAddValue(), and prepareUpdate().

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.

Parameters:
$asNew [boolean]: if true, pretend this object was never in the DB
Returns:
[SDatabaseModel]: object that is copy of this object, or null on error

Reimplemented from SModel2.

Definition at line 702 of file SDatabaseModel.php5.

References SModel2::getAttributeDefault().

SDatabaseModel::finishDelete ( status  ) 

Completes the DELETE operation at the end of the transaction.

For internal use only.

This method is called after the transaction is completed to finish deleting the object. All this method does is call the onDeleteFinish() callback and then resets this object to a raw state.

Parameters:
$status [boolean]: true if DELETE operation succeeded, falso otherwise

Definition at line 474 of file SDatabaseModel.php5.

References SModel2::nullify(), and onDeleteFinish().

Referenced by commit().

SDatabaseModel::finishInsert ( status  ) 

Completes the INSERT operation at the end of the transaction.

For internal use only.

This method is called after the transaction is completed to finish deleting the object. This method must reset attributes that are marked as COMMIT_FIRST to COMMIT_CHANGED, since the object has finished inserting and now should just operate as normal. It must also update the base attributes using the current attributes. Finally, it calls onInsertFinish() to allow users of the class to do additional work after the insert.

Parameters:
$status [boolean]: true if transaction completed successfully

Definition at line 522 of file SDatabaseModel.php5.

References SModel2::changeAttribute(), onInsertFinish(), and SModel2::updateBase().

Referenced by commit().

SDatabaseModel::finishUpdate ( status  ) 

Completes the UPDATE operation at the end of the transaction.

For internal use only.

This method is called after the transaction is completed to finish deleting the object. This method must reset attributes that are marked as COMMIT_FIRST to COMMIT_CHANGED, since the object has finished updating and now should just operate as normal. It must also update the base attributes using the current attributes. Finally, it calls onUpdateFinish() to allow users of the class to do additional work after the update.

Parameters:
$status [boolean]: true if transaction completed successfully

Definition at line 494 of file SDatabaseModel.php5.

References SModel2::changeAttribute(), onUpdateFinish(), and SModel2::updateBase().

Referenced by commit().

SDatabaseModel::fromDB ( rep  ) 

Populate this object based on a link or representation stored in a foreign database field.

Parameters:
$rep [string]: The link/representation of the object
Override this function to populate this object from the value of $rep. By default, it will call populate and pass in $rep as the primary key. ???

Definition at line 986 of file SDatabaseModel.php5.

References populate().

SDatabaseModel::getConstraintForPrimaryKey ( skipStorageCheck = false  ) 

Get a constraints array that uniquely specifies this object by its primary key.

Parameters:
$skipStorageCheck [boolean]: do not use
Returns:
[array]: An array with one item, where the key is the object's primary key attribute, and the value is this object's value of the primary key. Return false if the object is not yet stored.

For internal use only.

Note:
$skipStorageCheck is used by commit() in the case that we need to INSERT and then UPDATE an object in the middle of a transaction

Definition at line 670 of file SDatabaseModel.php5.

References SModel2::isStored(), and SObject::setError().

Referenced by commit().

SDatabaseModel::getFormatted ( field,
format 
)

Retrieves a DATE/TIME field and formats it.

Parameters:
$field [string]: name of field to retrieve
$format [string]: strftime()-compatible string to format the field's value with
Returns:
[string]: formatted value of $field or false if field does not exist

Definition at line 997 of file SDatabaseModel.php5.

References SModel2::attributeExists(), DBI2::formatTimestamp(), and SObject::setError().

static SDatabaseModel::getListBase ( DBI,
constraints,
limit,
order,
count,
objClass,
asObjects = true,
extraJoins = array(),
groupBy = array(),
extraAttrs = array() 
) [static, protected]

Do the bulk of the work for getList() requests.

For internal use only.

This function takes an optional set of constraints (no constraints will find all objects). These constraints limit the values of different attributes. This function will search table $tableName in database $DBI for rows matching the constraints. It then populates and returns an array of instances of the class that called the function.

Parameters:
$DBI [DBI2]: DBI object to query
$constraints [array]: The search constraints
$limit [array]: The search limit
$order [array]: How to order search objects
$count [boolean]: If true, only return the count of results, otherwise, return the results themselves
$objClass [string]: class name of object with which objects are created
$asObjects [bool]: if true, return array of objects, otherwise, just return resultset
$extraJoins [array]: additional joins to make in the query (see SQuery::setExtraJoins())
$groupBy [array]: additional group by clause (see SQuery::setGroupBy())
$extraAttrs [array]: additional attributes to be selected (see SQuery::setExtraAttrs)
Returns:
[array]: The set of matching objects, or the count of results if $count is true, or a resultset if $count is false and $asObjects is false

Definition at line 742 of file SDatabaseModel.php5.

References STimer::endAvg(), and STimer::startAvg().

static SDatabaseModel::getListBaseMulti ( DBI,
constraints,
limit,
order,
count,
objClass,
asObjects = true,
depth = 1,
extraJoins = array(),
groupBy = array(),
extraAttrs = array(),
extraTables = array() 
) [static, protected]

Retrieves list of objects using JOINs.

For internal use only.

Parameters:
$DBI [DBI2]: DBI2 object to use for queries
$constraints [array]: query constraints array for WHERE clause
$limit [array]: query limit array for LIMIT clause
$order [array]: query order array for ORDER BY clause
$count [boolean]: if true, only return the count of objects that would be returned (nearly equivalent to calling getListBase() with $count = true)
$objClass [string]: class name of class to be used when creating objects
$asObjects [bool]: if true, return array of objects, otherwise, just return resultset
$extraJoins [array]: additional joins to make in the query (see SQuery::setExtraJoins())
$groupBy [array]: additional group by clause (see SQuery::setGroupBy())
$extraAttrs [array]: additional attributes to be selected (see SQuery::setExtraAttrs)
$extraTables [array]: additional tables to be selected (see SQuery::setExtraTables)
Returns:
[array]: list of objects, or flat array of a mapping array and resultset if $asObjects is false, or a count if $count is true; or null on error

Definition at line 821 of file SDatabaseModel.php5.

References STimer::endAvg(), and STimer::startAvg().

SDatabaseModel::getPrimaryKey (  ) 

Retrieves primary key attribute name for this object.

Returns:
[string]: name of attribute that is considered the primary key, if any

Definition at line 1049 of file SDatabaseModel.php5.

Referenced by commit(), and prepareUpdate().

SDatabaseModel::getTableName (  ) 

Retrieves name of table this object represents.

Returns:
[string]: name of table

Definition at line 1040 of file SDatabaseModel.php5.

Referenced by commit().

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

Parameters:
$options [array]: array of options that control how XML is generated (see parent class)
Returns:
[mixed]: string of XML or SimpleXML object

Reimplemented from SModel2.

Definition at line 1029 of file SDatabaseModel.php5.

SDatabaseModel::isDatabaseAttribute ( attrName  ) 

Determines if given attribute is one that should go into the database.

See isDatabaseAttributeStatic().

Parameters:
$attrName [string]: name of attribute to check
Returns:
[boolean]: whether attribute satisfies conditions in isDatabaseAttributeStatic()

Definition at line 1120 of file SDatabaseModel.php5.

References SModel2::getAttributeInfo().

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.

Parameters:
$info [array]: attribute information (as would come from getAttributeInfo())
Returns:
[boolean]: whether attribute satisfies above conditions

Definition at line 1102 of file SDatabaseModel.php5.

References SModel2::COMMIT_NOSOURCE.

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.

Returns:
[boolean]: true to continue transaction; false to cancel it

Definition at line 903 of file SDatabaseModel.php5.

Referenced by commit().

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.

Definition at line 914 of file SDatabaseModel.php5.

Referenced by finishDelete().

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.

Parameters:
$what [array]: attributes and new values that will be inserted into the DB
Returns:
[boolean]: true to continue transaction; false to cancel it

Definition at line 925 of file SDatabaseModel.php5.

Referenced by commit().

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.

Definition at line 936 of file SDatabaseModel.php5.

Referenced by finishInsert().

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.

Parameters:
$what [array]: attributes and new values that will be update in the DB
Returns:
[boolean]: true to continue transaction; false to cancel it

Definition at line 947 of file SDatabaseModel.php5.

Referenced by commit().

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.

Definition at line 957 of file SDatabaseModel.php5.

Referenced by finishUpdate().

SDatabaseModel::populate ( constraints,
multi = false 
)

Populate this object's attributes from a record in the database.

The database model populate function will:

  • Call getListBase() or getListBaseMulti() to search the database using $constraints
  • Return false if no matches are found
  • Select the first matching database row
  • Copy values from the database row to the object's attributes
  • Report an error if there is a type mismatch
  • Otherwise, mark the object as stored and copy current attributes to base attributes, among other things
  • Return true/false based on success/failure of copying data

Parameters:
$constraints [array]: A set of search constraints to locate a database row
$multi [boolean]: if true, use getListBaseMulti() to grab a JOINed result set
Returns:
[bool]: True on success; false on error

Definition at line 70 of file SDatabaseModel.php5.

References setAttrsFromDBResult(), setAttrsFromMultiDBResult(), SObject::setError(), and SModel2::updateBase().

Referenced by AuthUserToProject::__construct(), AuthUserToPermission::__construct(), AuthUserToGenGroup::__construct(), AuthUserConfig::__construct(), AuthUser::__construct(), AuthResetPassword::__construct(), AuthProject::__construct(), AuthPermission::__construct(), AuthInvalidLoginAttempt::__construct(), AuthHashType::__construct(), AuthGenGroupToPermission::__construct(), AuthGenGroup::__construct(), AuthEmailTemplate::__construct(), AuthEmailHeader::__construct(), AuthConfirmEmail::__construct(), View_SDRResourceMinimal::__construct(), View_SDRResourceDetails::__construct(), SDRVersionFieldValue::__construct(), SDRVersionCache::__construct(), SDRVersion::__construct(), SDRValueCache::__construct(), SDRValue::__construct(), SDRTextValue::__construct(), SDRSearchWordCount::__construct(), SDRSearchWord::__construct(), SDRResourceProject::__construct(), SDRResourceCache::__construct(), SDRResource::__construct(), SDRProjectField::__construct(), SDRProject::__construct(), SDRIntValue::__construct(), SDRFieldValue::__construct(), SDRField::__construct(), SDRDateValue::__construct(), SDRAgent::__construct(), SDRAdminLdapRole::__construct(), CSERDuserPageviewLog::__construct(), CSERDuserLoginLog::__construct(), CSERDuserDetail::__construct(), CSERDuser::__construct(), CSERDsubject::__construct(), CSERDreviewSubject::__construct(), CSERDreview::__construct(), CSERDresponse::__construct(), CSERDquestion::__construct(), CSERDnotification::__construct(), CSERDldapUser::__construct(), CSERDdetail::__construct(), CSERDcomment::__construct(), and fromDB().

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().

Parameters:
$results [array]: results array (described above)
Returns:
[boolean]: success or failure

Definition at line 308 of file SDatabaseModel.php5.

References setAttrsFromDBResult().

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().

Parameters:
$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
Returns:
[boolean]: success or failure

Definition at line 327 of file SDatabaseModel.php5.

References setAttrsFromMultiDBResult().

SDatabaseModel::populateWith ( &$  row,
mapping = null,
as = null 
) [protected]

Initialize this object with data from a JOIN.

For internal use only.

This is used by setAttrsFromMultiDBResult() to initialize foreign key objects. It basically extracts the fields that belong to this object from the passed in row and initializes this object with the attributes. If any attributes are themselves foreign key attributes, they are used to recursively initialize the corresponding foreign key objects with more calls to populateWith().

Parameters:
$row [array]: row from DB query result
$mapping [array]: maps table and attribute aliases (comes from SQuery::getMapping())
$as [string]: alias of the table from which to populate this object
Returns:
[boolean]: success or failure

Definition at line 130 of file SDatabaseModel.php5.

References SModel2::getAttributeForeign(), SModel2::getAttributeType(), and SModel2::updateBase().

SDatabaseModel::prepareUpdate ( isUpdate  )  [protected]

Grabs attributes to be committed, among other things.

For internal use only.

This method grabs all attributes that need to be in the database commit query. It also checks to see if any COMMIT_FIRST attributes need to have their type changed to COMMIT_CHANGED. It takes an approach of many failures are allowed. Thus, if there are multiple errors, they will all be reported, instead of just bailing on the first error.

Parameters:
$isUpdate [boolean]: true if this is for an UPDATE, false for an INSERT
Returns:
[array]: boolean indicating error, array of attributes to reset to COMMIT_CHANGED and an associative array of attribute => new value pairs to put into the DB

Definition at line 550 of file SDatabaseModel.php5.

References commit(), SModel2::getAttributes(), SObject::getErrorFrom(), getPrimaryKey(), SModel2::isChanged(), SModel2::isDirty(), and SObject::setError().

Referenced by commit().

SDatabaseModel::registerDBI ( DBI  )  [protected]

Register this object's DBI@ with the parent class.

For internal use only.

Call this function from your constructor

Parameters:
$DBI [DBI2]: The DBI2 registered with the DBI2 class

Definition at line 1061 of file SDatabaseModel.php5.

References SObject::setError().

Referenced by AuthModelBase::__construct(), SDRModel::__construct(), ModelBase::__construct(), and CSERDModelBase::__construct().

SDatabaseModel::registerPrimaryKey ( primaryKey,
isAuto = true 
) [protected]

Register this object's primary key name with the parent class.

For internal use only.

Parameters:
$primaryKey [string]: The name of the primary key of this object
Call this function from your constructor

Definition at line 1088 of file SDatabaseModel.php5.

Referenced by AuthUserToProject::__construct(), AuthUserToPermission::__construct(), AuthUserToGenGroup::__construct(), AuthUserConfig::__construct(), AuthUser::__construct(), AuthResetPassword::__construct(), AuthProject::__construct(), AuthPermission::__construct(), AuthHashType::__construct(), AuthGenGroupToPermission::__construct(), AuthGenGroup::__construct(), AuthEmailTemplate::__construct(), AuthEmailHeader::__construct(), AuthConfirmEmail::__construct(), View_SDRResourceMinimal::__construct(), View_SDRResourceDetails::__construct(), SDRVersionFieldValue::__construct(), SDRVersionCache::__construct(), SDRVersion::__construct(), SDRValueCache::__construct(), SDRValue::__construct(), SDRTextValue::__construct(), SDRSearchWordCount::__construct(), SDRSearchWord::__construct(), SDRResourceProject::__construct(), SDRResourceCache::__construct(), SDRResource::__construct(), SDRProjectField::__construct(), SDRProject::__construct(), SDRIntValue::__construct(), SDRFieldValue::__construct(), SDRField::__construct(), SDRDateValue::__construct(), SDRAgent::__construct(), CSERDuserPageviewLog::__construct(), CSERDuserLoginLog::__construct(), CSERDuser::__construct(), CSERDsubject::__construct(), CSERDreview::__construct(), CSERDresponse::__construct(), CSERDquestion::__construct(), CSERDnotification::__construct(), CSERDdetail::__construct(), and CSERDcomment::__construct().

SDatabaseModel::registerTableName ( tableName  )  [protected]

Register this object's table name with the parent class.

For internal use only.

Parameters:
$tableName [string]: The name of the table mapping to this object
Call this function from your constructor

Definition at line 1077 of file SDatabaseModel.php5.

Referenced by AuthUserToProject::__construct(), AuthUserToPermission::__construct(), AuthUserToGenGroup::__construct(), AuthUserConfig::__construct(), AuthUser::__construct(), AuthResetPassword::__construct(), AuthProject::__construct(), AuthPermission::__construct(), AuthInvalidLoginAttempt::__construct(), AuthHashType::__construct(), AuthGenGroupToPermission::__construct(), AuthGenGroup::__construct(), AuthEmailTemplate::__construct(), AuthEmailHeader::__construct(), AuthConfirmEmail::__construct(), View_SDRResourceMinimal::__construct(), View_SDRResourceDetails::__construct(), SDRVersionFieldValue::__construct(), SDRVersionCache::__construct(), SDRVersion::__construct(), SDRValueCache::__construct(), SDRValue::__construct(), SDRTextValue::__construct(), SDRSearchWordCount::__construct(), SDRSearchWord::__construct(), SDRResourceProject::__construct(), SDRResourceCache::__construct(), SDRResource::__construct(), SDRProjectField::__construct(), SDRProject::__construct(), SDRIntValue::__construct(), SDRFieldValue::__construct(), SDRField::__construct(), SDRDateValue::__construct(), SDRAgent::__construct(), SDRAdminLdapRole::__construct(), CSERDuserPageviewLog::__construct(), CSERDuserLoginLog::__construct(), CSERDuserDetail::__construct(), CSERDuser::__construct(), CSERDsubject::__construct(), CSERDreviewSubject::__construct(), CSERDreview::__construct(), CSERDresponse::__construct(), CSERDquestion::__construct(), CSERDnotification::__construct(), CSERDldapUser::__construct(), CSERDdetail::__construct(), and CSERDcomment::__construct().

SDatabaseModel::setAttrsFromDBResult ( dbResult  )  [protected]

Set this object's attributes from a DBResult object.

For internal use only.

  • Match DB column names with attribute names to copy data
  • If the attribute type is INT or STRING, copy DB value directly
  • If the attribute type is object, create an instance of the object and call the "fromDB()" method on that object, passing in the DB value
  • If the attribute is an array, flag a warning and move on

Parameters:
$dbResult [DBResult row]: row from DB query result
Returns:
[bool]: True on success; false on error

Definition at line 186 of file SDatabaseModel.php5.

References SModel2::changeAttribute(), SModel2::getAttributes(), and SObject::setError().

Referenced by populate(), and populateFromResults().

SDatabaseModel::setAttrsFromMultiDBResult ( dbResult,
mapping = null,
as = null 
) [protected]

Set this object's attributes from a DBResult object.

For internal use only.

  • Match DB column names with attribute names to copy data
  • If the attribute type is INT or STRING, copy DB value directly
  • If the attribute type is object, create an instance of the object and call the "fromDB()" method on that object, passing in the DB value
  • If the attribute is an array, flag a warning and move on
  • If attribute is a foreign key, then instantiate the associated object and have it initialize from the resultset

Parameters:
$dbResult [DBResult row]: row from DB query
$mapping [array]: maps table and attribute aliases (comes from SQuery::getMapping())
$as [string]: alias of the table from which to populate this object
Returns:
[bool]: True on success; false on error

Definition at line 242 of file SDatabaseModel.php5.

References SModel2::changeAttribute(), SModel2::getAttributes(), SModel2::getAttributeType(), and SObject::setError().

Referenced by populate(), and populateFromResultsMulti().

SDatabaseModel::setFormatted ( field,
newValue 
)

Updates a DATE/TIME field and formats according to what DB requires.

Parameters:
$field [string]: name of field to update
$newValue [string]: some type of time/date-indicating string that will be converged to standard DB format
Returns:
[boolean]: false if field does not exist, true otherwise

Definition at line 1012 of file SDatabaseModel.php5.

References SModel2::attributeExists(), and SObject::setError().

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.

Returns:
[string]: The link/representation of the object

Definition at line 974 of file SDatabaseModel.php5.


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:05:56 2010 for Common by  doxygen 1.5.6