show members without position in list

This commit is contained in:
2021-10-30 02:08:31 +02:00
parent 576ee49da0
commit e9d20a56ff
6 changed files with 128 additions and 72 deletions

View File

@@ -19,15 +19,17 @@ class MembersEditor
private array $persistables = [];
private array $membershipsAffected = [];
private array $oldMembershipsHashes = [];
public const VALIDATION_GROUP = 'household_memberships';
public const VALIDATION_GROUP_CREATED = 'household_memberships_created';
public const VALIDATION_GROUP_AFFECTED = 'household_memberships';
public function __construct(ValidatorInterface $validator, ?Household $household)
{
$this->validator = $validator;
$this->household = $household;
}
public function addMovement(\DateTimeImmutable $date, Person $person, Position $position, ?bool $holder = false, ?string $comment = null): self
{
if (NULL === $this->household) {
@@ -56,6 +58,7 @@ class MembersEditor
if ($participation->getEndDate() === NULL || $participation->getEndDate() > $date) {
$participation->setEndDate($date);
$this->membershipsAffected[] = $participation;
$this->oldMembershipsHashes[] = \spl_object_hash($participation);
}
}
}
@@ -97,13 +100,18 @@ class MembersEditor
{
if ($this->hasHousehold()) {
$list = $this->validator
->validate($this->getHousehold(), null, [ self::VALIDATION_GROUP ]);
->validate($this->getHousehold(), null, [ self::VALIDATION_GROUP_AFFECTED ]);
} else {
$list = new ConstraintViolationList();
}
foreach ($this->membershipsAffected as $m) {
$list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP ]));
if (\in_array(\spl_object_hash($m), $this->oldMembershipsHashes)) {
$list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP_AFFECTED ]));
} else {
$list->addAll($this->validator->validate($m, null, [ self::VALIDATION_GROUP_CREATED,
self::VALIDATION_GROUP_AFFECTED ]));
}
}
return $list;