Skip to content
PHP Ecosystem
Explore

NodeContext

API reference › Nested sets behavior › NodeContext

final readonly classyii2\extensions\nestedsets\NodeContext
Sourcesrc/NodeContext.php

Represents the immutable target position and depth offset of a node insertion or move relative to a target node.

PropertyTypeDescriptionDefined by
$depthLevelDelta readonly constructorintDepth offset relative to the target node: 1 for a child, 0 for a sibling.NodeContext
$targetPositionValue readonly constructorintLeft value the inserted or moved node takes.NodeContext
MethodDescriptionDefined by
__construct()Creates a context for a position relative to the target node.NodeContext
forAppendTo() staticCreates the context that places a node as the last child of the target node.NodeContext
forInsertAfter() staticCreates the context that places a node as the next sibling of the target node.NodeContext
forInsertBefore() staticCreates the context that places a node as the previous sibling of the target node.NodeContext
forPrependTo() staticCreates the context that places a node as the first child of the target node.NodeContext
getTargetDepth()Returns the depth of the target node.NodeContext
getTargetTreeValue()Returns the tree identifier of the target node.NodeContext
public function __construct(yii\db\ActiveRecord $targetNode, int $targetPositionValue, int $depthLevelDelta)

Creates a context for a position relative to the target node.

Parameters

ParameterTypeDescription
$targetNodeyii\db\ActiveRecordNode the insertion or move is relative to.
$targetPositionValueintLeft value the inserted or moved node takes.
$depthLevelDeltaintDepth offset relative to the target node: 1 for a child, 0 for a sibling.
public static function forAppendTo(yii\db\ActiveRecord $targetNode, "rgt" $rightAttribute): self

Creates the context that places a node as the last child of the target node.

Parameters

ParameterTypeDescription
$targetNodeyii\db\ActiveRecordNode that becomes the parent.
$rightAttribute"rgt"Name of the right boundary attribute.

Returns

self: Context positioned at the target right value.

public static function forInsertAfter(yii\db\ActiveRecord $targetNode, "rgt" $rightAttribute): self

Creates the context that places a node as the next sibling of the target node.

Parameters

ParameterTypeDescription
$targetNodeyii\db\ActiveRecordNode that becomes the previous sibling.
$rightAttribute"rgt"Name of the right boundary attribute.

Returns

self: Context positioned right after the target right value.

public static function forInsertBefore(yii\db\ActiveRecord $targetNode, "lft" $leftAttribute): self

Creates the context that places a node as the previous sibling of the target node.

Parameters

ParameterTypeDescription
$targetNodeyii\db\ActiveRecordNode that becomes the next sibling.
$leftAttribute"lft"Name of the left boundary attribute.

Returns

self: Context positioned at the target left value.

public static function forPrependTo(yii\db\ActiveRecord $targetNode, "lft" $leftAttribute): self

Creates the context that places a node as the first child of the target node.

Parameters

ParameterTypeDescription
$targetNodeyii\db\ActiveRecordNode that becomes the parent.
$leftAttribute"lft"Name of the left boundary attribute.

Returns

self: Context positioned right after the target left value.

public function getTargetDepth("depth" $depthAttribute): int

Returns the depth of the target node.

Parameters

ParameterTypeDescription
$depthAttribute"depth"Name of the depth attribute.

Returns

int: Depth of the target node.e

public function getTargetTreeValue(false|string $treeAttribute): mixed

Returns the tree identifier of the target node.

Parameters

ParameterTypeDescription
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.

Returns

mixed: Tree identifier, or null when $treeAttribute is false.