Item methods
__construct( setup )
setupAn optional hash array with the following possible setup keys:loadMethodIf specified, it loads the Item from the database using the given method, from one of the following available loading methods:fromDatabaseRowLoads the item from the given DatabaseRow object data passed in thedatabaseRowsetup key.fromIdLoads the item identified by the id given in theidsetup key.fromDataLoads the item using the data passed in thedatasetup key.
databaseRowThe DatabaseRow object to load the Item from when thefromDatabaseRowloadMethodis specified.idThe id on the database of the item to load, when thefromIdloadMethodis specified.dataA hash array containing the data of the item to load, when thefromDataloadMethodis specified, where each key is the field name, and its value the field value.
Throws: An Exception if the item could not be constructed or loaded.
__get( key )
Magic method to return the Item's data corresponding to the given key
keyThe key of the data to get, matches the database field name.
Returns: The data, or null if key didn't exist.
__isset( key )
Magic method to check whether the given key exists in the item.
keyThe key of the data to check, matches the database field name.
Returns: true if the key exists, false if not.
__set( key )
Magic method to set the item data with the given key to the given value
keyThe key of the data to set, matches the database field name.valueThe value
clearCache( fieldNames )
Removes this Item from the cache. Can be overloaded if more additional things have to be cleared from cache in relation to the Item.
fieldNamesAn optional array of field names that have been used to query items by index, so those queries will be cleared from cache.idFieldNameand other field names commonly used by this object are automatically added to this array and cleared from cache.
Returns: true on success, false on failure.
delete
Deletes this item from the database.
Returns: true on success, false on failure.
loadFromData( data )
Loads the item with the given data.
dataA hash array containing the data of the item, where each key is the field name as defined in the Item::$fields property, and each value is the field value.
Returns: true on success, false on failure.
loadFromDatabaseRow( databaseRow )
Loads the item from the given DatabaseRow.
databaseRowA DatabaseRow object containing the data of the item.
Returns: true on success, false on failure.
loadFromId( id, fieldName, method )
Loads the item identified by the given id from the database.
idThe idfieldNameThe name of the field containing the id, as defined in the Item::$fields property. Should be a field that uniquely identifies a row on the database.methodThe loading method to use. If not specified, it uses the default Item::$loadFromIdMethod. One of the following values:queryDatabaseCacheLoad the item from the database using cache.queryDatabaseLoad the item from the database without using cache.
Returns: true if the item was found and loaded successfully, false otherwise.
loadInline( data )
Loads the item when no loadMethod has been provided on construction. Intended to be overloaded when needed.
dataA hash array with the data. Default:false
Returns: true on success, false on error.
update( data )
Updates the data on the database for this Item with the passed data, or with the data stored on the object if no data is passed.
dataAn optional hash array where each key is the field name to update, and each value the new data to store on that field for this item. If not passed or left to false, the current data stored in the object is used. Default:falseFor multilanguage fields, a hash array must be passed as the value, where each key is one of the available
LANGUAGE_?constants and the value is the value in that language. If a non-array value is passed the currently detected language will be used.
Returns: true on success, false on failure.
Last updated
Was this helpful?