mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Merge remote-tracking branch 'origin/master' into features/sql-vue-from-household-address-to-person
This commit is contained in:
@@ -11,6 +11,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
@@ -20,6 +22,7 @@ use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "household"=Household::class
|
||||
* })
|
||||
* @MaxHolder(groups={"household_memberships"})
|
||||
*/
|
||||
class Household
|
||||
{
|
||||
@@ -52,10 +55,26 @@ class Household
|
||||
*/
|
||||
private Collection $members;
|
||||
|
||||
/**
|
||||
* @ORM\Embedded(class=CommentEmbeddable::class, columnPrefix="comment_members_")
|
||||
*/
|
||||
private CommentEmbeddable $commentMembers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false})
|
||||
*/
|
||||
private bool $waitingForBirth = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", name="waiting_for_birth_date", nullable=true, options={"default": null})
|
||||
*/
|
||||
private ?\DateTimeImmutable $waitingForBirthDate = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->addresses = new ArrayCollection();
|
||||
$this->members = new ArrayCollection();
|
||||
$this->commentMembers = new CommentEmbeddable();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -129,6 +148,53 @@ class Household
|
||||
return $this->members;
|
||||
}
|
||||
|
||||
public function getMembersOnRange(\DateTimeImmutable $from, ?\DateTimeImmutable $to): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where(
|
||||
$expr->gte('startDate', $from)
|
||||
);
|
||||
|
||||
if (NULL !== $to) {
|
||||
$criteria->andWhere(
|
||||
$expr->orX(
|
||||
$expr->lte('endDate', $to),
|
||||
$expr->eq('endDate', NULL)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->getMembers()
|
||||
->matching($criteria)
|
||||
;
|
||||
}
|
||||
|
||||
public function getMembersDuringMembership(HouseholdMember $membership)
|
||||
{
|
||||
return $this->getMembersOnRange(
|
||||
$membership->getStartDate(),
|
||||
$membership->getEndDate()
|
||||
)->filter(
|
||||
function(HouseholdMember $m) use ($membership) {
|
||||
return $m !== $membership;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function getMembersHolder(): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where(
|
||||
$expr->eq('holder', true)
|
||||
);
|
||||
|
||||
return $this->getMembers()->matching($criteria);
|
||||
}
|
||||
|
||||
public function getCurrentMembers(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
@@ -223,6 +289,42 @@ class Household
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommentMembers(): CommentEmbeddable
|
||||
{
|
||||
return $this->commentMembers;
|
||||
}
|
||||
|
||||
public function setCommentMembers(CommentEmbeddable $commentMembers): self
|
||||
{
|
||||
$this->commentMembers = $commentMembers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWaitingForBirth(): bool
|
||||
{
|
||||
return $this->waitingForBirth;
|
||||
}
|
||||
|
||||
public function setWaitingForBirth(bool $waitingForBirth): self
|
||||
{
|
||||
$this->waitingForBirth = $waitingForBirth;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWaitingForBirthDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->waitingForBirthDate;
|
||||
}
|
||||
|
||||
public function setWaitingForBirthDate(?\DateTimeImmutable $waitingForBirthDate): self
|
||||
{
|
||||
$this->waitingForBirthDate = $waitingForBirthDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function validate(ExecutionContextInterface $context, $payload)
|
||||
{
|
||||
$addresses = $this->getAddresses();
|
||||
@@ -236,7 +338,5 @@ class Household
|
||||
}
|
||||
}
|
||||
dump($cond);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user