2017 © Pedro Peláez
 

library phptree

A collection of PHP classes for storing a tree in a relational database

image

vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  • Wednesday, May 10, 2017
  • by vakata
  • Repository
  • 1 Watchers
  • 0 Stars
  • 598 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 13 % Grown

The README.md

phptree

Latest Version on Packagist ![Software License][ico-license] Build Status Code Climate ![Tests Coverage][ico-cc-coverage], (*1)

Storing trees in a relational database. Keep in mind the tree needs to have a single root, so it is probably safe to begin with this structure (this example is mySQL, but it should be clear):, (*2)

CREATE TABLE struct (
    id  int(10) unsigned NOT NULL AUTO_INCREMENT,
    lft int(10) unsigned NOT NULL,
    rgt int(10) unsigned NOT NULL,
    lvl int(10) unsigned NOT NULL,
    pid int(10) unsigned NOT NULL,
    pos int(10) unsigned NOT NULL,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO struct VALUES (1, 1, 2, 0, 0, 0);

# now you can use 1 as your tree root

Install

Via Composer, (*3)

``` bash $ composer require vakata/phptree, (*4)


## Usage ```php // create an instance $dbc = new \vakata\database\DB("mysqli://root@127.0.0.1/treedb"); $tree = new \vakata\phptree\Tree( $dbc, 'tree_table', [ 'id' => 'id', 'parent' => 'pid', 'position' => 'pos', 'level' => 'lvl', 'left' => 'lft', 'right' => 'rgt' ] ); // WORKING WITH NODES $tree->getRoot()->getChildren(); // get all children of the root $tree->getRoot()->addChild(new \vakata\phptree\Node(['key' => 'val1'])); // create a node $tree->getRoot()->addChild(new \vakata\phptree\Node(['key' => 'val2'])); // create a node $tree->save(); $tree->getNode(2)->moveTo($tree->getRoot(), 2); $tree->getNode(3)->copyTo($tree->getRoot()); $tree->getNode(3)->remove();

Read more in the API docs, (*5)

Testing

bash $ composer test, (*6)

Contributing

Please see CONTRIBUTING for details., (*7)

Security

If you discover any security related issues, please email github@vakata.com instead of using the issue tracker., (*8)

Credits

License

The MIT License (MIT). Please see License File for more information., (*9)

The Versions

10/05 2017

dev-master

9999999-dev https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

10/05 2017

2.0.5

2.0.5.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

05/04 2017

2.0.4

2.0.4.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

24/01 2017

2.0.3

2.0.3.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

06/12 2016

2.0.2

2.0.2.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

05/12 2016

2.0.1

2.0.1.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

02/12 2016

2.0.0

2.0.0.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

28/10 2016

1.0.2

1.0.2.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

27/10 2016

1.0.1

1.0.1.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata

10/05 2016

1.0.0

1.0.0.0 https://github.com/vakata/phptree

A collection of PHP classes for storing a tree in a relational database

  Sources   Download

MIT

The Requires

 

The Development Requires

tree vakata