Download the PHP package paulzi/yii2-nested-intervals without Composer
On this page you can find all versions of the php package paulzi/yii2-nested-intervals. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paulzi/yii2-nested-intervals
More information about paulzi/yii2-nested-intervals
Files in paulzi/yii2-nested-intervals
Package yii2-nested-intervals
Short Description Nested Intervals Behavior for Yii2
License MIT
Informations about the package yii2-nested-intervals
Yii2 Nested Intervals Behavior
Implementation of nested intervals 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
Single tree migration:
Multiple tree migration:
Configuring
Optional you can setup Query for finding roots:
Query class:
Options
$treeAttribute = null
- setup tree attribute for multiple tree in table schema.$leftAttribute = 'lft'
- left attribute in table schema.$rightAttribute = 'rgt'
- right attribute in table schema.$depthAttribute = 'depth'
- depth attribute in table schema (note: it must be signed int).$range = [0, 2147483647]
- interval size. Default values is max value for work in 32 bit php and standard signed int columns. If you have BIGINT left and right columns, support 64 bit expression db and 64 bit version of php, you can use[0, 9223372036854775807]
(SQLite not support this).$amountOptimize = 10
- optimization of the insert - the average number of children per level. The value can be an integer or an array indicating the value for each level. If the level is deeper than specified in the property, the value is taken from the last level in the array.$reserveFactor = 1
- factor determining the size of the gaps between the nodes. Default is 1, which corresponds to the fact that the intervals are equal to the size of the elements themselves. If you have many use ofinsertBefore()
andinsertAfter()
methods, you can try to increase this factor for better efficiency.$noPrepend = false
- if true, then when you insert into an empty node will use the initial position of the gap.$noAppend = false
- if true, then when you insert into an empty node will be used by the final position of the gap.$noInsert = false
- if true, then between neighboring nodes will not be gaps.
Usage
Selection
Getting the root nodes
If you connect NestedIntervalsQueryTrait
, 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:
Getting descendants of a node
To get all the descendants of a node:
To populate children
relations for self and descendants of a node:
To get the children of a node:
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:
Optimisation
For uniform distribution of nodes over the interval (slow!):