Download the PHP package allegiance-group/nested-set without Composer
On this page you can find all versions of the php package allegiance-group/nested-set. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download allegiance-group/nested-set
More information about allegiance-group/nested-set
Files in allegiance-group/nested-set
Package nested-set
Short Description PHP library for manipulating and retrieving database records using nested set model technique to represent tree data structure
License BSD-3-Clause
Homepage https://github.com/Beaconfire/NestedSet
Informations about the package nested-set
metalinspired\NestedSet v2
Introduction
This is a fork of the repository by metalspired found at https://github.com/metalinspired/NestedSet. This was created to apply the following patches: (Find nested set node id by custom data)[https://github.com/Beaconfire/NestedSet/commit/f52319a30c295fb1bc373a260aeaf50a59c21235.patch] (Prevent warnings in Drupal admin)[https://github.com/Beaconfire/NestedSet/commit/75367158584e16c0e5612159f16703c64c8fa2ae.patch]
This library allows you to manipulate and retrieve database records using nested set model technique to represent tree data structure. It uses Laminas\Db as underlying database abstraction layer.
Requirements
- PHP >= 5.6
- Laminas\Db >= 2.8
Installation
Usage
(Hybrid) Nested Set
Nested Set requires only left
and right
columns in table to represent a tree structure.
Hybrid Nested Set requires additional parent
, ordering
and depth
columns.
This addition makes manipulation more complex but greatly simplifies retrieval of nodes.
For example, in order to find siblings of a node we simply query for nodes with same parent, instead of using join
to find parent and join
to get parent's immediate descendants.
Ordering
column is used to represent natural order of nodes.
Config object
Config class, as name suggests, is used to create an object with predefined configuration for manipulation/selection classes in this utility, and you do so by changing values of its public members. It also has three static methods that create instance of Config object and set its $adapter member to an Laminas\DB\Adapter\Driver instance.
Example:
Manipulation
Manipulate classes contain methods for creating (inserting), moving and deleting nodes in nested set model. It also has createRootNode method that creates a root node that serves as a container for all other nodes.
Example:
Manipulation methods, excluding insert
, can also accept array of node identifiers as their first argument, meaning you can move
, delete
and clean
multiple nodes with just one call.
Example:
HybridManipulate class has extra method named reorder
.
It allows you to move a node within its parent by using order column value as destination instead of node identifier.
Retrieving records
Find classes contain methods for retrieving records and their names pretty much explain what they do. All you need is to provide them with node identifier ($id argument), all other arguments are options. For arguments list please refer to each function source;
Each of these methods have an (almost) equal get*Query method (for example getFindAncestorsQuery
) which returns Select object instead of ResultInterface.
Unlike find methods these methods do not take identifier as argument but instead define an :id placeholder.
For usage example simply look at one of find* methods.
Important note: Unlike $columns or $where arguments, when using $order argument you must match column names with table t
(t
is an alias for table you are querying), for example:
Factory
Factory encapsulates find and manipulate classes of NestedSet
and HybridNestedSet
in one class.