mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add address suggestion by household
This commit is contained in:
@@ -6,10 +6,12 @@ use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Repository\Household\HouseholdRepository;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class HouseholdApiController extends ApiController
|
||||
{
|
||||
@@ -50,4 +52,45 @@ class HouseholdApiController extends ApiController
|
||||
return $this->json($collection, Response::HTTP_OK, [],
|
||||
[ "groups" => ["read"]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/address/suggest/by-household/{household_id}.{_format}",
|
||||
* name="chill_person_address_suggest_by_household",
|
||||
* requirements={
|
||||
* "_format"="json"
|
||||
* }
|
||||
* )
|
||||
* @ParamConverter("household", options={"id" = "household_id"})
|
||||
*/
|
||||
public function suggestAddressByHousehold(Household $household, string $_format)
|
||||
{
|
||||
// TODO add acl
|
||||
|
||||
$addresses = [];
|
||||
// collect addresses from location in courses
|
||||
foreach ($household->getCurrentPersons() as $person) {
|
||||
foreach ($person->getAccompanyingPeriodParticipations() as $participation) {
|
||||
if (null !== $participation->getAccompanyingPeriod()->getAddressLocation()) {
|
||||
$a = $participation->getAccompanyingPeriod()->getAddressLocation();
|
||||
$addresses[$a->getId()] = $a;
|
||||
}
|
||||
if (null !== $personLocation = $participation
|
||||
->getAccompanyingPeriod()->getPersonLocation()) {
|
||||
$a = $personLocation->getCurrentHouseholdAddress();
|
||||
if (null !== $a) {
|
||||
$addresses[$a->getId()] = $a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove the actual address
|
||||
$actual = $household->getCurrentAddress();
|
||||
if (null !== $actual) {
|
||||
$addresses = \array_filter($addresses, fn($a) => $a !== $actual);
|
||||
}
|
||||
|
||||
return $this->json(\array_values($addresses), Response::HTTP_OK, [],
|
||||
[ 'groups' => [ 'read' ] ]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user