mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
cs: Use Collection
more and fix potential duplicates.
This commit is contained in:
parent
bcd25fa950
commit
33913867ee
@ -22,6 +22,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use function in_array;
|
||||
|
||||
class PersonApiController extends ApiController
|
||||
{
|
||||
@ -79,6 +80,8 @@ class PersonApiController extends ApiController
|
||||
{
|
||||
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
|
||||
|
||||
$seenAddressIds = [];
|
||||
|
||||
// collect addresses from location in courses
|
||||
$addresses = $person
|
||||
->getAccompanyingPeriodParticipations()
|
||||
@ -91,13 +94,30 @@ class PersonApiController extends ApiController
|
||||
static function (AccompanyingPeriodParticipation $accompanyingPeriodParticipation): ?Address {
|
||||
return $accompanyingPeriodParticipation->getAccompanyingPeriod()->getAddressLocation();
|
||||
}
|
||||
)
|
||||
->filter(
|
||||
// We remove potential null addresses.
|
||||
static fn (?Address $address): bool => null !== $address
|
||||
)
|
||||
->filter(
|
||||
static function (Address $address) use (&$seenAddressIds): bool {
|
||||
$id = $address->getId();
|
||||
|
||||
if (in_array($id, $seenAddressIds, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$seenAddressIds[] = $id;
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
// remove the actual address
|
||||
$actual = $person->getCurrentHouseholdAddress();
|
||||
|
||||
if (null !== $actual) {
|
||||
$addresses = $addresses->filter(static fn (?Address $address): bool => $address !== $actual);
|
||||
$addresses = $addresses->filter(static fn (Address $address): bool => $address !== $actual);
|
||||
}
|
||||
|
||||
return $this->json(
|
||||
|
Loading…
x
Reference in New Issue
Block a user