Class AkActsAsTree

(line 92)

Description

AkObject
   |
   --AkObserver
      |
      --AkActsAsTree

Located in File: /AkActiveRecord/AkActsAsBehaviours/AkActsAsTree.php

acts_as_tree

Makes your model acts as a tree (surprise!). Consider the following example:

class Category extends ActiveRecord { var $acts_as = 'tree'; }

$Category = new Category;

$CategoryA = $Category->create(); $CategoryAa = $Category->create(); $CategoryAa1 = $Category->create(); $CategoryAa2 = $Category->create(); $CategoryAb = $Category->create(); $CategoryB = $Category->create();

$CategoryA->tree->addChild($CategoryAa) $CategoryA->tree->addChild($CategoryAb) $CategoryAa->tree->addChild($CategoryAa1) $CategoryAa->tree->addChild($CategoryAa2)

This will effectively give you:

Category A \_ Category Aa \_ Category Aa1 \_ Category Aa2 \_ Category Ab Category B

OK. Admittedly you won't get a graph in real life. But at least the following functions:

$CategoryA->tree->hasChildren() # ==> true $CategoryA->tree->childrenCount() # ==> 2 $CategoryA->tree->getChildren() # ==> array($CategoryAa, $CategoryAb) // fairly expensive operation follows // (yes, array(parent, array_of_children) is not nice but unfortunately PHP doesn't allow for objects as keys) $CategoryA->tree->getDescendants() # ==> array(array($CategoryAa, array($CategoryAa1, $CategoryAa2)), $CategoryAb)

$CategoryAa->tree->getChildren() # ==> array($CategoryAa1, $CategoryAa2) $CategoryAa->tree->getSiblings() # ==> array($CategoryAb) $CategoryAa->tree->hasParent() # ==> true $CategoryAa->tree->getParent() # ==> $CategoryA

$CatagoryAa1->tree->hasChildren() # ==> false $CategoryAa1->tree->getParent() # ==> $CategoryAa // fairly expensive operation follows $CategoryAa1->tree->getAncestors() # ==> array($CategoryAa, $CategoryA) // fairly expensive operation follows $CategoryAa1->tree->getAncestors(1) # ==> array($CategoryAa)

To make this work your model needs a parent_id column (whose name can be overriden with +parent_column+. Furthermore you can set the +dependent+ option to automatically delete all children if their parent gets deleted. Otherwise they will become orphants (i.e. have parent_id = NULL)

(Note that on adding a child it will be saved. If the parent has been unsaved until now it will also be saved.)



Class Variables

Summary:
mixed $scope
mixed $_dependent

$parent_column = 'parent_id' (line 108)

Data type : mixed

Configuration options are:

* +parent_column+ - specifies the column name to use for keeping the position integer (default: parent_id) * +dependent+ - set to true to automatically delete all children when its parent is deleted * +scope+ - restricts what is to be considered a list. Given a symbol, it'll attach "_id" (if that hasn't been already) and use that as the foreign key restriction. It's also possible to give it an entire string that is interpolated if you need a tighter scope than just a foreign key. Example: <tt>actsAsTree(array('scope' => array('todo_list_id = ? AND completed = 0',$todo_list_id)));</tt>

$scope (line 109)

Data type : mixed

$scope_condition (line 110)

Data type : mixed

$_ActiveRecordInstance (line 114)

Data type : mixed

$_dependent = false (line 112)

Data type : mixed

$_parent_column_name = 'parent_id' (line 111)

Data type : mixed

Class Constants

Summary:

Method Detail

Summary:
AkActsAsTree AkActsAsTree ( &$ActiveRecordInstance)
void addChild ( &$child)
void beforeDestroy ( &$object)
void childrenCount ()
void getAncestors ([integer $level = 0])
void getChildren ()
void getDependent ()
void getDescendants ([integer $level = 0])
void getParent ()
void getScopedColumn ( $column)
void getSiblings ([ $options = array()])
void getType ()
void hasChildren ()
void hasParent ()
void init ([ $options = array()])
void reloadActiveRecordInstance ( &$nodeInstance)
void setDependent ( $val)
void setParentColumnName ( $parent_column_name)
void setScopeCondition ( $scope_condition)
void _ensureIsActiveRecordInstance ( &$ActiveRecordInstance)
void _recursiveGetDescendants ( $level,  $from)

Constructor AkActsAsTree (line 116)

AkActsAsTree AkActsAsTree( &$ActiveRecordInstance)

Parameters

  • &$ActiveRecordInstance:

Info

Method addChild (line 228)

void addChild( &$child)

Parameters

  • &$child:

Info

Method beforeDestroy (line 350)

void beforeDestroy( &$object)

Parameters

  • &$object:

Info

Method childrenCount (line 260)

void childrenCount( )

Info

Method getAncestors (line 284)

void getAncestors( [integer $level = 0])

Parameters

  • integer $level: How deep do you want to search? everything <= 0 means infinite deep

Info

Method getChildren (line 266)

void getChildren( )

Info

Method getDependent (line 207)

void getDependent( )

Info

Method getDescendants (line 323)

void getDescendants( [integer $level = 0])

Parameters

  • integer $level: How deep do you want to search? everything <= 0 means infinite deep

Info

Method getParent (line 271)

void getParent( )

Info

Method getParentColumnName (line 197)

void getParentColumnName( )

Info

Method getScopeCondition (line 161)

void getScopeCondition( )

Info

Method getScopedColumn (line 185)

void getScopedColumn( $column)

Parameters

  • $column:

Info

Method getSelfAndSiblings (line 315)

void getSelfAndSiblings( )

Info

Method getSiblings (line 305)

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

Parameters

  • $options:

Info

Method getType (line 156)

void getType( )

Info

Method hasChildren (line 217)

void hasChildren( )

Info

Method hasParent (line 222)

void hasParent( )

Info

Method init (line 121)

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

Parameters

  • $options:

Info

Method reloadActiveRecordInstance (line 151)

void reloadActiveRecordInstance( &$nodeInstance)

Parameters

  • &$nodeInstance:

Info

Method setDependent (line 212)

void setDependent( $val)

Parameters

  • $val:

Info

Method setParentColumnName (line 202)

void setParentColumnName( $parent_column_name)

Parameters

  • $parent_column_name:

Info

Method setScopeCondition (line 176)

void setScopeCondition( $scope_condition)

Parameters

  • $scope_condition:

Info

Method _ensureIsActiveRecordInstance (line 131)

void _ensureIsActiveRecordInstance( &$ActiveRecordInstance)

Parameters

  • &$ActiveRecordInstance:

Info

Method _recursiveGetDescendants (line 331)

void _recursiveGetDescendants( $level, $from)

Parameters

  • $level:
  • $from:

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