doctrine-extensions / DoctrineExtensions

Doctrine2 behavioral extensions, Translatable, Sluggable, Tree-NestedSet, Timestampable, Loggable, Sortable
MIT License
4.03k stars 1.27k forks source link

ODM\MongoDB TreeListener does not support tree type: nested #1314

Closed houssemeddinear closed 2 years ago

houssemeddinear commented 9 years ago

i work with mongodb database , nested strategy for Tree dont work !

it show this exception : ODM\MongoDB TreeListener does not support tree type: nested

this is my service configuration

gedmo.listener.tree:
        class: Gedmo\Tree\TreeListener
        tags:
            # ODM MongoDb subscriber, where **default** is manager name
            - { name: doctrine_mongodb.odm.event_subscriber }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

and this is my entity

<?php

namespace Application\MainBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ODM\Document(repositoryClass="Application\MainBundle\Document\CategoryRepository", collection="Categories")
 * @Gedmo\Tree(type="nested")
 */
class Category implements \Gedmo\Tree\Node
{
    use \Gedmo\Blameable\Traits\BlameableDocument;
    use \Gedmo\Timestampable\Traits\TimestampableDocument;

    /**
     * @var string 
     * @ODM\Id
     */
    protected $id;

    /**
     * @var string name
     * @ODM\String
     * @Assert\NotBlank
     * @Assert\Length(max = 255)
     * @Gedmo\TreePathSource
     * @Gedmo\Translatable
     */
    protected $name;

    /**
     * @var int 
     * @ODM\Int
     */
    protected $sortOrder;

    /**
     * @var boolean Активна ли категория
     * @ODM\Boolean
     */
    protected $isActive;

    /**
     * @var \Application\MainBundle\Document\Category Родительская категория
     * @ODM\ReferenceOne(targetDocument="\Application\MainBundle\Document\Category", nullable=true)
     * @Gedmo\TreeParent
     */
    protected $parent;

    /**
     * @Gedmo\TreeLeft
     * @ODM\Int
     */
    private $lft;

    /**
     * @Gedmo\TreeRight
     * @ODM\Int
     */
    private $rgt;

    /**
     * @Gedmo\TreeRoot
     * @ODM\Int(name="root", nullable=true)
     */
    private $root;

    /**
     *
     * @ODM\ReferenceMany(targetDocument="\Application\MainBundle\Document\Category", sort= {"lft" : "ASC"} )
     */
    private $children;

    /**
     * @var string path
     * @ODM\String
     * @Gedmo\TreePath(separator="|")
     */
    protected $path;

    /**
     * @var int level
     * @ODM\Int
     * @Gedmo\TreeLevel
     */
    protected $level;

    /**
     * @var \DateTime Время блокировки
     * @ODM\Date
     * @Gedmo\TreeLockTime
     */
    protected $lockTime;

     /**
     * @var int colonne
     * @ODM\Int
     */
    protected $column;

    /**
     * 
     * @return string
     */
    public function __toString()
    {
        $prefix   = ($this->level > 1)
            ? str_repeat('&nbsp;&nbsp;', $this->level)
            : '';

        return (string) html_entity_decode($prefix) . $this->name;
    }

    /**
     * 
     * @return string
     */
    public function getTreeName()
    {
        $prefix   = ($this->level > 1)
            ? str_repeat('&nbsp;&nbsp;', $this->level)
            : '';

        return (string) html_entity_decode($prefix) . $this->name;
    }

    public function __construct()
    {
        $this->children = new ArrayCollection();
    }

    /**
     * Get id
     * @return string $id
     */
    public function getId()
    {
        return $this->id;
    }

    function getLft() {
        return $this->lft;
    }

    function getRgt() {
        return $this->rgt;
    }

    function getRoot() {
        return $this->root;
    }

    function getChildren() {
        return $this->children;
    }

    function setLft($lft) {
        $this->lft = $lft;
        return $this;
    }

    function setRgt($rgt) {
        $this->rgt = $rgt;
        return $this;
    }

    function setRoot($root) {
        $this->root = $root;
        return $this;
    }

    function setChildren($children) {
        $this->children = $children;
        return $this;
    }

    /**
     * Set column
     * @param int $column
     * @return self
     */
    public function setColumn($column)
    {
        $this->column = $column;
        return $this;
    }

    /**
     * Get column
     * @return int $column
     */
    public function getColumn()
    {
        return $this->column;
    }

    /**
     * Set name
     * @param string $name
     * @return self
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }

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

    /**
     * Set sortOrder
     * @param int $sortOrder
     * @return self
     */
    public function setSortOrder($sortOrder)
    {
        $this->sortOrder = $sortOrder;
        return $this;
    }

    /**
     * Get sortOrder
     * @return int $sortOrder
     */
    public function getSortOrder()
    {
        return $this->sortOrder;
    }

    /**
     * Set isActive
     * @param boolean $isActive
     * @return self
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;
        return $this;
    }

    /**
     * Get isActive
     * @return boolean $isActive
     */
    public function getIsActive()
    {
        return $this->isActive;
    }

    /**
     * Set parent
     * @param \Application\MainBundle\Document\Category $parent
     * @return self
     */
    public function setParent($parent)
    {
        $this->parent = $parent;
        return $this;
    }

    /**
     * Get parent
     * @return \Application\MainBundle\Document\Category $parent
     */
    public function getParent()
    {
        return $this->parent;
    }

    /**
     * Remove parent
     * @return self
     */
    public function removeParent()
    {
        $this->parent = null;
        return $this;
    }

    /**
     * Set path
     * @param string $path
     * @return self
     */
    public function setPath($path)
    {
        $this->path = $path;
        return $this;
    }

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

    /**
     * Set level
     * @param int $level
     * @return self
     */
    public function setLevel($level)
    {
        $this->level = $level;
        return $this;
    }

    /**
     * Get level
     * @return int $level
     */
    public function getLevel()
    {
        return $this->level;
    }

    /**
     * Set lockTime
     * @param \DateTime $lockTime
     * @return self
     */
    public function setLockTime($lockTime)
    {
        $this->lockTime = $lockTime;
        return $this;
    }

    /**
     * Get lockTime
     * @return \DateTime $lockTime
     */
    public function getLockTime()
    {
        return $this->lockTime;
    }

}
sgasser commented 9 years ago

For MongoDB only "Materialized Path strategy" is supported.

 * @Gedmo\Tree(type="materializedPath")
github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.