From 8275715b5648df345aca0c958764425233410042 Mon Sep 17 00:00:00 2001 From: Tchama Date: Mon, 21 Oct 2019 13:04:22 +0200 Subject: [PATCH] Sort collection of participations by firstname in Event entity --- Entity/Event.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Entity/Event.php b/Entity/Event.php index 87cc9bab1..acafc5ae3 100644 --- a/Entity/Event.php +++ b/Entity/Event.php @@ -4,7 +4,6 @@ namespace Chill\EventBundle\Entity; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\HasScopeInterface; -use Doctrine\ORM\Mapping as ORM; /** * Event @@ -215,11 +214,28 @@ class Event implements HasCenterInterface, HasScopeInterface /** * Get participations * - * @return \Doctrine\Common\Collections\Collection + * @return \ArrayIterator|\Doctrine\Common\Collections\Collection|\Traversable */ public function getParticipations() { - return $this->participations; + return $this->getParticipationsOrdered(); + } + + /** + * Sort Collection of Participations + * + * @return \ArrayIterator|\Traversable + */ + public function getParticipationsOrdered() { + + $iterator = $this->participations->getIterator(); + + $iterator->uasort(function($first, $second) + { + return strnatcasecmp($first->getPerson()->getFirstName(), $second->getPerson()->getFirstName()); + }); + + return $iterator; } /**