mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
backend: allow to remove people from household, or move to a new household
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Chill\PersonBundle\Household;
|
||||
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
@@ -13,12 +14,12 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
class MembersEditor
|
||||
{
|
||||
private ValidatorInterface $validator;
|
||||
private Household $household;
|
||||
private ?Household $household = null;
|
||||
|
||||
private array $persistables = [];
|
||||
private array $membershipsAffected = [];
|
||||
|
||||
public function __construct(ValidatorInterface $validator, Household $household)
|
||||
public function __construct(ValidatorInterface $validator, ?Household $household)
|
||||
{
|
||||
$this->validation = $validator;
|
||||
$this->household = $household;
|
||||
@@ -62,6 +63,33 @@ class MembersEditor
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function leaveMovement(
|
||||
\DateTimeImmutable $date,
|
||||
Person $person
|
||||
): self {
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where(
|
||||
$expr->andX(
|
||||
$expr->lt('startDate', $date),
|
||||
$expr->isNull('endDate', $date)
|
||||
)
|
||||
);
|
||||
|
||||
$participations = $person->getHouseholdParticipations()
|
||||
->matching($criteria)
|
||||
;
|
||||
|
||||
foreach ($participations as $participation) {
|
||||
$participation->setEndDate($date);
|
||||
$this->membershipsAffected[] = $participation;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function validate(): ConstraintViolationListInterface
|
||||
{
|
||||
|
||||
@@ -72,8 +100,13 @@ class MembersEditor
|
||||
return $this->persistables;
|
||||
}
|
||||
|
||||
public function getHousehold(): Household
|
||||
public function getHousehold(): ?Household
|
||||
{
|
||||
return $this->household;
|
||||
}
|
||||
|
||||
public function hasHousehold(): bool
|
||||
{
|
||||
return $this->household !== null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user