Omeka_Record_AbstractRecord

class Omeka_Record_AbstractRecord

Package: Record

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

property id

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 _errors

Any errors raised during the validation process.

property _cache

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

property _mixins

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 _db

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 _postData

Storage for the POST data when handling a form.

property _locked

Whether or not the record is locked. Locked records cannot be saved.

property _eventCallbacks

List of built in callback methods.

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

Subclass constructor behavior.

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

Returns:void
__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.

__get(string $prop)

Retrieve database records that are associated with the current one.

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

mixed

__call(string $m, array $a)

Delegate unknown method calls to Omeka_Record_Mixin_AbstractMixin instances.

Parameters:
  • $m (string) – Method name.
  • $a (array) – Method arguments.
Returns:

mixed

_initializeMixins()

Initialize the mixins for a record.

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

delegateToMixins(string $method, array $args = Array, boolean $all =)

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

Parameters:
  • $method (string) –
  • $args (array) –
  • $all (boolean) – (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.

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 (unknown) –
  • $args (unknown) –
_addToCache(mixed $value, string $key)

Add a value to the record-specific cache.

Parameters:
  • $value (mixed) –
  • $key (string) –
Returns:

void

_getCached(string $name)

Get a value from the record-specific cache.

Parameters:
  • $name (string) –
Returns:

mixed

getProperty(string $property)

Get a property about the record for display purposes.

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

mixed

exists()

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

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

Returns:boolean
_validate()

Template method for defining record validation rules.

Should be overridden by subclasses.

Returns:void
isValid()

Determine whether or not the record is valid.

Returns:boolean
getErrors()

Retrieve validation errors associated with this record.

Returns:Omeka_Validate_Errors
hasErrors()

Determine whether or not this record has any validation errors.

Returns:boolean
addError(string|null $field, string $msg)

Add a validation error for a specific field.

Currently limited to a single error per field, so multiple error messagesmust 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.
Returns:

void

addErrorsFrom(Omeka_Record_AbstractRecord $record)

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

Parameters:
Returns:

void

lock()

Prevent a record from being modified.

Can be used to prevent accidentally saving/deleting a record if its state maychange but saving would be undesirable, such as modifying a record fordisplay purposes.

Returns:void
getTable($class)

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

Parameters:
  • $class (unknown) –
Returns:

Omeka_Db_Table

getDb()

Retrieve the Omeka_Db instance associated with this record.

Returns:Omeka_Db
toArray()

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

Returns:array
save(boolean $throwIfInvalid = 1)

Save the record.

Parameters:
  • $throwIfInvalid (boolean) –
Returns:

boolean Whether the save was successful.

__clone()

Clone the record.

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

delete()

Delete the record.

Returns:void
_delete()

Template method for defining record deletion logic.

Subclasses can override this method to define additional logic for deletingrecords. Note that this is different from both the beforeDelete() andafterDelete() hooks in that it executes after beforeDelete(), but beforethe record is actually deleted.

Common use cases include emulating cascading deletes with otherdatabase rows.

Returns:void
beforeSave($args)

Executes before the record is saved.

Parameters:
  • $args (unknown) –
afterSave($args)

Executes after the record is inserted.

Parameters:
  • $args (unknown) –
beforeDelete()

Executes before the record is deleted.

afterDelete()

Executes after the record is deleted.

setArray(array|Traversable $data)

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

Parameters:
  • $data (array|Traversable) –
Returns:

void

getPluginBroker()
setPluginBroker($broker)
Parameters:
  • $broker (unknown) –
offsetExists(string $name)

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

Required by ArrayAccess.

Parameters:
  • $name (string) –
Returns:

boolean

offsetUnset(string $name)

Unset the given field.

Required by ArrayAccess.

Parameters:
  • $name (string) –
Returns:

void

offsetGet(string $name)

Retrieve the value of a given field.

Required by ArrayAccess.

Parameters:
  • $name (string) –
Returns:

mixed

offsetSet(string $name, mixed $value)

Set the value of a given field.

Required by ArrayAccess.

Parameters:
  • $name (string) –
  • $value (mixed) –
Returns:

void

filterPostData(array $post)

Filter the form input according to some criteria.

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

Parameters:
  • $post (array) –
Returns:

array Filtered post data.

setPostData(array $post)

Set the POST data to the record.

Parameters:
  • $post (array) –
fieldIsUnique(string $field, mixed $value)

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:

boolean

getRecordUrl(string $action = show)

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

The record_url() global uses this method to get routing parameters fornon-standard records, e.g. records defined by plugins. Subclasses shouldoverride this method if the default route (as defined below) isincorrect.

Parameters:
  • $action (string) –
Returns:

string|array A URL string or a routing array.