Was looking at your code in CategorizerBundle, in particular the updateAction() in CategoryController.
I haven't tried it out (mainly because I am still on Symfony2.0 and there is a 2.1 dependancy, as per
https://github.com/Sylius/SyliusCategorizerBundle/issues/6), but it appears the code doesn't prevent assigning a category's parent fto itself or even to a node in it's own subtree (which would be a logical inconsistency).
Is this correct?
If so, you may want to have a look at the editAction() in this categoryController:
https://github.com/l3pp4rd/gediminasm.org/blob/master/src/Gedmo/DemoBundle/Controller/CategoryController.phpYou'll see the
CategoryEntityLoader seems to what we need with it's query. The main part of the query is in the getEntities() function. In the code below, $this->basedOnNode
is the node being edited. In your updateAction() it would be the equivalent of your $category variable.
public function getEntities()
{
$qb = $this->em
->createQueryBuilder()
->select('c')
->from('GedmoDemoBundle:Category', 'c')
;
if (!is_null($this->basedOnNode)) {
$qb->where($qb->expr()->notIn(
'c.id',
$this->em
->createQueryBuilder()
->select('n')
->from('GedmoDemoBundle:Category', 'n')
->where('n.root = '.$this->basedOnNode->getRoot())
->andWhere($qb->expr()->between(
'n.lft',
$this->basedOnNode->getLeft(),
$this->basedOnNode->getRight()
))
->getDQL()
));
}
$q = $qb->getQuery();
$this->categoryController->setTranslatableHints($q);
return $q->getResult();
}
You may want to implement a similiar query in your categorizer bundle (and perhaps open the possibility of removing the Symfony 2.1 dependancy while you're at it).
Hope this helps.