Item methods

__construct( setup )

  • setup An optional hash array with the following possible setup keys:

    • loadMethod If specified, it loads the Item from the database using the given method, from one of the following available loading methods:

      • fromDatabaseRow Loads the item from the given DatabaseRow object data passed in the databaseRow setup key.

      • fromId Loads the item identified by the id given in the id setup key.

      • fromData Loads the item using the data passed in the data setup key.

    • databaseRow The DatabaseRow object to load the Item from when the fromDatabaseRow loadMethod is specified.

    • id The id on the database of the item to load, when the fromId loadMethod is specified.

    • data A hash array containing the data of the item to load, when the fromData loadMethod is 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

  • key The 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.

  • key The 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

  • key The key of the data to set, matches the database field name.

  • value The 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.

  • fieldNames An optional array of field names that have been used to query items by index, so those queries will be cleared from cache. idFieldName and 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.

  • data A 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.

  • databaseRow A 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.

  • id The id

  • fieldName The 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.

  • method The loading method to use. If not specified, it uses the default Item::$loadFromIdMethod. One of the following values:

    • queryDatabaseCache Load the item from the database using cache.

    • queryDatabase Load 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.

  • data A 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.

  • data An 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: false

    • For 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