mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch 'features/add-suggestion-household-member-editor' into 'master'
Add suggestion household member editor See merge request Chill-Projet/chill-bundles!97
This commit is contained in:
@@ -4,15 +4,50 @@ 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"]]);
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
@@ -25,11 +26,17 @@ class HouseholdMemberController extends ApiController
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private AccompanyingPeriodRepository $periodRepository;
|
||||
|
||||
public function __construct(UrlGeneratorInterface $generator, TranslatorInterface $translator)
|
||||
public function __construct(
|
||||
UrlGeneratorInterface $generator,
|
||||
TranslatorInterface $translator,
|
||||
AccompanyingPeriodRepository $periodRepository
|
||||
)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
$this->translator = $translator;
|
||||
$this->periodRepository = $periodRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,8 +151,23 @@ class HouseholdMemberController extends ApiController
|
||||
'allowLeaveWithoutHousehold' => $allowLeaveWithoutHousehold ?? $request->query->has('allow_leave_without_household'),
|
||||
];
|
||||
|
||||
// context
|
||||
if ($request->query->has('accompanying_period_id')) {
|
||||
$period = $this->periodRepository->find(
|
||||
$request->query->getInt('accompanying_period_id')
|
||||
);
|
||||
|
||||
if ($period === null) {
|
||||
throw $this->createNotFoundException('period not found');
|
||||
}
|
||||
|
||||
// TODO add acl on accompanying Course
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/Household/members_editor.html.twig', [
|
||||
'data' => $data
|
||||
'data' => $data,
|
||||
'expandSuggestions' => (int) $request->query->getBoolean('expand_suggestions', false),
|
||||
'accompanyingCourse' => $period ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user