Gedmo Tree could be used for example with Projects and sub-products and so on. But i've an situation where i have a connection table between Products and Categories (ManytoMany).
Each product could be connected through many Categories. And each Category could have many Products. In my product view there is an option to connect multiple categories.
The problem i have is a bit difficult to explain. I've a view with all categories where a category could have sub categories.
cat1 (show products)
1.1 cat1-1 (show products)
1.2 cat1-2 (show products)
Each categorie, even sub categories haves a link, that opens a new page with all theire connected products. I need to find a way to sort these products based on theire category, what i'm trying to do with Gedmo Tree.
See entity below which is the connection entitiy.
The problem is that Gedmo doesn't distinct the category where you in. It just continues with counting the lft and rgt.
I hope i've discribe my problem cleary and that somebody have an sollution.
Maybe i could use Gedmo treeRoot? But don't know where treeRoot could be used for
<?php
/**
* ProductCategory
*/
namespace XBS\AppBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ProductCategory
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductCategoryRepository")
* @Gedmo\Tree(type="nested")
* ...
*/
class ProductCategory
{
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Product", inversedBy="productCategories")
* @Assert\NotNull()
*/
protected $product;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Category", inversedBy="productCategories")
* @Assert\NotNull()
*/
protected $category;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Category", inversedBy="children" )
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Category", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
*/
protected $children;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* setProduct
*
* @param null $product
* @return $this
*/
public function setProduct($product = null)
{
$this->product = $product;
return $this;
}
/**
* getProduct
* @return mixed
*/
public function getProduct()
{
return $this->product;
}
/**
* setCategory
*
* @param null $category
* @return $this
*/
public function setCategory($category = null)
{
$this->category = $category;
return $this;
}
/**
* getCategory
* @return mixed
*/
public function getCategory()
{
return $this->category;
}
/**
* @return String empty
*/
public function __toString(){
return '';
}
}