Class AkAssociation

(line 21)

Description

AkObject
   |
   --AkObserver
      |
      --AkAssociation

Located in File: /AkActiveRecord/AkAssociation.php

Observer classes respond to life-cycle callbacks to implement trigger-like behavior outside the original class. This is a great way to reduce the clutter that normally comes when the model class is burdened with functionality that doesn't pertain to the core responsibility of the class.

Example:

class CommentObserver extends AkObserver { function afterSave($comment) { Ak::mail("admin@example.com", "New comment was posted", $comment->toString()); } }

This Observer sends an email when a Comment::save is finished.

## Observing a class that can't be inferred

Observers will by default be mapped to the class with which they share a name. So CommentObserver will be tied to observing Comment, ProductManagerObserver to ProductManager, and so on. If you want to name your observer differently than the class you're interested in observing, you can use the AkActiveRecord->observe() class method:

function afterUpdate(&$account) { $AuditTrail =& new AuditTrail($account, "UPDATED"); $AuditTrail->save(); }

If the audit observer needs to watch more than one kind of object, this can be specified with multiple arguments:

function afterUpdate(&$record) { $ObservedRecord =& new AuditTrail($record, "UPDATED"); $ObservedRecord->save(); }

The AuditObserver will now act on both updates to Account and Balance by treating them both as records.

## Available callback methods

The observer can implement callback methods for each of these methods: beforeCreate, beforeValidation, beforeValidationOnCreate, beforeSave, afterValidation, afterValidationOnCreate, afterCreate and afterSave

## Triggering Observers

In order to activate an observer, you need to call create an Observer instance and attach it to a model.

In the Akelos Framework, this can be done in controllers using the short-hand of for example:

$ComentObserverInstance =& new CommentObserver(); $Model->addObserver(&$ComentObserverInstance);



Classes extended from AkAssociation:
AkHasMany
Adds the following methods for retrieval and query of collections of associated objects.
AkHasOne
Adds the following methods for retrieval and query of a single associated object.
AkHasAndBelongsToMany
Associates two classes via an intermediate join table. Unless the join table is explicitly specified as an option, it is guessed using the lexical order of the class names. So a join between Developer and Project will give the default join table name of "developers_projects" because "D" outranks "P".
AkBelongsTo
Adds the following methods for retrieval and query for a single associated object that this object holds an id to.

Class Variables

Summary:
mixed $models
mixed $options
mixed $Owner

$models = array() (line 25)

Data type : mixed

$options = array() (line 24)

Data type : mixed

$Owner (line 23)

Data type : mixed

Class Constants

Summary:

Method Detail

Summary:
AkAssociation AkAssociation ( &$Owner)
void addAssociated ( $association_id, [ $options = array()])
void &addModel ( $association_id,  &$associated_model)
void &getModel ( $association_id)
void &getModels ()
void getOption ( $association_id,  $option_name)
void getOptions ( $association_id)
void getType ()
void initializeAssociated ( $options)
void &loadAssociated ( $association_id)
void setAssociatedId ( $association_id,  $associated_id)
void setAssociationId ( $association_id)
void setOptions ( $association_id,  $options)
void &_build ( $association_id,  &$AssociatedObject, [ $reference_associated = true])
void _findOwnerTypeForAssociation ( &$AssociatedModel,  $Owner)
void _getLoadedHandler ( $association_id)
void _hasTablePrefix ( $association_id)
void _saveLoadedHandler ( $association_id,  $associated)

Constructor AkAssociation (line 27)

AkAssociation AkAssociation( &$Owner)

Parameters

  • &$Owner:

Info

Method addAssociated (line 151)

void addAssociated( $association_id, [ $options = array()])

Overridden in child classes as:

AkHasMany::addAssociated()
AkHasOne::addAssociated()
AkHasAndBelongsToMany::addAssociated()
AkBelongsTo::addAssociated()

Class interfaces. All Association objects must implement the following methods

Parameters

  • $association_id:
  • $options:

Info

Method addModel (line 90)

void &addModel( $association_id, &$associated_model)

