Witajcie, chciałbym się podzielić czymś co mi całkiem fajnie wyszło (bo działa ;) ) a w google podobnych rozwiązań znaleźć nie mogłem, to też liczę na krytykę i wskazania prawidłowego zapisu sortowania kolekcji wg pozycji, nie wiem czy powinno się to robić po stronie TWIGA ale dla mnie wygodniej było w encji :)
patrz getChildren()
//..
/**
* @O\OneToMany(targetEntity="BlogBundle\Entity\Group", mappedBy="parent")
*/
private $children;
/**
* @O\ManyToOne(targetEntity="BlogBundle\Entity\Group", inversedBy="children")
*/
private $parent;
//...
/**
* @O\Column(type="integer")
*/
private $position;
/**
* Constructor
*/
public function __construct()
{
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
//...
}
//....
/**
* Get children
*
* @return array
*/
function cmp($a, $b)
{
return strcmp($a->getPosition(), $b->getPosition());
}
public function getChildren()
{
$ar = [];
foreach($this->children as $child){
array_push($ar,$child);
}
usort($ar, array($this, "cmp"));
return $ar;
}
//...