i am currently developing a content management system with symfony and symfony cmf. i am trying to implement a sorting functionality for some nodes that are belonging to a user.
What i've figured out so far is that the nodes had to be placed in the same depth to be correctly sorted and that the elements, which are found by the documentManager, are sorted from the lowest sort_order to the highest.
What i can't figure out currently is, how the hell do i set the sort_order? The AbstractBlock class was having two Methods setPosition and getPosition, but setPosition isn't implemented at all. It's just a comment with a TODO and a return $this statement.
So did anyone in here already managed to implement a sorting functionality with Symfony CMF? If so, please let me how i can do so.
Sharpy35
The default storage of the CMF that you are aparently using is Doctrine PHPCR-ODM. It builds in turn on PHPCR, which is a tree structured database. Children of a specific node are custom ordered. By default, nodes are appended at the end of the list of children.
When working with PHPCR / PHPCR-ODM, you should not need to interact with the database directly, jackalope-doctrine-dbal does that for you. If you want to know what is going on, better read the documentation on the PHPCR API than trying to read information from the database ;-)
There are 3 things you can do
In PHPCR-ODM: If you have a children collection mapped to a field, you can reorder elements in that collection. For example:
$collection = $myDocument->getChildren(); $collection->clear(); foreach ($mySortedItems as $key => $item) { $collection[$key] = $item; }
In PHPCR: Use the Node::orderBefore method to reorder children. You can use the DocumentManager::getNodeForDocument
method to get the PHPCR node you need for this.