Download the PHP package paulzi/yii2-adjacency-list without Composer
On this page you can find all versions of the php package paulzi/yii2-adjacency-list. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paulzi/yii2-adjacency-list
More information about paulzi/yii2-adjacency-list
Files in paulzi/yii2-adjacency-list
Package yii2-adjacency-list
Short Description Adjacency List Behavior for Yii2
License MIT
Informations about the package yii2-adjacency-list
Yii2 Adjacency List Behavior
Implementation of adjacency list algorithm for storing the trees in DB tables.
Install
Install via Composer:
or add
to the require
section of your composer.json
file.
Migrations example
Configuring
Optional you can setup Query for finding roots:
Query class:
Sortable Behavior
This behavior attach SortableBehavior. You can use its methods (for example, reorder()).
Options
$parentAttribute = 'parent_id'
- parent attribute in table schema.$sortable = []
- SortableBehavior settings - see paulzi/yii2-sortable.$checkLoop = false
- check loop when moving nodes (slower).$parentsJoinLevels = 3
- amount of join levels, when finding ancestors.$childrenJoinLevels = 3
- amount of join levels, when finding descendants.
Usage
Selection
Getting the root nodes
If you connect AdjacencyListQueryTrait
, you can get all the root nodes:
Getting ancestors of a node
To get ancestors of a node:
To get parent of a node:
To get root of a node:
For get ordered list of primary keys ancestors:
Getting descendants of a node
To get all the descendants of a node:
*Note: guaranteed order on each parent nodes, nodes of different parents can be mixed with each other and option childrenJoinLevels can change this order.
To populate children
relations for self and descendants of a node:
To get the children of a node:
For get ordered array of primary keys descendants per level:
*Note: guaranteed order on each parent nodes, nodes of different parents can be mixed with each other and option childrenJoinLevels can change this order.
Getting the leaves nodes
To get all the leaves of a node:
Getting the neighbors nodes
To get the next node:
To get the previous node:
Some checks
Modifications
To make a root node:
Note: if you allow multiple trees and attribute tree
is not set, it automatically takes the primary key value.
To prepend a node as the first child of another node:
To append a node as the last child of another node:
To insert a node before another node:
To insert a node after another node:
To delete a node with descendants:
Note: when deleting with delete() child nodes mixed with parent
Reorder children:
Updating from 1.x to 2.x
1) Move attributes sortAttribute
, step
into sortable
attribute.
2) Change namespace from paulzi\adjacencylist
to paulzi\adjacencyList
.
3) Include paulzi\yii2-sortable
(composer update
).