Skip to content
PHP Ecosystem
Explore

QueryConditionBuilder

API reference › Nested sets behavior › QueryConditionBuilder

final classyii2\extensions\nestedsets\QueryConditionBuilder
Sourcesrc/QueryConditionBuilder.php

Builds Yii condition arrays and offset expressions for nested set queries and bulk coordinate updates.

MethodDescriptionDefined by
createChildrenCondition() staticReturns a condition matching the descendants of a node, optionally limited to a maximum depth below it.QueryConditionBuilder
createCrossTreeMoveCondition() staticReturns a condition matching the nodes of a tree whose boundary value is at least the given value.QueryConditionBuilder
createLeavesCondition() staticReturns a condition matching the leaf nodes strictly inside the given ancestor boundaries.QueryConditionBuilder
createNextSiblingCondition() staticReturns a condition matching the node whose left value immediately follows the given right value.QueryConditionBuilder
createOffsetUpdates() staticReturns column expressions for updateAll() that add a signed offset to each given attribute.QueryConditionBuilder
createParentsCondition() staticReturns a condition matching the ancestors of a node, optionally limited to a maximum number of levels above it.QueryConditionBuilder
createPrevSiblingCondition() staticReturns a condition matching the node whose right value immediately precedes the given left value.QueryConditionBuilder
createRangeCondition() staticReturns a condition matching the nodes whose boundaries lie within the given range, inclusive.QueryConditionBuilder
createShiftCondition() staticReturns a condition matching the nodes whose boundary value is at least the given value.QueryConditionBuilder
createSubtreeMoveCondition() staticReturns a condition matching a subtree, including its root, within its current tree.QueryConditionBuilder
public static function createChildrenCondition(string $leftAttribute, int $leftValue, string $rightAttribute, int $rightValue, false|string $treeAttribute = false, mixed $treeValue = null, string|null $depthAttribute = null, int|null $parentDepth = null, int|null $maxRelativeDepth = null): array<int|string, mixed>

Returns a condition matching the descendants of a node, optionally limited to a maximum depth below it.

Parameters

ParameterTypeDescription
$leftAttributestringName of the left boundary attribute.
$leftValueintLeft value of the ancestor.
$rightAttributestringName of the right boundary attribute.
$rightValueintRight value of the ancestor.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$treeValuemixedTree identifier to match; ignored when $treeAttribute is false.
$depthAttributestring|nullName of the depth attribute, or null to skip depth filtering.
$parentDepthint|nullDepth of the ancestor; required together with $maxRelativeDepth.
$maxRelativeDepthint|nullMaximum number of levels below the ancestor, or null for all descendants.

Returns

array<int|string, mixed>: Condition matching the descendants.

public static function createCrossTreeMoveCondition(string $attribute, int $value, string $treeAttribute, mixed $treeValue): array<int|string, mixed>

Returns a condition matching the nodes of a tree whose boundary value is at least the given value.

Opens space in the destination tree before a subtree moves into it.

Parameters

ParameterTypeDescription
$attributestringName of the left or right boundary attribute to compare.
$valueintLowest boundary value to match, inclusive.
$treeAttributestringName of the tree attribute.
$treeValuemixedIdentifier of the tree that receives the subtree.

Returns

array<int|string, mixed>: Condition matching the nodes to shift.

public static function createLeavesCondition(string $leftAttribute, string $rightAttribute, false|string $treeAttribute = false, mixed $treeValue = null, int|null $parentLeftValue = null, int|null $parentRightValue = null): array<int|string, mixed>

Returns a condition matching the leaf nodes strictly inside the given ancestor boundaries.

Parameters

ParameterTypeDescription
$leftAttributestringName of the left boundary attribute.
$rightAttributestringName of the right boundary attribute.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$treeValuemixedTree identifier to match; ignored when $treeAttribute is false.
$parentLeftValueint|nullLeft value of the ancestor whose leaves are matched.
$parentRightValueint|nullRight value of the ancestor whose leaves are matched.

Returns

array<int|string, mixed>: Condition matching the leaf descendants.

public static function createNextSiblingCondition(string $leftAttribute, int $rightValue, false|string $treeAttribute = false, mixed $treeValue = null): array<int|string, mixed>

