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.

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.

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

    • 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

Returns: true on success, false on failure.

Last updated

Was this helpful?