mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix validation groups and sequential validator msg
This commit is contained in:
parent
b2c1d75fc5
commit
41617295c1
@ -1209,6 +1209,20 @@ class Person implements HasCenterInterface
|
||||
return $this->householdParticipations;
|
||||
}
|
||||
|
||||
public function getHouseholdParticipationsShareHousehold(): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where(
|
||||
$expr->eq('shareHousehold', true)
|
||||
);
|
||||
|
||||
return $this->getHouseholdParticipations()
|
||||
->matching($criteria)
|
||||
;
|
||||
}
|
||||
|
||||
public function getCurrentHousehold(?\DateTimeImmutable $at = null): ?Household
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
|
@ -19,6 +19,8 @@ class MembersEditor
|
||||
private array $persistables = [];
|
||||
private array $membershipsAffected = [];
|
||||
|
||||
public const VALIDATION_GROUP = 'household_memberships';
|
||||
|
||||
public function __construct(ValidatorInterface $validator, ?Household $household)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
@ -41,12 +43,12 @@ class MembersEditor
|
||||
$this->household->addMember($membership);
|
||||
|
||||
if ($position->getShareHousehold()) {
|
||||
foreach ($person->getHouseholdParticipations() as $participation) {
|
||||
if (FALSE === $participation->getShareHousehold()) {
|
||||
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
||||
if ($participation === $membership) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($participation === $membership) {
|
||||
if ($participation->getStartDate() > $membership->getStartDate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -92,7 +94,13 @@ class MembersEditor
|
||||
|
||||
public function validate(): ConstraintViolationListInterface
|
||||
{
|
||||
return $this->validator->validate($this->getHousehold(), null, [ "memberships" ]);
|
||||
$list = $this->validator->validate($this->getHousehold(), null, [ self::VALIDATION_GROUP ]);
|
||||
|
||||
foreach ($this->membershipsAffected as $m) {
|
||||
$list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP ]));
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getPersistable(): array
|
||||
|
@ -29,7 +29,7 @@ class HouseholdMembershipSequentialValidator extends ConstraintValidator
|
||||
throw new UnexpectedTypeException($constraint, Person::class);
|
||||
}
|
||||
|
||||
$participations = $person->getHouseholdParticipations();
|
||||
$participations = $person->getHouseholdParticipationsShareHousehold();
|
||||
|
||||
if ($participations->count() === 0) {
|
||||
return;
|
||||
@ -47,6 +47,7 @@ class HouseholdMembershipSequentialValidator extends ConstraintValidator
|
||||
if ($covers->hasIntersections()) {
|
||||
foreach ($covers->getIntersections() as list($start, $end, $metadata)) {
|
||||
$participation = $participations[$metadata[0]];
|
||||
$nbHousehold = count($metadata);
|
||||
|
||||
$this->context
|
||||
->buildViolation("household_membership.Person with membership covering")
|
||||
@ -55,7 +56,9 @@ class HouseholdMembershipSequentialValidator extends ConstraintValidator
|
||||
$participation->getPerson(), []
|
||||
),
|
||||
// TODO when date is correctly i18n, fix this
|
||||
'%from%' => $start->format('d-m-Y')
|
||||
'%from%' => $start->format('d-m-Y'),
|
||||
'%nbHousehold%' => $nbHousehold,
|
||||
|
||||
])
|
||||
->addViolation()
|
||||
;
|
||||
|
@ -40,4 +40,4 @@ household:
|
||||
max_holder_overflowed: Il ne peut y avoir plus de deux titulaires simultanément. Or, avec cette modification, ce nombre sera dépassé entre le {{ start }} et le {{ end }}.
|
||||
household_membership:
|
||||
The end date must be after start date: La date de la fin de l'appartenance doit être postérieure à la date de début.
|
||||
Person with membership covering: Une personne ne peut pas appartenir à deux ménages simultanément. Or, avec cette modification, %person_name% appartiendrait à deux ménages à partir du %from%.
|
||||
Person with membership covering: Une personne ne peut pas appartenir à deux ménages simultanément. Or, avec cette modification, %person_name% appartiendrait à %nbHousehold% ménages à partir du %from%.
|
||||
|
Loading…
x
Reference in New Issue
Block a user