Returns a condition matching the node whose left value immediately follows the given right value.

Parameters

ParameterTypeDescription
$leftAttributestringName of the left boundary attribute.
$rightValueintRight value of the reference node.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$treeValuemixedTree identifier to match; ignored when $treeAttribute is false.

Returns

array<int|string, mixed>: Condition matching the next sibling.

public static function createOffsetUpdates(yii\db\Connection $db, array<string, int> $attributeOffsets): array<string, yii\db\Expression>

Returns column expressions for updateAll() that add a signed offset to each given attribute.

Parameters

ParameterTypeDescription
$dbyii\db\ConnectionConnection used to quote the column names.
$attributeOffsetsarray<string, int>Signed offsets indexed by attribute name.

Returns

array<string, yii\db\Expression>: Offset expressions indexed by attribute name.

public static function createParentsCondition(string $leftAttribute, int $leftValue, string $rightAttribute, int $rightValue, false|string $treeAttribute = false, mixed $treeValue = null, string|null $depthAttribute = null, int|null $childDepth = null, int|null $maxRelativeDepth = null): array<int|string, mixed>

Returns a condition matching the ancestors of a node, optionally limited to a maximum number of levels above it.

Parameters

ParameterTypeDescription
$leftAttributestringName of the left boundary attribute.
$leftValueintLeft value of the node.
$rightAttributestringName of the right boundary attribute.
$rightValueintRight value of the node.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$treeValuemixedTree identifier to match; ignored when $treeAttribute is false.
$depthAttributestring|nullName of the depth attribute, or null to skip depth filtering.
$childDepthint|nullDepth of the node; required together with $maxRelativeDepth.
$maxRelativeDepthint|nullMaximum number of levels above the node, or null for all ancestors.

Returns

array<int|string, mixed>: Condition matching the ancestors.

public static function createPrevSiblingCondition(string $rightAttribute, int $leftValue, false|string $treeAttribute = false, mixed $treeValue = null): array<int|string, mixed>

Returns a condition matching the node whose right value immediately precedes the given left value.

Parameters

ParameterTypeDescription
$rightAttributestringName of the right boundary attribute.
$leftValueintLeft value of the reference node.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$treeValuemixedTree identifier to match; ignored when $treeAttribute is false.

Returns

array<int|string, mixed>: Condition matching the previous sibling.

public static function createRangeCondition(string $leftAttribute, int $leftValue, string $rightAttribute, int $rightValue, false|string $treeAttribute = false, mixed $treeValue = null): array<int|string, mixed>

Returns a condition matching the nodes whose boundaries lie within the given range, inclusive.

Parameters

ParameterTypeDescription
$leftAttributestringName of the left boundary attribute.
$leftValueintLowest left value to match.
$rightAttributestringName of the right boundary attribute.
$rightValueintHighest right value to match.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$treeValuemixedTree identifier to match; ignored when $treeAttribute is false.

Returns

array<int|string, mixed>: Condition matching the subtree, including its root.

public static function createShiftCondition(string $attribute, int $value, false|string $treeAttribute = false, mixed $treeValue = null): array<int|string, mixed>

Returns a condition matching the nodes whose boundary value is at least the given value.

Parameters

ParameterTypeDescription
$attributestringName of the left or right boundary attribute to compare.
$valueintLowest boundary value to match, inclusive.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$treeValuemixedTree identifier to match; ignored when $treeAttribute is false.

Returns

array<int|string, mixed>: Condition matching the nodes to shift.

public static function createSubtreeMoveCondition(string $leftAttribute, int $leftValue, string $rightAttribute, int $rightValue, false|string $treeAttribute, mixed $currentTreeValue): array<int|string, mixed>

Returns a condition matching a subtree, including its root, within its current tree.

Parameters

ParameterTypeDescription
$leftAttributestringName of the left boundary attribute.
$leftValueintLeft value of the subtree root.
$rightAttributestringName of the right boundary attribute.
$rightValueintRight value of the subtree root.
$treeAttributefalse|stringName of the tree attribute, or false when multiple trees are disabled.
$currentTreeValuemixedIdentifier of the tree that currently contains the subtree.

Returns

array<int|string, mixed>: Condition matching the subtree to move.