From 3417aa8207963cd7eae4b88bf09fc7fb9211fef3 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 15 Nov 2021 12:00:42 +0100 Subject: [PATCH] person: do not suggest the current household of the person --- .../Controller/HouseholdApiController.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php index 11e41ba29..3f3e04cb3 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php @@ -47,13 +47,22 @@ class HouseholdApiController extends ApiController $count = $this->householdRepository->countByAccompanyingPeriodParticipation($person); $paginator = $this->getPaginatorFactory()->create($count); - if ($count === 0) { - $households = []; - } else { - $households = $this->householdRepository->findByAccompanyingPeriodParticipation($person, + $households = []; + if ($count !== 0) { + $allHouseholds = $this->householdRepository->findByAccompanyingPeriodParticipation($person, $paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber()); - } + $currentHouseholdPerson = $person->getCurrentHousehold(); + foreach ($allHouseholds as $h) { + if ($h !== $currentHouseholdPerson) { + array_push($households, $h); + } + } + if (null !== $currentHouseholdPerson) { + $count = $count - 1; + $paginator = $this->getPaginatorFactory()->create($count); + } + } $collection = new Collection($households, $paginator); return $this->json($collection, Response::HTTP_OK, [],