\Horde_Rdo_Base

Horde_Rdo_Base abstract class (Rampage Data Objects). Entity classes extend this baseline.

Summary

Methods
Properties
Constants
__construct()
__clone()
__get()
offsetGet()
__set()
offsetSet()
__isset()
offsetExists()
__unset()
offsetUnset()
setFields()
getIterator()
getMapper()
setMapper()
addRelation()
hasRelation()
removeRelation()
save()
delete()
toArray()
No public properties found
No constants found
_fillPlaceholders()
$_mapper
$_fields
N/A
No private methods found
No private properties found
N/A

Properties

$_mapper

$_mapper : \Horde_Rdo_Mapper

The Horde_Rdo_Mapper instance associated with this Rdo object. The Mapper takes care of all backend access.

Type

\Horde_Rdo_Mapper

$_fields

$_fields : array

This object's fields.

Type

array

Methods

__construct()

__construct(array  $fields = array()) 

Constructor. Can be called directly by a programmer, or is called in Horde_Rdo_Mapper::map(). Takes an associative array of initial object values.

Parameters

array $fields

Initial values for the new object.

__clone()

__clone() 

When Rdo objects are cloned, unset the unique id that identifies them so that they can be modified and saved to the backend as new objects. If you don't really want a new object, don't clone.

__get()

__get(string  $field) : mixed

Fetch fields that haven't yet been loaded. Lazy-loaded fields and lazy-loaded relationships are handled this way. Once a field is retrieved, it is cached in the $_fields array so it doesn't need to be fetched again.

Parameters

string $field

The name of the field to access.

Returns

mixed —

The value of $field or null.

offsetGet()

offsetGet(  $field) 

Implements getter for ArrayAccess interface.

Parameters

$field

__set()

__set(string  $field, mixed  $value) 

Set a field's value.

Parameters

string $field

The field to set

mixed $value

The field's new value

offsetSet()

offsetSet(  $field,   $value) 

Implements setter for ArrayAccess interface.

Parameters

$field
$value

__isset()

__isset(string  $field) 

Allow using isset($rdo->foo) to check for field or relationship presence.

Parameters

string $field

The field name to check existence of.

offsetExists()

offsetExists(  $field) 

Implements isset() for ArrayAccess interface.

Parameters

$field

__unset()

__unset(string  $field) 

Allow using unset($rdo->foo) to unset a basic field. Relationships cannot be unset in this way.

Parameters

string $field

The field name to unset.

offsetUnset()

offsetUnset(  $field) 

Implements unset() for ArrayAccess interface.

Parameters

$field

setFields()

setFields(array  $fields = array()) 

Set field values for the object

Parameters

array $fields

Initial values for the new object.

getIterator()

getIterator() : \Horde_Rdo_Iterator

Implement the IteratorAggregate interface. Looping over an Rdo object goes through each property of the object in turn.

Returns

\Horde_Rdo_Iterator

The Iterator instance.

getMapper()

getMapper() : \Horde_Rdo_Mapper

Get a Mapper instance that can be used to manage this object. The Mapper instance can come from a few places:

  • If the class Mapper exists, it will be used automatically.

  • Any Rdo instance created with Horde_Rdo_Mapper::map() will have a $mapper object set automatically.

  • Subclasses can override getMapper() to return the correct mapper object.

  • The programmer can call $rdoObject->setMapper($mapper) to provide a mapper object.

A Horde_Rdo_Exception will be thrown if none of these conditions are met.

Returns

\Horde_Rdo_Mapper

The Mapper instance managing this object.

setMapper()

setMapper(\Horde_Rdo_Mapper  $mapper) 

Associate this Rdo object with the Mapper instance that will manage it. Called automatically by Horde_Rdo_Mapper:map().

Parameters

\Horde_Rdo_Mapper $mapper

The Mapper to manage this Rdo object.

addRelation()

addRelation(string  $relationship, \Horde_Rdo_Base  $peer) 

Adds a relation to one of the relationships defined in the mapper.

  • For one-to-one relations, simply updates the relation field.
  • For one-to-many relations, updates the related object's relation field.
  • For many-to-many relations, adds an entry in the "through" table.
  • Performs a no-op if the peer is already related.

This is a proxy to the mapper's addRelation() method.

Parameters

string $relationship

The relationship key in the mapper.

\Horde_Rdo_Base $peer

The object to add the relation.

Throws

\Horde_Rdo_Exception

hasRelation()

hasRelation(string  $relationship, \Horde_Rdo_Base  $peer = null) : boolean

Checks whether a relation to a peer is defined through one of the relationships in the mapper.

Parameters

string $relationship

The relationship key in the mapper.

\Horde_Rdo_Base $peer

The object to check for the relation. If this is null, check if there is any peer for this relation.

Throws

\Horde_Rdo_Exception

Returns

boolean —

True if related.

removeRelation()

removeRelation(string  $relationship, \Horde_Rdo_Base  $peer = null) : integer

Removes a relation to one of the relationships defined in the mapper.

  • For one-to-one and one-to-many relations, simply sets the relation field to 0.
  • For many-to-many, either deletes all relations to this object or just the relation to a given peer object.
  • Performs a no-op if the peer is already unrelated.

This is a proxy to the mapper's removeRelation method.

Parameters

string $relationship

The relationship key in the mapper

\Horde_Rdo_Base $peer

The object to remove from the relation

Throws

\Horde_Rdo_Exception

Returns

integer —

The number of relations affected

save()

save() : boolean

Save any changes to the backend.

Returns

boolean —

Success.

delete()

delete() : boolean

Delete this object from the backend.

Returns

boolean —

Success or failure.

toArray()

toArray(boolean  $lazy = false, boolean  $relationships = false) : array

Converts the entity to an Array.

This method can be used when handing it over to Horde_Variables so that the database is not unnecessarily queried because of lazyFields/lazyRelationships.

Parameters

boolean $lazy

Whether lazy elements should be added.

boolean $relationships

Whether relationships should be added.

Returns

array —

All selected fields and relationships.

_fillPlaceholders()

_fillPlaceholders(array  $query) : array

Take a query array and replace @field@ placeholders with values from this object.

Parameters

array $query

The query to process placeholders on.

Returns

array —

The query with placeholders filled in.