Framework
3.9
|
DataItem is the generic base class for database mapped classes. More...
Public Member Functions | |
DataItem () | |
Constructor. More... | |
__sleep () | |
fireEvent ($event) | |
Fires the specified event to all registered handlers. More... | |
joinTransaction ($tx) | |
Join the DataItem to the specified DataTransaction. More... | |
getTransaction () | |
Retrieves the current DataTransaction. More... | |
cast ($class) | |
Cast this object to another class. More... | |
disablePrimaryKey () | |
enablePrimaryKey () | |
getHiddenFields () | |
Retrieves the list of hidden fields. More... | |
populate ($line, $alias=false) | |
Populates the object using the supplied associative array (field -> value). More... | |
getFields () | |
Retrieve the field type list for this object. More... | |
overrideFieldType ($field, $type) | |
Override the type for the specified field. More... | |
getFieldList ($alias="") | |
Returned a comma-separated list of the fields for this object (applying the assigned filter if there is one). More... | |
getFieldArray () | |
Return an array of field names for this object filtered by any active filter. More... | |
hasField ($field) | |
Returns true if this DataItem contains a field with the specified name and that field is not excluded by a filter. More... | |
hasRelation ($relation) | |
Returns true if this DataItem contains a relation with the specified name. More... | |
getPrimaryKey () | |
Retrieves the primary key field name. More... | |
getPrimaryKeyList () | |
Retrieves a list of all the primary keys used for an object as an array. More... | |
get ($field) | |
Retrieve the value for the specified field. More... | |
set ($field, $value) | |
Set the value of the specified field. More... | |
getType ($field) | |
Retrieves the data type of the specified field. More... | |
getFilter () | |
Returns the filter set on this object. More... | |
setFilter ($filter) | |
Sets the filter on this object. More... | |
getFieldAliases () | |
Retrieve the list of field aliases. More... | |
getFieldAnnotations () | |
Retrieve the list of field annotations. More... | |
pack () | |
The pack() method is called prior to persisting a DataItem to storage. More... | |
unpack () | |
The unpack() method is called after populating a DataItem. More... | |
load ($id) | |
Load the object with the specified primary key. More... | |
old () | |
Retrieves the currently stored state of the DataItem from the database and returns it as a new object. More... | |
loadComposite () | |
Creates an outer CompositeDataItem from its base component. More... | |
save () | |
Store the object in the database. More... | |
select () | |
Select the object from the database, based on the value of the primary key field. More... | |
exists ($constraint="") | |
Check whether the object exists in the database. More... | |
update () | |
Update the row in the database that corresponds to this object. More... | |
updateExplicit ($updates, $params=null) | |
Executes an explicit update command against the database. More... | |
insert () | |
Insert a new row in the database to store this object. More... | |
delete ($constraint="") | |
Delete the row in the database that corresponds to this object. More... | |
deleteAll () | |
Delete all the rows in the database that correspond to this class. More... | |
tableExists () | |
Check if the table for this class exists in the database. More... | |
duplicate () | |
Persists a duplicate of the DataItem to the database under a new primary key. More... | |
distinctValues ($field, $sorted=false, $constraint="") | |
Retrieves the distinct values in the database for the specified field across the specified set of records. More... | |
fromGET () | |
Automatically populate the object based on parameters in the $_GET collection. More... | |
fromPOST () | |
Automatically populate the object based on parameters in the $_POST collection. More... | |
fromREQUEST () | |
Automatically populate the object based on parameters in either the $_GET or $_POST collection, depending on the method used to access the page. More... | |
fromDataSet ($params) | |
Automatically populate the object based on a custom set of parameters (such as a filtered $_POST collection) More... | |
compare ($to) | |
Compare this object to another object. More... | |
copy ($from) | |
Copies values from another object, field by field. More... | |
cloneFrom ($from) | |
Copies values from another object, field by field, excluding the primary key. More... | |
cacheLookup ($id) | |
Populate the object from the local cache if the object is marked as "cacheLocal". More... | |
getRelated ($class, $field="") | |
Returns a single item related by the specified foreign key. More... | |
getRelatedList ($class, $field="", $orderBy="") | |
Returns a list of items that are related to this item. More... | |
crossReference ($class, $xref, $orderBy="", $pkField="", $xrefField="") | |
Returns a list of items related to this item via a cross-reference table. More... | |
queryValue ($func) | |
Query the database to calculate an aggregate value. More... | |
toXML ($indent=0, $path=null) | |
Generates an XML representation of the object. More... | |
fromXML ($node) | |
Populates the object from the specified XML node. More... | |
toJSON () | |
format ($template="", $separator=", ") | |
Substitute values for field names in a string, with the fields formatted using their type's default format or according to the formatting template sting passed in. More... | |
formatField ($template) | |
formatThroughRelation ($template, $separator=", ") | |
prettifyFieldName ($field) | |
relateTo ($target, $field="") | |
Link this object to the specified target by setting corresponding field to the value of the target's primary key. More... | |
Public Member Functions inherited from AbstractDataItem | |
decorate ($name, $value) | |
Adds a decoration to the DataItem. More... | |
getDecoration ($name) | |
Retrieve the value of a decoration on the current DataItem. More... | |
setOption ($opt) | |
Set a behavior option flag. More... | |
clearOptions ($opt) | |
Clear the specified behavior option flag. More... | |
getConnection () | |
Retrieves a connection to the database. More... | |
getIdentityConstraint () | |
Subclasses can override this function to provide additional identity constraints to be used when querying or updating. More... | |
populate ($line) | |
Populates the object using the supplied associative array (field -> value). More... | |
getPrimaryKeyValue () | |
Retrieves the primary key value. More... | |
quoteFieldValue ($field, $type=null) | |
Returns the properly quoted value of the specified field. More... | |
quoteValue ($val, $type) | |
formatFieldValue ($field, $template="") | |
formatFieldForXML ($field) | |
Format field for XML output. More... | |
reformatToSQLDate ($date) | |
Reformats the specified date to be in a format used by the database. More... | |
reformatFromSQLDate ($date) | |
fromJSON ($json) | |
Populate from the supplied JSON object. More... | |
prettifyClassName ($plural=false) | |
Static Public Member Functions | |
static | registerEventHandler ($class, $event, $handler) |
Register an event handler for a specific event and DataItem class. More... | |
Public Attributes | |
$_tx = null | |
$_pkDisabled = false | |
Public Attributes inherited from AbstractDataItem | |
$filter | |
$_options = 0 | |
$_tx = null | |
Tracks the current database transaction for each DataItem. More... | |
$_decorations = null | |
Static Public Attributes | |
static | $_eventMap = array() |
static | $dataTypeRendererMap |
DataItem is the generic base class for database mapped classes.
It provides a compact, consistent API for object persistence in the database.
Definition at line 61 of file data_item.inc.
DataItem::__sleep | ( | ) |
Definition at line 133 of file data_item.inc.
DataItem::cacheLookup | ( | $id | ) |
Populate the object from the local cache if the object is marked as "cacheLocal".
Reimplemented from AbstractDataItem.
Definition at line 1179 of file data_item.inc.
DataItem::cast | ( | $class | ) |
Cast this object to another class.
For simple DataItems this checks that the class is the same as the supplied class and returns a reference if so. If not an exception is thrown.
string | $class |
DataItemException |
Reimplemented from AbstractDataItem.
Definition at line 219 of file data_item.inc.
DataItem::cloneFrom | ( | $from | ) |
Copies values from another object, field by field, excluding the primary key.
This works the same as DataItem::copy(), but should be used in preference when you are wanting to create a duplicate row in the database.
object | from the object from which data is to be copied |
Definition at line 1172 of file data_item.inc.
DataItem::compare | ( | $to | ) |
Compare this object to another object.
If all the fields match, the method returns true, otherwise false. If a filter is in place on the source object, then only the filtered fields are compared.
object | $to | the object with which to compare this object |
Reimplemented from AbstractDataItem.
Definition at line 1127 of file data_item.inc.
DataItem::copy | ( | $from | ) |
Copies values from another object, field by field.
If a filter is in place on the source object, then only the filtered fields are copied.
object | from the object from which data is to be copied |
Reimplemented from AbstractDataItem.
Definition at line 1148 of file data_item.inc.
DataItem::crossReference | ( | $class, | |
$xref, | |||
$orderBy = "" , |
|||
$pkField = "" , |
|||
$xrefField = "" |
|||
) |
Returns a list of items related to this item via a cross-reference table.
The cross-reference table must contain the primary keys of each of the related classes as fields.
string | $class | the name of the related class |
string | $xref | the name of the cross-reference table |
string | $orderBy | (optional) a sort order clause for the results. |
string | $pkField | (optional) the field in the cross-reference table that maps to the primary key of the source object. |
string | xrefField (optional) the field in the cross-refence table that maps to the primary key of the cross-referenced objects. |
Definition at line 1286 of file data_item.inc.
DataItem::DataItem | ( | ) |
Constructor.
DataItems can be constructed in three ways:
Definition at line 97 of file data_item.inc.
DataItem::delete | ( | $constraint = "" | ) |
Delete the row in the database that corresponds to this object.
Reimplemented from AbstractDataItem.
Definition at line 888 of file data_item.inc.
DataItem::deleteAll | ( | ) |
Delete all the rows in the database that correspond to this class.
Reimplemented from AbstractDataItem.
Definition at line 920 of file data_item.inc.
DataItem::disablePrimaryKey | ( | ) |
Definition at line 229 of file data_item.inc.
DataItem::distinctValues | ( | $field, | |
$sorted = false , |
|||
$constraint = "" |
|||
) |
Retrieves the distinct values in the database for the specified field across the specified set of records.
string | $field | |
boolean | $sorted | |
string | $constraint |
Reimplemented from AbstractDataItem.
Definition at line 1001 of file data_item.inc.
DataItem::duplicate | ( | ) |
Persists a duplicate of the DataItem to the database under a new primary key.
Foreign keys are not updated. Use this as a way to create a quick copy of an existing object, or to import a serialized object into the data store under a new primary key. For utility, the previous value of the primary key is returned.
Definition at line 983 of file data_item.inc.
DataItem::enablePrimaryKey | ( | ) |
Definition at line 239 of file data_item.inc.
DataItem::exists | ( | $constraint = "" | ) |
Check whether the object exists in the database.
Reimplemented from AbstractDataItem.
Definition at line 665 of file data_item.inc.
DataItem::fireEvent | ( | $event | ) |
Fires the specified event to all registered handlers.
The firing object is passed as a parameter to all the registered handlers.
string | $event | the event to be fired |
Definition at line 169 of file data_item.inc.
DataItem::format | ( | $template = "" , |
|
$separator = ", " |
|||
) |
Substitute values for field names in a string, with the fields formatted using their type's default format or according to the formatting template sting passed in.
example template string: "{program_name} {start_date} {number_students}"
In the above example "N/A" would be output if the name field is empty or null. This will also work with numeric fields with a value of 0 and booleans with false. Very useful for places where you are linking to a form by name or title.
Fields can also be retrieved through a relation from the dataitem obj that calls this format function.
Syntax: {method()} Example: {getFullName()}
This format calls the specified method on the object and substitutes the returned value into the output. Parameters cannot be passed.
for example: "{MyRelation.event_name}"
Variables used: $format - stores the pattern inside the braces {} for search & replace substitution in the template string.
$fieldFormat - the requested formatting for the field, if any.
$sub - the value to be substituted or replacement value in the tempalte string.
Reimplemented from AbstractDataItem.
Definition at line 1582 of file data_item.inc.
DataItem::formatField | ( | $template | ) |
Definition at line 1643 of file data_item.inc.
DataItem::formatThroughRelation | ( | $template, | |
$separator = ", " |
|||
) |
Definition at line 1713 of file data_item.inc.
DataItem::fromDataSet | ( | $params | ) |
Automatically populate the object based on a custom set of parameters (such as a filtered $_POST collection)
Definition at line 1102 of file data_item.inc.
DataItem::fromGET | ( | ) |
Automatically populate the object based on parameters in the $_GET collection.
Reimplemented from AbstractDataItem.
Definition at line 1042 of file data_item.inc.
DataItem::fromPOST | ( | ) |
Automatically populate the object based on parameters in the $_POST collection.
If the key does not exist in $_POST and the type is Boolean, that means that the user unchecked a checkbox and we need to assign 0 to the field.
Reimplemented from AbstractDataItem.
Definition at line 1062 of file data_item.inc.
DataItem::fromREQUEST | ( | ) |
Automatically populate the object based on parameters in either the $_GET or $_POST collection, depending on the method used to access the page.
Reimplemented from AbstractDataItem.
Definition at line 1084 of file data_item.inc.
DataItem::fromXML | ( | $node | ) |
Populates the object from the specified XML node.
DOMNode | $node |
Reimplemented from AbstractDataItem.
Definition at line 1485 of file data_item.inc.
DataItem::get | ( | $field | ) |
Retrieve the value for the specified field.
string | $field | the field to retrieve |
Reimplemented from AbstractDataItem.
Definition at line 474 of file data_item.inc.
DataItem::getFieldAliases | ( | ) |
Retrieve the list of field aliases.
Reimplemented from AbstractDataItem.
Definition at line 523 of file data_item.inc.
DataItem::getFieldAnnotations | ( | ) |
Retrieve the list of field annotations.
Reimplemented from AbstractDataItem.
Definition at line 532 of file data_item.inc.
DataItem::getFieldArray | ( | ) |
Return an array of field names for this object filtered by any active filter.
Reimplemented from AbstractDataItem.
Definition at line 415 of file data_item.inc.
DataItem::getFieldList | ( | $alias = "" | ) |
Returned a comma-separated list of the fields for this object (applying the assigned filter if there is one).
Reimplemented from AbstractDataItem.
Definition at line 361 of file data_item.inc.
DataItem::getFields | ( | ) |
Retrieve the field type list for this object.
Reimplemented from AbstractDataItem.
Definition at line 333 of file data_item.inc.
DataItem::getFilter | ( | ) |
Returns the filter set on this object.
Reimplemented from AbstractDataItem.
Definition at line 505 of file data_item.inc.
DataItem::getHiddenFields | ( | ) |
Retrieves the list of hidden fields.
These will be automatically hidden in any AutoForm.
Reimplemented from AbstractDataItem.
Definition at line 249 of file data_item.inc.
DataItem::getPrimaryKey | ( | ) |
Retrieves the primary key field name.
Reimplemented from AbstractDataItem.
Definition at line 455 of file data_item.inc.
DataItem::getPrimaryKeyList | ( | ) |
Retrieves a list of all the primary keys used for an object as an array.
Reimplemented from AbstractDataItem.
Definition at line 464 of file data_item.inc.
DataItem::getRelated | ( | $class, | |
$field = "" |
|||
) |
Returns a single item related by the specified foreign key.
The foreign key name must match the primary key name for the specified class.
Use this method to implement one-to-one relations.
string | $class | the name of the related class |
string | $field | the name of the foreign key defining the relation. |
Definition at line 1210 of file data_item.inc.
DataItem::getRelatedList | ( | $class, | |
$field = "" , |
|||
$orderBy = "" |
|||
) |
Returns a list of items that are related to this item.
Usually the items will be related by having a foreign key field that matches the primary key on the calling object. However, another field on the calling object can be specified if required. You can also optionally specify a sort order for the results.
Use this field to implement one-to-many relationships.
string | $class | the name of the related class |
string | $field | (optional) the name of the field defining the relation |
string | $orderBy | (optional) a sort order clause for the results |
Definition at line 1260 of file data_item.inc.
DataItem::getTransaction | ( | ) |
Retrieves the current DataTransaction.
Reimplemented from AbstractDataItem.
Definition at line 206 of file data_item.inc.
DataItem::getType | ( | $field | ) |
Retrieves the data type of the specified field.
$field | the field in question |
Reimplemented from AbstractDataItem.
Definition at line 496 of file data_item.inc.
DataItem::hasField | ( | $field | ) |
Returns true if this DataItem contains a field with the specified name and that field is not excluded by a filter.
string | $field |
Reimplemented from AbstractDataItem.
Definition at line 434 of file data_item.inc.
DataItem::hasRelation | ( | $relation | ) |
Returns true if this DataItem contains a relation with the specified name.
string | $relation |
Reimplemented from AbstractDataItem.
Definition at line 447 of file data_item.inc.
DataItem::insert | ( | ) |
Insert a new row in the database to store this object.
Reimplemented from AbstractDataItem.
Definition at line 812 of file data_item.inc.
DataItem::joinTransaction | ( | $tx | ) |
Join the DataItem to the specified DataTransaction.
DataTransaction | $tx | the transaction to join |
Reimplemented from AbstractDataItem.
Definition at line 198 of file data_item.inc.
DataItem::load | ( | $id | ) |
Load the object with the specified primary key.
int | id the primary key value to instantiate from |
Reimplemented from AbstractDataItem.
Definition at line 561 of file data_item.inc.
DataItem::loadComposite | ( | ) |
Creates an outer CompositeDataItem from its base component.
In order for this method to succeed, the base component table must have a 'composite_class' field that is populated with the class name of the correct CompositeDataItem class.
Definition at line 620 of file data_item.inc.
DataItem::old | ( | ) |
Retrieves the currently stored state of the DataItem from the database and returns it as a new object.
This can be used for comparisons when updating a DataItem, for instance to trigger related updates when a field value is changed.
Definition at line 601 of file data_item.inc.
DataItem::overrideFieldType | ( | $field, | |
$type | |||
) |
Override the type for the specified field.
string | $field | |
string | $type |
Definition at line 347 of file data_item.inc.
DataItem::pack | ( | ) |
The pack() method is called prior to persisting a DataItem to storage.
It can be used to perform a preprocessing step prior to storage, such as formatting sub-objects into a JSON, XML or other serialized format and storing them in a field.
Definition at line 543 of file data_item.inc.
DataItem::populate | ( | $line, | |
$alias = false |
|||
) |
Populates the object using the supplied associative array (field -> value).
Only values that match the definition of the sub-classed object will be copied. Fields that have been excluded by the use of an InclusionFilter or ExclusionFilter will also not be populated.
array | $line | the array of values to populate the object with. |
Definition at line 262 of file data_item.inc.
DataItem::prettifyFieldName | ( | $field | ) |
DataItem::queryValue | ( | $func | ) |
Query the database to calculate an aggregate value.
The database table associated with the instatiated object is used as the source for the data.
string | $func | the value or function to retrieve |
string | $constraints | optional constraint clause to apply to the query |
Definition at line 1346 of file data_item.inc.
|
static |
Register an event handler for a specific event and DataItem class.
DataItem events are fired by DataItems at various points in the data lifecycle (such as inserting, updating, deleting, etc.)
string | $class | the DataItem class to which the event handler is to be attached |
string | $event | the name of the event |
callable | $handler | the event handler (a callable function) |
Definition at line 151 of file data_item.inc.
DataItem::relateTo | ( | $target, | |
$field = "" |
|||
) |
Link this object to the specified target by setting corresponding field to the value of the target's primary key.
DataItem | $target | the DataItem to which the relationship will be created |
string | $field | the field to set for the relationship. If not specified, the primary key of the target object is used for the foreign key field name. |
Reimplemented from AbstractDataItem.
Definition at line 1791 of file data_item.inc.
DataItem::save | ( | ) |
Store the object in the database.
Reimplemented from AbstractDataItem.
Definition at line 636 of file data_item.inc.
DataItem::select | ( | ) |
Select the object from the database, based on the value of the primary key field.
Reimplemented from AbstractDataItem.
Definition at line 656 of file data_item.inc.
DataItem::set | ( | $field, | |
$value | |||
) |
Set the value of the specified field.
$field | the field to set |
$value | the value to which the field is to be set |
Reimplemented from AbstractDataItem.
Definition at line 485 of file data_item.inc.
DataItem::setFilter | ( | $filter | ) |
Sets the filter on this object.
$filter | the filter |
Reimplemented from AbstractDataItem.
Definition at line 514 of file data_item.inc.
DataItem::tableExists | ( | ) |
Check if the table for this class exists in the database.
Definition at line 944 of file data_item.inc.
DataItem::toJSON | ( | ) |
Definition at line 1502 of file data_item.inc.
DataItem::toXML | ( | $indent = 0 , |
|
$path = null |
|||
) |
Generates an XML representation of the object.
Filters are honored when determining which fields are included in the XML. Empty fields are not output (note that a string field with value "" is not considered empty).
Reimplemented from AbstractDataItem.
Definition at line 1396 of file data_item.inc.
DataItem::unpack | ( | ) |
The unpack() method is called after populating a DataItem.
It can be used to unpack serialized sub-object representations so they are can be used directly by your application.
Definition at line 552 of file data_item.inc.
DataItem::update | ( | ) |
Update the row in the database that corresponds to this object.
Reimplemented from AbstractDataItem.
Definition at line 707 of file data_item.inc.
DataItem::updateExplicit | ( | $updates, | |
$params = null |
|||
) |
Executes an explicit update command against the database.
This enables you to perform updates on the object using database functions, allowing for atomic operations, etc. For example, you might make such a call as $obj->updateExplicit("SET count=count+1"); The object is refreshed from the database automatically after the update.
string | $updates | the update command to be run |
array | $params | optional array for bound parameters |
Definition at line 775 of file data_item.inc.
|
static |
Definition at line 63 of file data_item.inc.
DataItem::$_pkDisabled = false |
Definition at line 66 of file data_item.inc.
DataItem::$_tx = null |
Definition at line 65 of file data_item.inc.
|
static |
Definition at line 70 of file data_item.inc.