TreeTrait
Public API for moving tree nodes on the bridge side, shared by both bridge stacks (Admin and Front).
It delegates through service, mapper and repository (bridge POST to the Api endpoint).
Table of Contents
Methods
- deleteNode() : Result
- Deletes a node with its whole subtree and closes the gap in `lft`/`rgt`.
- insertTreeNode() : Result
- Computes `lft`, `rgt` and `level` for a newly inserted node (after `save()`, when it has `parent_id` but zero `lft`/`rgt`); it becomes the last sibling.
- moveDown() : Result
- moveSubtree() : Result
- Moves the whole subtree under another parent.
- moveSubtreeTo() : Result
- Moves the whole subtree under a new parent at a specific position.
- moveUp() : Result
- reorderChildren() : Result
- Reorders the direct children of a parent (with subtrees) in one operation under the tree lock on the Api.
- moveTreeNode() : Result
- requireServiceTreeMethod() : void
- Loud guard against silent failure: a bridge tree operation runs only when the next service has the same tree method.
Methods
deleteNode()
Deletes a node with its whole subtree and closes the gap in `lft`/`rgt`.
public
deleteNode(int $id[, TreeConfig $config = new TreeConfig() ]) : Result
Parameters
- $id : int
- $config : TreeConfig = new TreeConfig()
Return values
ResultinsertTreeNode()
Computes `lft`, `rgt` and `level` for a newly inserted node (after `save()`, when it has `parent_id` but zero `lft`/`rgt`); it becomes the last sibling.
public
insertTreeNode(int $id[, TreeConfig $config = new TreeConfig() ]) : Result
Parameters
- $id : int
- $config : TreeConfig = new TreeConfig()
Return values
ResultmoveDown()
public
moveDown(int $id[, TreeConfig $config = new TreeConfig() ]) : Result
Parameters
- $id : int
- $config : TreeConfig = new TreeConfig()
Return values
ResultmoveSubtree()
Moves the whole subtree under another parent.
public
moveSubtree(int $id, int|null $newParentId[, TreeConfig $config = new TreeConfig() ]) : Result
Parameters
- $id : int
- $newParentId : int|null
-
null moves to the root level
- $config : TreeConfig = new TreeConfig()
Return values
ResultmoveSubtreeTo()
Moves the whole subtree under a new parent at a specific position.
public
moveSubtreeTo(int $id, int|null $newParentId, int $afterId[, TreeConfig $config = new TreeConfig() ][, TreeMoveExpectation|null $expectation = null ]) : Result
Parameters
- $id : int
- $newParentId : int|null
-
null is the root level
- $afterId : int
-
-1 as the first child, 0 as the last child, >0 after that sibling
- $config : TreeConfig = new TreeConfig()
- $expectation : TreeMoveExpectation|null = null
-
expected state verified on the Api under a lock (a mismatch gives
TREE_STALE); null skips the check
Return values
ResultmoveUp()
public
moveUp(int $id[, TreeConfig $config = new TreeConfig() ]) : Result
Parameters
- $id : int
- $config : TreeConfig = new TreeConfig()
Return values
ResultreorderChildren()
Reorders the direct children of a parent (with subtrees) in one operation under the tree lock on the Api.
public
reorderChildren(int|null $parentId, array<int, int> $orderedIds[, TreeConfig $config = new TreeConfig() ]) : Result
A mismatching set of children gives TREE_STALE; data.changed is the number of moved children.
Parameters
- $parentId : int|null
-
null is the root level
- $orderedIds : array<int, int>
-
ids of all children of the parent in the new order
- $config : TreeConfig = new TreeConfig()
Return values
ResultmoveTreeNode()
private
moveTreeNode(int $id, int $direction, TreeConfig $config) : Result
Parameters
- $id : int
- $direction : int
- $config : TreeConfig
Return values
ResultrequireServiceTreeMethod()
Loud guard against silent failure: a bridge tree operation runs only when the next service has the same tree method.
private
requireServiceTreeMethod(string $method) : void
IMPORTANT: TreeTrait must be used per entity on every layer (manager, service, mapper,
repository); it is not inherited from the Admin/Front base. When one is missing the call throws
a LogicException (logged) instead of a silent INVALID_OPERATION that hides where the
wiring is broken.
Parameters
- $method : string