https://github.com/pgaultier/tree
Hazel Tree management for PHP
https://github.com/pgaultier/tree
Last synced: 7 months ago
JSON representation
Hazel Tree management for PHP
- Host: GitHub
- URL: https://github.com/pgaultier/tree
- Owner: pgaultier
- License: other
- Created: 2016-03-21T16:22:43.000Z (over 9 years ago)
- Default Branch: devel
- Last Pushed: 2016-03-22T17:10:24.000Z (over 9 years ago)
- Last Synced: 2025-02-15T07:40:26.473Z (9 months ago)
- Language: PHP
- Size: 42 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Sweelix Node management
=======================
Sweelix node management is an implementation of Rational numbers to key nested sets
by Dan Hazel (http://arxiv.org/abs/0806.3115).
[](https://packagist.org/packages/sweelix/tree)
[](https://travis-ci.org/pgaultier/tree)
[](https://scrutinizer-ci.com/g/pgaultier/tree/?branch=master)
[](https://scrutinizer-ci.com/g/pgaultier/tree/?branch=master)
[](https://packagist.org/packages/sweelix/tree)
[](https://packagist.org/packages/sweelix/tree)
[](https://travis-ci.org/pgaultier/tree)
[](https://scrutinizer-ci.com/g/pgaultier/tree/?branch=devel)
[](https://scrutinizer-ci.com/g/pgaultier/tree/?branch=devel)
Installation
------------
If you use Packagist for installing packages, then you can update your composer.json like this :
``` json
{
"require": {
"sweelix/tree": "*"
}
}
```
Howto use it
------------
Create a Node class and attach the NodeTrait to it. You can look at the class ```Node```.
``` php
use sweelix\tree\NodeTrait;
class MyNode {
use NodeTrait;
}
```
Now you can create a node :
``` php
$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 :
```sql
# 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 ](http://nvie.com/posts/a-successful-git-branching-model/), and send us a pull request.