Omeka_Record_AbstractRecord

Package: Record

class Omeka_Record_AbstractRecord

implements ArrayAccess

A base class for domain objects, inspired by, though not strictly adherent to, the ActiveRecord pattern.

property Omeka_Record_AbstractRecord::$id

int

Unique ID for the record.

All implementations of Omeka_Record_AbstractRecord must have a table containing an ‘id’ column, preferably as the primary key.

property Omeka_Record_AbstractRecord::$_cache

protected array

An in-memory cache for related objects that have been retrieved via the magic __get() syntax.

property Omeka_Record_AbstractRecord::$_mixins

protected array

Set of Omeka_Record_Mixin_AbstractMixin objects that are designed to extend the behavior of Omeka_Record_AbstractRecord implementations.

Examples include {@link Taggable}, {@link Relatable}, {@link ActsAsElementText}, etc.

property Omeka_Record_AbstractRecord::$_db

protected Omeka_Db

protected array

Key/value pairs indicating aliases for methods that retrieve related data objects. For example, a subclass might define the following: <code> protected $_related = array(‘Sections’=>’loadSections’); </code> This would allow the client to write code like: <code> $sections = $subclassInstance->Sections; </code> Which would be equivalent to: <code> $sections = $subclassInstance->loadSections(); </code> The difference being, the former is cached so as to avoid multiple trips to the database.

property Omeka_Record_AbstractRecord::$_postData

protected ArrayObject

Storage for the POST data when handling a form.

Omeka_Record_AbstractRecord::__construct($db = null)
Parameters:
  • $db (Omeka_Db|null) – (optional) Defaults to the Omeka_Db instance from the bootstrap.

Omeka_Record_AbstractRecord::construct()

Subclass constructor behavior.

Subclasses of Omeka_Record_AbstractRecord can override this function to add behavior to the constructor without overriding __construct.

Omeka_Record_AbstractRecord::__destruct()

Unsets mixins, which contain circular references, upon record destruction

IMPORTANT: Solves a memory leak when retrieving/saving records.

Required because PHP 5.2 does not do garbage collection on circular references.

Omeka_Record_AbstractRecord::__get($prop)

Retrieve database records that are associated with the current one.

Parameters:
  • $prop (string) – Related data to retrieve.

Returns:

mixed

Omeka_Record_AbstractRecord::__call($m, $a)

Delegate unknown method calls to Omeka_Record_Mixin_AbstractMixin instances.

Parameters:
  • $m (string) – Method name.

  • $a (array) – Method arguments.

Returns:

mixed

Omeka_Record_AbstractRecord::_initializeMixins()

Initialize the mixins for a record.

Any Omeka_Record_AbstractRecord subclass that uses mixins should initialize them here, since this is called on construction and when mixins need to be reinitialized.

Omeka_Record_AbstractRecord::delegateToMixins($method, $args = array(), $all = false)

Delegate to the given method in one or more mixin instances.

Parameters:
  • $method (string) –

  • $args (array) –

  • $all (bool) – (optional) Whether or not to call the same method on every mixin instance that has that method. Defaults to false.

Returns:

mixed If $all is false, the return value from the invoked method. Otherwise there is no return value.

Omeka_Record_AbstractRecord::runCallbacks($event, $args = array())

Invoke all callbacks associated with a specific record event.

Callbacks execute in the following order: - Omeka_Record_AbstractRecord hooks like Omeka_Record_AbstractRecord::afterDelete() - Record mixin hooks like Taggable::afterSave() - Generic record plugin hooks like ‘before_delete_record’ - Specific record plugin hooks like ‘before_delete_item’

Parameters:
  • $event

  • $args

Omeka_Record_AbstractRecord::_addToCache($value, $key)

Add a value to the record-specific cache.

Parameters:
  • $value (mixed) –

  • $key (string) –

Omeka_Record_AbstractRecord::_getCached($name)

Get a value from the record-specific cache.

Parameters:
  • $name (string) –

Returns:

mixed

Omeka_Record_AbstractRecord::getProperty($property)

Get a property about the record for display purposes.

Parameters:
  • $property (string) – Property to get. Always lowercase.

Returns:

mixed

Omeka_Record_AbstractRecord::exists()

Determine whether or not this record is persistent in the database.

For simplicity, non-persistent records are indicated by the lack of a value for the ‘id’ column.

Returns:

bool

Omeka_Record_AbstractRecord::_validate()

Template method for defining record validation rules.

Should be overridden by subclasses.

Omeka_Record_AbstractRecord::isValid()

Determine whether or not the record is valid.

Returns:

bool

Omeka_Record_AbstractRecord::getErrors()

Retrieve validation errors associated with this record.

Returns:

