Class AkActsAsNestedSet

(line 22)

Description

AkObject
   |
   --AkObserver
      |
      --AkActsAsNestedSet

Located in File: /AkActiveRecord/AkActsAsBehaviours/AkActsAsNestedSet.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);



Class Variables

Summary:

$_ActiveRecordInstance (line 106)

Data type : mixed

$_left_column_name = 'lft' (line 102)

Data type : mixed

$_parent_column_name = 'parent_id' (line 104)

Data type : mixed

$_right_column_name = 'rgt' (line 103)

Data type : mixed

$_scope_condition (line 101)

Data type : mixed

Configuration options are:

* +parent_column+ - specifies the column name to use for keeping the position integer (default: parent_id) * +left_column+ - column name for left boundary data, default "lft" * +right_column+ - column name for right boundary data, default "rgt" * +scope+ - restricts what is to be considered a list. Example: <tt>actsAsList(array('scope' => array('todo_list_id = ? AND completed = 0',$todo_list_id)));</tt>

Class Constants

Summary:

Method Detail

Summary:
AkActsAsNestedSet AkActsAsNestedSet ( &$ActiveRecordInstance)
void addChild ( &$child)
void beforeCreate ( &$object)
void beforeDestroy ( &$object)
void countChildren ()
void getAllChildren ()
void &getAncestors ()
void getChildren ()
void getFullSet ([ $exclude = null])
void getLevel ()
void &getParent ()
void &getParents ()
void getRoot ()
void getRoots ()
void getScopedColumn ( $column)
void getSiblings ([ $search_for_self = false])
void getType ()
void init ([ $options = array()])
void isChild ()
void isRoot ()
void isUnknown ()
void moveTo ( $target,  $position)
void moveToChildOf ( $node)
void moveToLeftOf ( $node)
void moveToRightOf ( $node)
void reloadActiveRecordInstance ( &$nodeInstance)
void setLeftColumnName ( $left_column_name)
void setParentColumnName ( $parent_column_name)
void setRightColumnName ( $right_column_name)
void setScopeCondition ( $scope_condition)
void _ensureIsActiveRecordInstance ( &$ActiveRecordInstance)

Constructor AkActsAsNestedSet (line 108)

AkActsAsNestedSet AkActsAsNestedSet( &$ActiveRecordInstance)

Parameters

  • &$ActiveRecordInstance:

Info

Method addChild (line 250)

void addChild( &$child)

Added a child to this object in the tree. If this object hasn't been initialized, it gets set up as a root node. Otherwise, this method will update all of the other elements in the tree and shift them to the right. Keeping everything balanced.

Parameters

  • &$child:

Info

Method beforeCreate (line 396)

void beforeCreate( &$object)

on creation, set automatically lft and rgt to the end of the tree

Parameters

  • &$object:

Info

Method beforeDestroy (line 335)

void beforeDestroy( &$object)

Prunes a branch off of the tree, shifting all of the elements on the right back to the left so the counts still work.

Parameters

  • &$object:

Info

Method countChildren (line 501)

void countChildren( )

Returns the number of all nested children of this object.

Info

Method getAllChildren (line 521)

void getAllChildren( )

Returns a set of all of its children and nested children

Info

Method getAncestors (line 434)

void &getAncestors( )

Returns an array of all parents

Info

Method getChildren (line 511)

void getChildren( )

Returns a set of only this entry's immediate children

Info

Method getFullSet (line 555)

void getFullSet( [ $exclude = null])

Returns a set of itself and all of its nested children

Parameters

  • $exclude:

Info

Method getLeftColumnName (line 189)

void getLeftColumnName( )

Info

Method getLevel (line 486)

void getLevel( )

Returns the level of this object in the tree

root level is 0

Info

Method getParent (line 308)

void &getParent( )

Returns the parent Object

Info

Method getParentColumnName (line 208)

void getParentColumnName( )

Info

Method getParents (line 324)

void &getParents( )

Returns an array of parent Objects this is usefull to make breadcrum like stuctures

Info

Method getRightColumnName (line 198)

void getRightColumnName( )

Info

Method getRoot (line 417)

void getRoot( )

Returns the single root

Info

Method getRoots (line 425)

void getRoots( )

Returns roots when multiple roots (or virtual root, which is the same)

Info

Method getScopeCondition (line 153)

void getScopeCondition( )

Info

Method getScopedColumn (line 177)

void getScopedColumn( $column)

Parameters

  • $column:

Info

Method getSelfAndAncestors (line 446)

void &getSelfAndAncestors( )

Returns the array of all parents and self

Info

Method getSelfAndSiblings (line 472)

void getSelfAndSiblings( )

Returns the array of all children of the parent, included self

Info

Method getSiblings (line 460)

void getSiblings( [ $search_for_self = false])

Returns the array of all children of the parent, except self

Parameters

  • $search_for_self:

Info

Method getType (line 148)

void getType( )

Info

Method init (line 113)

void init( [ $options = array()])

Parameters

  • $options:

Info

Method isChild (line 229)

void isChild( )

Returns true is this is a child node

Info

Method isRoot (line 220)

void isRoot( )

Returns true is this is a root node.

Info

Method isUnknown (line 239)

void isUnknown( )

Returns true if we have no idea what this is

Info

Method moveTo (line 591)

void moveTo( $target, $position)

Parameters

  • $target:
  • $position:

Info

Method moveToChildOf (line 586)

void moveToChildOf( $node)

Move the node to the child of another node

Parameters

  • $node:

Info

Method moveToLeftOf (line 570)

void moveToLeftOf( $node)

Move the node to the left of another node

Parameters

  • $node:

Info

Method moveToRightOf (line 578)

void moveToRightOf( $node)

Move the node to the left of another node

Parameters

  • $node:

Info

Method reloadActiveRecordInstance (line 143)

void reloadActiveRecordInstance( &$nodeInstance)

Parameters

  • &$nodeInstance:

Info

Method setLeftColumnName (line 193)

void setLeftColumnName( $left_column_name)

Parameters

  • $left_column_name:

Info

Method setParentColumnName (line 212)

void setParentColumnName( $parent_column_name)

Parameters

  • $parent_column_name:

Info

Method setRightColumnName (line 202)

void setRightColumnName( $right_column_name)

Parameters

  • $right_column_name:

Info

Method setScopeCondition (line 168)

void setScopeCondition( $scope_condition)

Parameters

  • $scope_condition:

Info

Method _ensureIsActiveRecordInstance (line 123)

void _ensureIsActiveRecordInstance( &$ActiveRecordInstance)

Parameters

  • &$ActiveRecordInstance:

Info

Method _setLeftAndRightToTheEndOfTheTree (line 402)

void _setLeftAndRightToTheEndOfTheTree( )

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:34 +0200 by phpDocumentor 1.3.2