Skip to content

Commit ad89950

Browse files
authored
Add usage to readme
1 parent 4daf9f6 commit ad89950

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

Diff for: README.md

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,65 @@
11
# Nested Set
22

3-
A PHP library for a Nested Set implementation.
3+
A PHP Doctrine DBAL implementation for Nested Sets.
44

55
[![CircleCI](https://circleci.com/gh/previousnext/nested-set.svg?style=svg)](https://circleci.com/gh/previousnext/nested-set)
66

7+
## Using
8+
9+
### Create table schema
10+
11+
Create the table schema, passing in a a [DBAL connection](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#getting-a-connection) and table name (defaults to 'tree').
12+
```php
13+
$schema = new DbalNestedSetSchema($connection, 'my_tree');
14+
schema->create();
15+
```
16+
17+
### Set up the nested set client
18+
19+
Create a new `DbalNestedSet` passing in the DBAL connection and the table name.
20+
21+
```php
22+
$nestedSet = new DbalNestedSet($connection, 'my_tree');
23+
```
24+
25+
### Add a root node
26+
27+
A NodeKey represents a unique ID for a node in the tree. It supports the idea of a node ID and a revision ID, mostly for compatibility with Drupal.
28+
29+
```php
30+
$nodeKey = new NodeKey($id, $revisionId);
31+
$rootNode = $nestedSet->addRootNode($nodeKey);
32+
```
33+
34+
### Add a child node
35+
36+
To add a child node, you provide the parent node, and a child node key.
37+
38+
```php
39+
$nodeKey = new NodeKey($id, $revisionId);
40+
$nestedSet->addNodeBelow($rootNode, $nodeKey);
41+
```
42+
43+
### Find Descendants
44+
45+
To find descendents, you provide the parent node key.
46+
47+
```php
48+
$nodeKey = new NodeKey($id, $revisionId);
49+
$descendants = $this->nestedSet->findDescendants($nodeKey);
50+
```
51+
52+
### Find ancestors
53+
54+
To find ancestors, you provide the child node key.
55+
56+
```php
57+
$nodeKey = new NodeKey($id, $revisionId);
58+
$ancestors = $this->nestedSet->findAncestors($nodeKey);
59+
```
60+
61+
See `\PNX\NestedSet\NestedSetInterface` for many more methods that can be used for interacting with the nested set.
62+
763
## Developing
864

965
### Dependencies

0 commit comments

Comments
 (0)