Omeka_Validate_Errors

Omeka_Record_AbstractRecord::hasErrors()

Determine whether or not this record has any validation errors.

Returns:

bool

Omeka_Record_AbstractRecord::addError($field, $msg)

Add a validation error for a specific field.

Currently limited to a single error per field, so multiple error messages must be concatenated together.

Parameters:
  • $field (string|null) – Name of the field. This can be null to indicate a general error not associated with a specific field.

  • $msg (string) – The error message.

Omeka_Record_AbstractRecord::addErrorsFrom(Omeka_Record_AbstractRecord $record)

Combine errors from a different Omeka_Record_AbstractRecord instance with the errors already on this record.

Parameters:
Omeka_Record_AbstractRecord::lock()

Prevent a record from being modified.

Can be used to prevent accidentally saving/deleting a record if its state may change but saving would be undesirable, such as modifying a record for display purposes.

Omeka_Record_AbstractRecord::getTable($class = null)

Retrieve the Omeka_Db_Table instance associated with this record, or with that of any given record class.

Parameters:
  • $class

Returns:

Omeka_Db_Table

Omeka_Record_AbstractRecord::getDb()

Retrieve the Omeka_Db instance associated with this record.

Returns:

Omeka_Db

Omeka_Record_AbstractRecord::toArray()

Retrieve an associative array of all the record’s columns and their values.

Returns:

array

Omeka_Record_AbstractRecord::save($throwIfInvalid = true)

Save the record.

Parameters:
  • $throwIfInvalid (bool) –

Returns:

bool Whether the save was successful.

Omeka_Record_AbstractRecord::__clone()

Clone the record.

Unsets the ID so the cloned record can be saved on its own.

Omeka_Record_AbstractRecord::delete()

Delete the record.

Omeka_Record_AbstractRecord::_delete()

Template method for defining record deletion logic.

Subclasses can override this method to define additional logic for deleting records. Note that this is different from both the beforeDelete() and afterDelete() hooks in that it executes after beforeDelete(), but before the record is actually deleted.

Common use cases include emulating cascading deletes with other database rows.

Omeka_Record_AbstractRecord::beforeSave($args)

Executes before the record is saved.

Parameters:
  • $args

Omeka_Record_AbstractRecord::afterSave($args)

Executes after the record is inserted.

Parameters:
  • $args

Omeka_Record_AbstractRecord::beforeDelete()

Executes before the record is deleted.

Omeka_Record_AbstractRecord::afterDelete()

Executes after the record is deleted.

Omeka_Record_AbstractRecord::setArray($data)

Set values for the record using an associative array or iterator.

Parameters:
  • $data (array|Traversable) –

Omeka_Record_AbstractRecord::getPluginBroker()
Omeka_Record_AbstractRecord::setPluginBroker($broker = null)
Parameters:
  • $broker

Omeka_Record_AbstractRecord::offsetExists($name)

Determine whether or not the given field has a value associated with it.

Required by ArrayAccess.

Parameters:
  • $name (string) –

Returns:

bool

Omeka_Record_AbstractRecord::offsetUnset($name)

Unset the given field.

Required by ArrayAccess.

Parameters:
  • $name (string) –

Omeka_Record_AbstractRecord::offsetGet($name)

Retrieve the value of a given field.

Required by ArrayAccess.

Parameters:
  • $name (string) –

Returns:

mixed

Omeka_Record_AbstractRecord::offsetSet($name, $value)

Set the value of a given field.

Required by ArrayAccess.

Parameters:
  • $name (string) –

  • $value (mixed) –

Omeka_Record_AbstractRecord::filterPostData($post)

Filter the form input according to some criteria.

Template method should be overridden by subclasses that wish to implement some sort of filtering criteria.

Parameters:
  • $post (array) –

Returns:

array Filtered post data.

Omeka_Record_AbstractRecord::setPostData($post)

Set the POST data to the record.

Parameters:
  • $post (array) –

Omeka_Record_AbstractRecord::fieldIsUnique($field, $value = null)

Check uniqueness of one of the record’s fields.

Parameters:
  • $field (string) –

  • $value (mixed) – Optional If null, this will check the value of the record’s $field. Otherwise check the uniqueness of this value for the given field.

Returns:

bool

Omeka_Record_AbstractRecord::getRecordUrl($action = 'show')

Get the routing parameters or the URL string to this record.

The record_url() global uses this method to get routing parameters for non-standard records, e.g. records defined by plugins. Subclasses should override this method if the default route (as defined below) is incorrect.

Parameters:
  • $action (string) –

Returns:

string|array A URL string or a routing array.

Omeka_Record_AbstractRecord::getFile()

Get a representative file for this record.

Returns:

File|null