sweelix / tree
PHP 5.6+ Tree structure management
Requires
- php: >=5.6.0
Requires (Dev)
- php: >=5.6.0
- codeception/codeception: *
This package is not auto-updated.
Last update: 2024-12-15 01:47:59 UTC
README
Sweelix node management is an implementation of Rational numbers to key nested sets by Dan Hazel (http://arxiv.org/abs/0806.3115).
Installation
If you use Packagist for installing packages, then you can update your composer.json like this :
{ "require": { "sweelix/tree": "*" } }
Howto use it
Create a Node class and attach the NodeTrait to it. You can look at the class Node
.
use sweelix\tree\NodeTrait; class MyNode { use NodeTrait; }
Now you can create a node :
$node = new MyNode(); $node->setPath('1.2.1'); $leftBorder = $node->getLeft(); $rightBorder = $node->getRight(); $treeInfo = $node->getMatrix()->toArray(); // insert your node in DB using leftBorder and rightBorder // do not forget to also store the tree info
Now you can search the node in your DB using regular nested set methods :
# find all the children select * from nodes where left > :nodeLeft and right < :nodeRight order by nodeLeft; # find all the parents select * from nodes where left < :nodeLeft and right > :nodeRight order by nodeRight;
Contributing
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
Fork the project, create a feature branch , and send us a pull request.