views:

225

answers:

1

What is the best way to add a sense of order in Doctrine Nested Sets?

The documention contains several examples of how to get al the childeren of a specific node

$category->getNode()->getSiblings()

But how can I for example:

  • change the position of the fourth sibling to the second position
  • get only the second sibling
  • add a sibling between the second and third child etc...

Do I have to manually add and ordercolumn to the model to do these operations?

+1  A: 

To get the second previous sibling:

$anotherCategory = $category->getNode()->getPrevSibling()->getNode()->getPrevSibling();

To insert category in its place:

$category->getNode()->moveAsPrevSiblingOf($anotherCategory);

To add a new sibling between second and third child, you'd simply use insertAsNextSiblingOf instead of moveAsPrevSiblingOf.

reko_t