Public Member Functions | |
__construct ($id="") | |
Create (and optionally populate) a new model object. | |
commit () | |
Save this object to one row of its linked database entity. | |
commitForeign ($table, $unique, $attributes, $foreignKey) | |
INSERT BRIEF DESCRIPTION HERE. | |
DBIHasNoError ($function="<not specified>", $msg="") | |
INSERT BRIEF DESCRIPTION HERE. | |
getAllAttributes () | |
INSERT BRIEF DESCRIPTION HERE. | |
getAttributes () | |
Get the names of all attributes for this object/entity. | |
getByCriteria ($criteria) | |
(DEPRECATED) | |
getDBI () | |
Get the DBI class this object is using as a database interface. | |
getEntity () | |
Get the name of the database entity that this object will populate from/commit to. | |
getForeignKey () | |
INSERT BRIEF DESCRIPTION HERE. | |
getList ($criteria="", $nullable=false) | |
Get a list of objects of this type from the database, based on a set of constraints. | |
getUniqueAttributes () | |
Get the list of unique attributes for this object (candidate keys). | |
isValidObject () | |
Check to see if this object is ready to commit. | |
markForDeletion () | |
Mark this object to be deleted when it is next committed. | |
populate ($id="") | |
Populate this object from one row of its linked database entity. | |
reset () | |
Set all attribute values to null. Remove 'marked for deletion' flag. | |
setDBI ($DBI) | |
Set the DBI class this object should use as a database interface. | |
superGetList ($criteria, $order="", $limit="") | |
INSERT BRIEF DESCRIPTION HERE. | |
unmarkForDeletion () | |
If this object has been marked for deletion, clear that marking. |
Extend this class to create objects that can easily be read from/write to the database.
In order to build your own SModel class, simply extend this class and implement the getAttributes() and getUniqueAttributes() functions in your subclass. Also set the entity in the constructor or implement getEntity() if you want to use a different entity name from the name of the class (SModel will lowercase the first letter of the class name).
To read from/write to the database, simply call populate() and commit() on your SModel objects. Also, SModel objects allow you to search for a list of objects of the same type using the getList() function.
SModel::__construct | ( | $ | id = "" |
) |
Create (and optionally populate) a new model object.
Create a new model object. Set the name of the database entity this object will query to the name of this class (but changing the first letter to lowercase).
If you pass in an id, the object will attempt to populate using that id number as the primary key.
$id | [int]: The object's primary key (optional) |
Reimplemented in SSurvey.
SModel::commit | ( | ) |
Save this object to one row of its linked database entity.
Check to see whether this object has a primary key. If not, attempt to insert a new row into the linked database entity for this object. If so, attempt to update the row specified by the primary key.
Copy all the relevant attributes, listed by this object's getAttributes() function, to the database row.
If we have just inserted a new row of the table, set this object's primary key to the id of the new primary key generated by the database insert.
Reimplemented in SGlobalUser.
SModel::commitForeign | ( | $ | table, | |
$ | unique, | |||
$ | attributes, | |||
$ | foreignKey | |||
) |
INSERT BRIEF DESCRIPTION HERE.
INSERT FULL DESCRIPTION HERE
$table | [TYPE]: DESCRIPTION | |
$unique | [TYPE]: DESCRIPTION | |
$attributes | [TYPE]: DESCRIPTION | |
$foreignKey | [TYPE]: DESCRIPTION |
SModel::DBIHasNoError | ( | $ | function = "<not specified>" , |
|
$ | msg = "" | |||
) |
INSERT BRIEF DESCRIPTION HERE.
INSERT FULL DESCRIPTION HERE
$function | [TYPE]: DESCRIPTION | |
$msg | [TYPE]: DESCRIPTION |
SModel::getAllAttributes | ( | ) |
INSERT BRIEF DESCRIPTION HERE.
INSERT FULL DESCRIPTION HERE
SModel::getAttributes | ( | ) |
Get the names of all attributes for this object/entity.
Return an array of all the instance variables for this object/entity that should be committed to the database when commit() is called on this object.
Reimplemented in CSERDUser, SEvent, SQuestion, SResponse, SSurvey, SGlobalUser, and SUser.
SModel::getByCriteria | ( | $ | criteria | ) |
(DEPRECATED)
INSERT FULL DESCRIPTION HERE
$criteria | [TYPE]: DESCRIPTION |
SModel::getDBI | ( | ) |
SModel::getEntity | ( | ) |
SModel::getForeignKey | ( | ) |
INSERT BRIEF DESCRIPTION HERE.
INSERT FULL DESCRIPTION HERE
SModel::getList | ( | $ | criteria = "" , |
|
$ | nullable = false | |||
) |
Get a list of objects of this type from the database, based on a set of constraints.
Search for a list of rows in this object's linked database entity, based on the constraints passed in. For each row found, create an object of the same type as this object. Return those objects as an array.
$criteria | [array]: The search criteria | |
$nullable | [TYPE]: DESCRIPTION |
SModel::getUniqueAttributes | ( | ) |
Get the list of unique attributes for this object (candidate keys).
Return a list of the unique attributes (candidate keys) for this object. The first item in this list must be the primary key. But you should theoretically be able to populate on any attribute in this list.
For most objects, this function will return a list with one element -- the string 'id'
Reimplemented in CSERDUser, SEvent, SQuestion, SResponse, SSurvey, SGlobalUser, and SUser.
SModel::isValidObject | ( | ) |
Check to see if this object is ready to commit.
This function is called by commit() before the object is written to the database. You can implement this function in your subclass to put in place some checks that must be true before the object can be committed.
SModel::markForDeletion | ( | ) |
Mark this object to be deleted when it is next committed.
This is a flag that you can set on the object so that, when you call commit() next, the row corresponding to this object will be deleted from the linked database entity.
SModel::populate | ( | $ | id = "" |
) |
Populate this object from one row of its linked database entity.
Lookup one row in the database based on the passed id/primary key value. If no value is passed in, check to see whether any of the other unique attributes are set on this object. If so, attempt to populate on those in the order they are listed by getUniqueAttributes().
Once we have found a row, select all the relevant attributes from that row, listed by this object's getAttributes() function. Then, copy the values from that row into this object's instance variables.
$id | [mixed]: A primary key value on which to populate this object |
SModel::setDBI | ( | $ | DBI | ) |
SModel::superGetList | ( | $ | criteria, | |
$ | order = "" , |
|||
$ | limit = "" | |||
) |
INSERT BRIEF DESCRIPTION HERE.
INSERT FULL DESCRIPTION HERE
$criteria | [TYPE]: DESCRIPTION | |
$order | [TYPE]: DESCRIPTION | |
$limit | [TYPE]: DESCRIPTION |