Parameters

  • $association_id:
  • &$associated_model:

Info

Method getAssociatedFinderSqlOptions (line 161)

void getAssociatedFinderSqlOptions( )

Overridden in child classes as:

AkHasMany::getAssociatedFinderSqlOptions()
AkHasOne::getAssociatedFinderSqlOptions()
AkHasAndBelongsToMany::getAssociatedFinderSqlOptions()
AkBelongsTo::getAssociatedFinderSqlOptions()

Info

Method getAssociatedIds (line 107)

void getAssociatedIds( )

Info

Method getModel (line 97)

void &getModel( $association_id)

Parameters

  • $association_id:

Info

Method getModels (line 102)

void &getModels( )

Info

Method getOption (line 85)

void getOption( $association_id, $option_name)

Parameters

  • $association_id:
  • $option_name:

Info

Method getOptions (line 80)

void getOptions( $association_id)

Parameters

  • $association_id:

Info

Method getType (line 156)

void getType( )

Overridden in child classes as:

AkHasMany::getType()
AkHasOne::getType()
AkHasAndBelongsToMany::getType()
AkBelongsTo::getType()

Info

Method initializeAssociated (line 34)

void initializeAssociated( $options)

Parameters

  • $options:

Info

Method isOwnerAnActiveRecord (line 166)

void isOwnerAnActiveRecord( )

Info

Method loadAssociated (line 133)

void &loadAssociated( $association_id)

Parameters

  • $association_id:

Info

Method setAssociatedId (line 127)

void setAssociatedId( $association_id, $associated_id)

Parameters

  • $association_id:
  • $associated_id:

Info

Method setAssociationId (line 53)

void setAssociationId( $association_id)

Parameters

  • $association_id:

Info

Method setOptions (line 75)

void setOptions( $association_id, $options)

Parameters

  • $association_id:
  • $options:

Info

Method _build (line 113)

void &_build( $association_id, &$AssociatedObject, [ $reference_associated = true])

Overridden in child classes as:

AkHasMany::_build()
AkHasAndBelongsToMany::_build()

Parameters

  • $association_id:
  • &$AssociatedObject:
  • $reference_associated:

Info

Method _findOwnerTypeForAssociation (line 190)

void _findOwnerTypeForAssociation( &$AssociatedModel, $Owner)

Recurses through $owner and its superclasses until it finds the class which defines the association to the given $associatedModel

Parameters

  • &$AssociatedModel:
  • $Owner:

Info

Method _getLoadedHandler (line 182)

void _getLoadedHandler( $association_id)

Parameters

  • $association_id:

Info

Method _hasTablePrefix (line 172)

void _hasTablePrefix( $association_id)

Parameters

  • $association_id:

Info

Method _saveLoadedHandler (line 177)

void _saveLoadedHandler( $association_id, $associated)

Parameters

  • $association_id:
  • $associated:

Info

Method _setAssociationAccesorAliasReferences (line 67)

void _setAssociationAccesorAliasReferences( )

Info

Inherited Variables

Inherited Class Variable Summary

Inherited From Class AkObserver

AkObserver::$_observing - $_observing array of models that we're observing

Inherited Methods

Inherited Method Summary

Inherited From Class AkObserver

AkObserver::__construct() -

AkObserver::observe() - Constructs the Observer

AkObserver::setObservedModels() - Constructs the Observer

AkObserver::update() -


Inherited From Class AkObject

AkObject::AkObject() - A hack to support __construct() on PHP 4

AkObject::__construct() - Class constructor, overriden in descendant classes

AkObject::freeMemory() - Unsets circular reference children that are not freed from memory when calling unset() or when the parent object is garbage collected.

AkObject::log() -

AkObject::toString() - Object-to-string conversion

AkObject::__clone() - Clone class (Zend Engine 2 compatibility trick)

AkObject::__destruct() - Class destructor, overriden in descendant classes

AkObject::__toString() -



Documentation generated on Tue, 17 Jun 2008 14:24:48 +0200 by phpDocumentor 1.3.2