2017 © Pedro Peláez
 

library closure-table

Traits for Closure Table in LeanMapper

image

inlm/closure-table

Traits for Closure Table in LeanMapper

  • Wednesday, December 27, 2017
  • by janpecha
  • Repository
  • 1 Watchers
  • 0 Stars
  • 788 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

Closure Table

Traits for Closure Table for LeanMapper., (*1)

Installation

Download a latest package or use Composer:, (*2)

composer require inlm/closure-table

Library requires PHP 5.4.0 or later., (*3)

Example

Database tables

``` sql CREATE TABLE category ( id int(10) unsigned NOT NULL AUTO_INCREMENT, name varchar(50) COLLATE utf8mb4_czech_ci NOT NULL, parent_id int(10) unsigned DEFAULT NULL, PRIMARY KEY (id), KEY parent_id (parent_id), CONSTRAINT category_ibfk_2 FOREIGN KEY (parent_id) REFERENCES category (id) ) ENGINE=InnoDB;, (*4)

CREATE TABLE category_closure ( ancestor_id int(10) unsigned NOT NULL, descendant_id int(10) unsigned NOT NULL, depth int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (ancestor_id,descendant_id), KEY descendant_id (descendant_id), CONSTRAINT category_closure_ibfk_1 FOREIGN KEY (ancestor_id) REFERENCES category (id), CONSTRAINT category_closure_ibfk_2 FOREIGN KEY (descendant_id) REFERENCES category (id) ) ENGINE=InnoDB;, (*5)



### Repository ``` php <?php class CategoryRepository extends \LeanMapper\Repository { use \Inlm\ClosureTable\TClosureTableRepository; }

Entity

``` php <?php /** * @property-read int $id * @property string $name * @property Category|NULL $parent m:hasOne(parent_id) * @property-read Category[] $parents m:hasMany(descendant_id:category_closure:ancestor_id:category) [optional] */ class Category extends \LeanMapper\Entity { use \Inlm\ClosureTable\TClosureTableEntity;, (*6)

/**
 * Returns direct children, ordered by 'name'
 * @return Category[]
 */
public function getChildren()
{
    return $this->getChildrenEntities(array('name'));
}

}, (*7)


Entity API: ``` php $category->getChildren(); // returns direct children (children.parent_id = category.id) $category->getParents(); // returns parent entities ordered by `depth` (from root) $category->getDescendants(); // returns all descendants $category->getAncestors(); // returns all ancestors $category->getDepth(); // returns entity depth in collection, for standalone entity returns 0

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/, (*8)

The Versions

27/12 2017

dev-master

9999999-dev

Traits for Closure Table in LeanMapper

  Sources   Download

BSD-3-Clause

The Requires

 

07/07 2016

v1.0.1

1.0.1.0

Traits for Closure Table in LeanMapper

  Sources   Download

BSD-3-Clause

The Requires

 

06/03 2016

v1.0.0

1.0.0.0

Traits for Closure Table in LeanMapper

  Sources   Download

BSD-3-Clause

The Requires