Inheritance diagram for TreeBehavior:

Public Member Functions | |
| __getMax ($Model, $scope, $right, $recursive=-1, $created=false) | |
| __getMin ($Model, $scope, $left, $recursive=-1) | |
| __sync (&$Model, $shift, $dir= '+', $conditions=array(), $created=false, $field= 'both') | |
| _setParent (&$Model, $parentId=null, $created=false) | |
| afterSave (&$Model, $created) | |
| beforeDelete (&$Model) | |
| beforeSave (&$Model) | |
| childcount (&$Model, $id=null, $direct=false) | |
| children (&$Model, $id=null, $direct=false, $fields=null, $order=null, $limit=null, $page=1, $recursive=null) | |
| generatetreelist (&$Model, $conditions=null, $keyPath=null, $valuePath=null, $spacer= '_', $recursive=null) | |
| getparentnode (&$Model, $id=null, $fields=null, $recursive=null) | |
| getpath (&$Model, $id=null, $fields=null, $recursive=null) | |
| movedown (&$Model, $id=null, $number=1) | |
| moveup (&$Model, $id=null, $number=1) | |
| recover (&$Model, $mode= 'parent', $missingParentAction=null) | |
| removefromtree (&$Model, $id=null, $delete=false) | |
| reorder (&$Model, $options=array()) | |
| setup (&$Model, $config=array()) | |
| verify (&$Model) | |
Public Attributes | |
| $_defaults | |
| $errors = array() | |
Definition at line 36 of file tree.php.
| TreeBehavior::__getMax | ( | $ | Model, | |
| $ | scope, | |||
| $ | right, | |||
| $ | recursive = -1, |
|||
| $ | created = false | |||
| ) |
get the maximum index value in the table.
Definition at line 870 of file tree.php.
References ConnectionManager::getDataSource().
| TreeBehavior::__getMin | ( | $ | Model, | |
| $ | scope, | |||
| $ | left, | |||
| $ | recursive = -1 | |||
| ) |
get the minimum index value in the table.
Definition at line 897 of file tree.php.
References ConnectionManager::getDataSource().
| TreeBehavior::__sync | ( | &$ | Model, | |
| $ | shift, | |||
| $ | dir = '+', |
|||
| $ | conditions = array(), |
|||
| $ | created = false, |
|||
| $ | field = 'both' | |||
| ) |
| TreeBehavior::_setParent | ( | &$ | Model, | |
| $ | parentId = null, |
|||
| $ | created = false | |||
| ) |
Sets the parent of the given node
The force parameter is used to override the "don't change the parent to the current parent" logic in the event of recovering a corrupted table, or creating new nodes. Otherwise it should always be false. In reality this method could be private, since calling save with parent_id set also calls setParent
| TreeBehavior::afterSave | ( | &$ | Model, | |
| $ | created | |||
| ) |
After save method. Called after all saves
Overriden to transparently manage setting the lft and rght fields if and only if the parent field is included in the parameters to be saved.
| AppModel | $Model Model instance. | |
| boolean | $created indicates whether the node just saved was created or updated |
Reimplemented from ModelBehavior.
| TreeBehavior::beforeDelete | ( | &$ | Model | ) |
| TreeBehavior::beforeSave | ( | &$ | Model | ) |
Before save method. Called before all saves
Overriden to transparently manage setting the lft and rght fields if and only if the parent field is included in the parameters to be saved. For newly created nodes with NO parent the left and right field values are set directly by this method bypassing the setParent logic.
Reimplemented from ModelBehavior.
| TreeBehavior::childcount | ( | &$ | Model, | |
| $ | id = null, |
|||
| $ | direct = false | |||
| ) |
Get the number of child nodes
If the direct parameter is set to true, only the direct children are counted (based upon the parent_id field) If false is passed for the id parameter, all top level nodes are counted, or all nodes are counted.
| AppModel | $Model Model instance | |
| mixed | $id The ID of the record to read or false to read all top level nodes | |
| boolean | $direct whether to count direct, or all, children |
Definition at line 211 of file tree.php.
References $id.
| TreeBehavior::children | ( | &$ | Model, | |
| $ | id = null, |
|||
| $ | direct = false, |
|||
| $ | fields = null, |
|||
| $ | order = null, |
|||
| $ | limit = null, |
|||
| $ | page = 1, |
|||
| $ | recursive = null | |||
| ) |
Get the child nodes of the current model
If the direct parameter is set to true, only the direct children are returned (based upon the parent_id field) If false is passed for the id parameter, top level, or all (depending on direct parameter appropriate) are counted.
| AppModel | $Model Model instance | |
| mixed | $id The ID of the record to read | |
| boolean | $direct whether to return only the direct, or all, children | |
| mixed | $fields Either a single string of a field name, or an array of field names | |
| string | $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC") defaults to the tree order | |
| integer | $limit SQL LIMIT clause, for calculating items per page. | |
| integer | $page Page number, for accessing paged data | |
| integer | $recursive The number of levels deep to fetch associated records |
| TreeBehavior::generatetreelist | ( | &$ | Model, | |
| $ | conditions = null, |
|||
| $ | keyPath = null, |
|||
| $ | valuePath = null, |
|||
| $ | spacer = '_', |
|||
| $ | recursive = null | |||
| ) |
A convenience method for returning a hierarchical array used for HTML select boxes
| AppModel | $Model Model instance | |
| mixed | $conditions SQL conditions as a string or as an array('field' =>'value',...) | |
| string | $keyPath A string path to the key, i.e. "{n}.Post.id" | |
| string | $valuePath A string path to the value, i.e. "{n}.Post.title" | |
| string | $spacer The character or characters which will be repeated | |
| integer | $recursive The number of levels deep to fetch associated records |
Definition at line 312 of file tree.php.
References Set::combine(), and order.
| TreeBehavior::getparentnode | ( | &$ | Model, | |
| $ | id = null, |
|||
| $ | fields = null, |
|||
| $ | recursive = null | |||
| ) |
Get the parent node
reads the parent id and returns this node
| AppModel | $Model Model instance | |
| mixed | $id The ID of the record to read | |
| integer | $recursive The number of levels deep to fetch associated records |
Definition at line 366 of file tree.php.
References $id.
| TreeBehavior::getpath | ( | &$ | Model, | |
| $ | id = null, |
|||
| $ | fields = null, |
|||
| $ | recursive = null | |||
| ) |
Get the path to the given node
| AppModel | $Model Model instance | |
| mixed | $id The ID of the record to read | |
| mixed | $fields Either a single string of a field name, or an array of field names | |
| integer | $recursive The number of levels deep to fetch associated records |
| TreeBehavior::movedown | ( | &$ | Model, | |
| $ | id = null, |
|||
| $ | number = 1 | |||
| ) |
Reorder the node without changing the parent.
If the node is the last child, or is a top level node with no subsequent node this method will return false
| AppModel | $Model Model instance | |
| mixed | $id The ID of the record to move | |
| mixed | $number how many places to move the node or true to move to last position |
Definition at line 434 of file tree.php.
References $id.
| TreeBehavior::moveup | ( | &$ | Model, | |
| $ | id = null, |
|||
| $ | number = 1 | |||
| ) |
Reorder the node without changing the parent.
If the node is the first child, or is a top level node with no previous node this method will return false
| AppModel | $Model Model instance | |
| mixed | $id The ID of the record to move | |
| mixed | $number how many places to move the node, or true to move to first position |
Definition at line 491 of file tree.php.
References $id.
| TreeBehavior::recover | ( | &$ | Model, | |
| $ | mode = 'parent', |
|||
| $ | missingParentAction = null | |||
| ) |
Recover a corrupted tree
The mode parameter is used to specify the source of info that is valid/correct. The opposite source of data will be populated based upon that source of info. E.g. if the MPTT fields are corrupt or empty, with the $mode 'parent' the values of the parent_id field will be used to populate the left and right fields. The missingParentAction parameter only applies to "parent" mode and determines what to do if the parent field contains an id that is not present.
| AppModel | $Model Model instance | |
| string | $mode parent or tree | |
| mixed | $missingParentAction 'return' to do nothing and return, 'delete' to delete, or the id of the parent to set as the parent_id |
Definition at line 554 of file tree.php.
References $id, $path, ConnectionManager::getDataSource(), and order.
| TreeBehavior::removefromtree | ( | &$ | Model, | |
| $ | id = null, |
|||
| $ | delete = false | |||
| ) |
Remove the current node from the tree, and reparent all children up one level.
If the parameter delete is false, the node will become a new top level node. Otherwise the node will be deleted after the children are reparented.
| AppModel | $Model Model instance | |
| mixed | $id The ID of the record to remove | |
| boolean | $delete whether to delete the node after reparenting children (if any) |
Definition at line 666 of file tree.php.
References $id, and ConnectionManager::getDataSource().
| TreeBehavior::reorder | ( | &$ | Model, | |
| $ | options = array() | |||
| ) |
Reorder method.
Reorders the nodes (and child nodes) of the tree according to the field and direction specified in the parameters. This method does not change the parent of any node.
Requires a valid tree, by default it verifies the tree before beginning.
Options:
| TreeBehavior::setup | ( | &$ | Model, | |
| $ | config = array() | |||
| ) |
Initiate Tree behavior
| object | $Model instance of model | |
| array | $config array of configuration settings. |
Reimplemented from ModelBehavior.
Definition at line 61 of file tree.php.
References $config, and ModelBehavior::$settings.
| TreeBehavior::verify | ( | &$ | Model | ) |
Check if the current tree is valid.
Returns true if the tree is valid otherwise an array of (type, incorrect left/right index, message)
Definition at line 733 of file tree.php.
References a().
| TreeBehavior::$_defaults |
1.4.7