mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-17 15:54:23 +00:00
54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Controller;
|
|
|
|
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\Repository\Household\HouseholdRepository;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
|
|
class HouseholdApiController extends ApiController
|
|
{
|
|
private HouseholdRepository $householdRepository;
|
|
|
|
public function __construct(HouseholdRepository $householdRepository)
|
|
{
|
|
$this->householdRepository = $householdRepository;
|
|
}
|
|
|
|
|
|
public function householdAddressApi($id, Request $request, string $_format): Response
|
|
{
|
|
return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, [ 'groups' => [ 'read' ] ]);
|
|
}
|
|
|
|
/**
|
|
* Find Household of people participating to the same AccompanyingPeriod
|
|
*
|
|
* @ParamConverter("person", options={"id" = "person_id"})
|
|
*/
|
|
public function suggestHouseholdByAccompanyingPeriodParticipationApi(Person $person, string $_format)
|
|
{
|
|
// TODO add acl
|
|
|
|
$count = $this->householdRepository->countByAccompanyingPeriodParticipation($person);
|
|
$paginator = $this->getPaginatorFactory()->create($count);
|
|
|
|
if ($count === 0) {
|
|
$households = [];
|
|
} else {
|
|
$households = $this->householdRepository->findByAccompanyingPeriodParticipation($person,
|
|
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
|
}
|
|
|
|
$collection = new Collection($households, $paginator);
|
|
|
|
return $this->json($collection, Response::HTTP_OK, [],
|
|
[ "groups" => ["read"]]);
|
|
}
|
|
}
|