Skip to content

Latest commit

 

History

History
130 lines (95 loc) · 2.72 KB

README.md

File metadata and controls

130 lines (95 loc) · 2.72 KB

DoctrineExtensions - Tree

Build Status Quality Score Code Coverage Downloads this Month Latest stable

Implementation of Tree from DoctrineExtensions to Nette.

Install

Via Composer:

$ composer require zenify/doctrine-extensions-tree

Register extension in your config.neon:

extensions:
	- Zenify\DoctrineExtensionsTree\DI\TreeExtension

Usage

For entity implementation, follow manual

Very simple entity could look like this:

namespace App\Entities;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;


/**
 * @ORM\Entity(repositoryClass="App\Model\CategoryTree")
 * @Gedmo\Tree(type="materializedPath")
 */
class Category
{

	/**
	 * @ORM\Column(type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue
	 */
	public $id;

	/**
	 * @Gedmo\TreePathSource
	 * @ORM\Column(type="string")
	 * @var string
	 */
	private $name;

	/**
	 * @Gedmo\TreeParent
	 * @ORM\ManyToOne(targetEntity="Category", cascade={"persist"})
	 * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=TRUE)
	 * @var Category
	 */
	private $parent;

	/**
 	 * @Gedmo\TreePath(separator="|")
	 * @ORM\Column(type="string", nullable=TRUE)
	 * @var string
	 */
	private $path;


	/**
	 * @param string $name
	 * @param Category $parent
	 */
	public function __construct($name, Category $parent = NULL)
	{
		$this->name = $name;
		$this->parent = $parent;
	}


	/**
	 * @return string
	 */
	public function getName()
	{
		return $this->name;
	}


	/**
	 * @return Category
	 */
	public function getParent()
	{
		return $this->parent;
	}


	/**
	 * @return string
	 */
	public function getPath()
	{
		return $this->path;
	}

}

And it's repository:

namespace App\Model;

use Gedmo\Tree\Entity\Repository\MaterializedPathRepository;


class CategoryTree extends MaterializedPathRepository
{

}