sweelix/tree

PHP 5.6+ Tree structure management

1.0.2 2016-03-22 08:25 UTC

This package is not auto-updated.

Last update: 2024-11-17 01:27:11 UTC


README

Sweelix node management is an implementation of Rational numbers to key nested sets by Dan Hazel (http://arxiv.org/abs/0806.3115).

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License

Latest Development Version Build Status Scrutinizer Code Quality Code Coverage

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.