NodeContext
API reference › Nested sets behavior › NodeContext
Represents the immutable target position and depth offset of a node insertion or move relative to a target node.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$depthLevelDelta readonly constructor | int | Depth offset relative to the target node: 1 for a child, 0 for a sibling. | NodeContext |
$targetPositionValue readonly constructor | int | Left value the inserted or moved node takes. | NodeContext |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a context for a position relative to the target node. | NodeContext |
forAppendTo() static | Creates the context that places a node as the last child of the target node. | NodeContext |
forInsertAfter() static | Creates the context that places a node as the next sibling of the target node. | NodeContext |
forInsertBefore() static | Creates the context that places a node as the previous sibling of the target node. | NodeContext |
forPrependTo() static | Creates 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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(yii\db\ActiveRecord $targetNode, int $targetPositionValue, int $depthLevelDelta)Creates a context for a position relative to the target node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$targetNode | yii\ | Node the insertion or move is relative to. |
$targetPositionValue | int | Left value the inserted or moved node takes. |
$depthLevelDelta | int | Depth offset relative to the target node: 1 for a child, 0 for a sibling. |
forAppendTo()
Section titled “forAppendTo() ”public static function forAppendTo(yii\db\ActiveRecord $targetNode, "rgt" $rightAttribute): selfCreates the context that places a node as the last child of the target node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$targetNode | yii\ | Node that becomes the parent. |
$rightAttribute | "rgt" | Name of the right boundary attribute. |
Returns
self: Context positioned at the target right value.
forInsertAfter()
Section titled “forInsertAfter() ”public static function forInsertAfter(yii\db\ActiveRecord $targetNode, "rgt" $rightAttribute): selfCreates the context that places a node as the next sibling of the target node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$targetNode | yii\ | Node that becomes the previous sibling. |
$rightAttribute | "rgt" | Name of the right boundary attribute. |
Returns
self: Context positioned right after the target right value.
forInsertBefore()
Section titled “forInsertBefore() ”public static function forInsertBefore(yii\db\ActiveRecord $targetNode, "lft" $leftAttribute): selfCreates the context that places a node as the previous sibling of the target node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$targetNode | yii\ | Node that becomes the next sibling. |
$leftAttribute | "lft" | Name of the left boundary attribute. |
Returns
self: Context positioned at the target left value.
forPrependTo()
Section titled “forPrependTo() ”public static function forPrependTo(yii\db\ActiveRecord $targetNode, "lft" $leftAttribute): selfCreates the context that places a node as the first child of the target node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$targetNode | yii\ | Node that becomes the parent. |
$leftAttribute | "lft" | Name of the left boundary attribute. |
Returns
self: Context positioned right after the target left value.
getTargetDepth()
Section titled “getTargetDepth() ”public function getTargetDepth("depth" $depthAttribute): intReturns the depth of the target node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$depthAttribute | "depth" | Name of the depth attribute. |
Returns
int: Depth of the target node.e
getTargetTreeValue()
Section titled “getTargetTreeValue() ”public function getTargetTreeValue(false|string $treeAttribute): mixedReturns the tree identifier of the target node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$treeAttribute | false| | Name of the tree attribute, or false when multiple trees are disabled. |
Returns
mixed: Tree identifier, or null when $treeAttribute is false.