mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,31 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Entity\Household;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
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
|
||||
* @ORM\Table(
|
||||
* name="chill_person_household"
|
||||
* )
|
||||
* name="chill_person_household"
|
||||
* )
|
||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "household"=Household::class
|
||||
* "household": Household::class
|
||||
* })
|
||||
* @MaxHolder(groups={"household_memberships"})
|
||||
*/
|
||||
class Household
|
||||
{
|
||||
/**
|
||||
* Addresses.
|
||||
*
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Chill\MainBundle\Entity\Address",
|
||||
* cascade={"persist", "remove", "merge", "detach"})
|
||||
* @ORM\JoinTable(name="chill_person_household_to_addresses")
|
||||
* @ORM\OrderBy({"validFrom": "DESC", "id": "DESC"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private Collection $addresses;
|
||||
|
||||
/**
|
||||
* @ORM\Embedded(class=CommentEmbeddable::class, columnPrefix="comment_members_")
|
||||
*/
|
||||
private CommentEmbeddable $commentMembers;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
@@ -34,32 +60,15 @@ class Household
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* Addresses
|
||||
*
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Chill\MainBundle\Entity\Address",
|
||||
* cascade={"persist", "remove", "merge", "detach"})
|
||||
* @ORM\JoinTable(name="chill_person_household_to_addresses")
|
||||
* @ORM\OrderBy({"validFrom" = "DESC", "id" = "DESC"})
|
||||
* @Serializer\Groups({"write"})
|
||||
*/
|
||||
private Collection $addresses;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity=HouseholdMember::class,
|
||||
* mappedBy="household"
|
||||
* )
|
||||
* targetEntity=HouseholdMember::class,
|
||||
* mappedBy="household"
|
||||
* )
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
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})
|
||||
*/
|
||||
@@ -68,7 +77,7 @@ class Household
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", name="waiting_for_birth_date", nullable=true, options={"default": null})
|
||||
*/
|
||||
private ?\DateTimeImmutable $waitingForBirthDate = null;
|
||||
private ?DateTimeImmutable $waitingForBirthDate = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -77,19 +86,13 @@ class Household
|
||||
$this->commentMembers = new CommentEmbeddable();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address $address
|
||||
* @return $this
|
||||
*/
|
||||
public function addAddress(Address $address)
|
||||
{
|
||||
foreach ($this->getAddresses() as $a) {
|
||||
if ($a->getValidFrom() < $address->getValidFrom() && $a->getValidTo() === NULL) {
|
||||
if ($a->getValidFrom() < $address->getValidFrom() && $a->getValidTo() === null) {
|
||||
$a->setValidTo($address->getValidFrom());
|
||||
}
|
||||
}
|
||||
@@ -99,35 +102,22 @@ class Household
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force an address starting at the current day
|
||||
* on the Household.
|
||||
*
|
||||
* This will force the startDate's address on today.
|
||||
*
|
||||
* Used on household creation.
|
||||
*
|
||||
* @Serializer\Groups({"create"})
|
||||
*/
|
||||
public function setForceAddress(Address $address)
|
||||
public function addMember(HouseholdMember $member): self
|
||||
{
|
||||
$address->setValidFrom(new \DateTime('today'));
|
||||
$this->addAddress($address);
|
||||
}
|
||||
if (!$this->members->contains($member)) {
|
||||
$this->members[] = $member;
|
||||
$member->setHousehold($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address $address
|
||||
*/
|
||||
public function removeAddress(Address $address)
|
||||
{
|
||||
$this->addresses->removeElement($address);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, the addresses are ordered by date, descending (the most
|
||||
* recent first)
|
||||
* recent first).
|
||||
*
|
||||
* @Assert\Callback(methods={"validate"})
|
||||
*
|
||||
* @return \Chill\MainBundle\Entity\Address[]
|
||||
*/
|
||||
public function getAddresses()
|
||||
@@ -135,25 +125,131 @@ class Household
|
||||
return $this->addresses;
|
||||
}
|
||||
|
||||
public function getCommentMembers(): CommentEmbeddable
|
||||
{
|
||||
return $this->commentMembers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Serializer\Groups({ "read" })
|
||||
* @Serializer\SerializedName("current_address")
|
||||
*/
|
||||
public function getCurrentAddress(\DateTime $at = null): ?Address
|
||||
public function getCurrentAddress(?DateTime $at = null): ?Address
|
||||
{
|
||||
$at = $at === null ? new \DateTime('today') : $at;
|
||||
$at = null === $at ? new DateTime('today') : $at;
|
||||
|
||||
$addrs = $this->getAddresses()->filter(function (Address $a) use ($at) {
|
||||
return $a->getValidFrom() <= $at && (
|
||||
NULL === $a->getValidTo() || $at < $a->getValidTo()
|
||||
null === $a->getValidTo() || $a->getValidTo() > $at
|
||||
);
|
||||
});
|
||||
|
||||
if ($addrs->count() > 0) {
|
||||
return $addrs->first();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCurrentMembers(?DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getMembers()->matching($this->buildCriteriaCurrentMembers($now));
|
||||
}
|
||||
|
||||
public function getCurrentMembersByPosition(Position $position, ?DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where($expr->eq('position', $position));
|
||||
|
||||
return $this->getCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* get current members ids.
|
||||
*
|
||||
* Used in serialization
|
||||
*
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\SerializedName("current_members_id")
|
||||
*/
|
||||
public function getCurrentMembersIds(?DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getCurrentMembers($now)->map(
|
||||
fn (HouseholdMember $m) => $m->getId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HouseholdMember[]
|
||||
*/
|
||||
public function getCurrentMembersOrdered(?DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
$members = $this->getCurrentMembers($now);
|
||||
|
||||
$members->getIterator()
|
||||
->uasort(
|
||||
function (HouseholdMember $a, HouseholdMember $b) {
|
||||
if ($a->getPosition() === null) {
|
||||
if ($b->getPosition() === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
} elseif ($b->getPosition() === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($a->getPosition()->getOrdering() < $b->getPosition()->getOrdering()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($a->getPosition()->getOrdering() > $b->getPosition()->getOrdering()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($a->isHolder() && !$b->isHolder()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!$a->isHolder() && $b->isHolder()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
return $members;
|
||||
}
|
||||
|
||||
public function getCurrentMembersWithoutPosition(?DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where($expr->isNull('position'));
|
||||
|
||||
return $this->getCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the persons currently associated to the household.
|
||||
*
|
||||
* Return a list of Person, instead of a list of HouseholdMembers
|
||||
*
|
||||
* @return Person[]
|
||||
*/
|
||||
public function getCurrentPersons(?DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getCurrentMembers($now)
|
||||
->map(function (HouseholdMember $m) { return $m->getPerson(); });
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,36 +260,13 @@ 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) {
|
||||
function (HouseholdMember $m) use ($membership) {
|
||||
return $m !== $membership;
|
||||
}
|
||||
);
|
||||
@@ -211,104 +284,33 @@ class Household
|
||||
return $this->getMembers()->matching($criteria);
|
||||
}
|
||||
|
||||
public function getCurrentMembers(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getMembers()->matching($this->buildCriteriaCurrentMembers($now));
|
||||
}
|
||||
|
||||
private function buildCriteriaCurrentMembers(?\DateTimeImmutable $now = null): Criteria
|
||||
public function getMembersOnRange(DateTimeImmutable $from, ?DateTimeImmutable $to): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = $now === null ? (new \DateTimeImmutable('today')) : $now;
|
||||
|
||||
$criteria
|
||||
->where($expr->orX(
|
||||
$expr->isNull('startDate'),
|
||||
$expr->lte('startDate', $date)
|
||||
))
|
||||
->andWhere($expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gt('endDate', $date)
|
||||
));
|
||||
|
||||
return $criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HouseholdMember[]
|
||||
*/
|
||||
public function getCurrentMembersOrdered(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
$members = $this->getCurrentMembers($now);
|
||||
|
||||
$members->getIterator()
|
||||
->uasort(
|
||||
function (HouseholdMember $a, HouseholdMember $b) {
|
||||
if ($a->getPosition() === NULL) {
|
||||
if ($b->getPosition() === NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} elseif ($b->getPosition() === NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($a->getPosition()->getOrdering() < $b->getPosition()->getOrdering()) {
|
||||
return -1;
|
||||
}
|
||||
if ($a->getPosition()->getOrdering() > $b->getPosition()->getOrdering()) {
|
||||
return 1;
|
||||
}
|
||||
if ($a->isHolder() && !$b->isHolder()) {
|
||||
return 1;
|
||||
}
|
||||
if (!$a->isHolder() && $b->isHolder()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
$criteria->where(
|
||||
$expr->gte('startDate', $from)
|
||||
);
|
||||
|
||||
return $members;
|
||||
if (null !== $to) {
|
||||
$criteria->andWhere(
|
||||
$expr->orX(
|
||||
$expr->lte('endDate', $to),
|
||||
$expr->eq('endDate', null)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->getMembers()
|
||||
->matching($criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* get current members ids
|
||||
*
|
||||
* Used in serialization
|
||||
*
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\SerializedName("current_members_id")
|
||||
*
|
||||
*/
|
||||
public function getCurrentMembersIds(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getCurrentMembers($now)->map(
|
||||
fn (HouseholdMember $m) => $m->getId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the persons currently associated to the household.
|
||||
*
|
||||
* Return a list of Person, instead of a list of HouseholdMembers
|
||||
*
|
||||
* @return Person[]
|
||||
*/
|
||||
public function getCurrentPersons(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getCurrentMembers($now)
|
||||
->map(function(HouseholdMember $m) { return $m->getPerson(); });
|
||||
}
|
||||
|
||||
public function getNonCurrentMembers(\DateTimeImmutable $now = null): Collection
|
||||
public function getNonCurrentMembers(?DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = $now === null ? (new \DateTimeImmutable('today')) : $now;
|
||||
$date = null === $now ? (new DateTimeImmutable('today')) : $now;
|
||||
|
||||
$criteria
|
||||
->where(
|
||||
@@ -324,17 +326,7 @@ class Household
|
||||
return $this->getMembers()->matching($criteria);
|
||||
}
|
||||
|
||||
public function getCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where($expr->eq('position', $position));
|
||||
|
||||
return $this->getCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
public function getNonCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
|
||||
public function getNonCurrentMembersByPosition(Position $position, ?DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
@@ -344,17 +336,7 @@ class Household
|
||||
return $this->getNonCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
public function getCurrentMembersWithoutPosition(\DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where($expr->isNull('position'));
|
||||
|
||||
return $this->getCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
public function getNonCurrentMembersWithoutPosition(\DateTimeInterface $now = null)
|
||||
public function getNonCurrentMembersWithoutPosition(?DateTimeInterface $now = null)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
@@ -364,14 +346,19 @@ class Household
|
||||
return $this->getNonCurrentMembers($now)->matching($criteria);
|
||||
}
|
||||
|
||||
public function addMember(HouseholdMember $member): self
|
||||
public function getWaitingForBirth(): bool
|
||||
{
|
||||
if (!$this->members->contains($member)) {
|
||||
$this->members[] = $member;
|
||||
$member->setHousehold($this);
|
||||
}
|
||||
return $this->waitingForBirth;
|
||||
}
|
||||
|
||||
return $this;
|
||||
public function getWaitingForBirthDate(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->waitingForBirthDate;
|
||||
}
|
||||
|
||||
public function removeAddress(Address $address)
|
||||
{
|
||||
$this->addresses->removeElement($address);
|
||||
}
|
||||
|
||||
public function removeMember(HouseholdMember $member): self
|
||||
@@ -386,11 +373,6 @@ class Household
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommentMembers(): CommentEmbeddable
|
||||
{
|
||||
return $this->commentMembers;
|
||||
}
|
||||
|
||||
public function setCommentMembers(CommentEmbeddable $commentMembers): self
|
||||
{
|
||||
$this->commentMembers = $commentMembers;
|
||||
@@ -398,9 +380,20 @@ class Household
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWaitingForBirth(): bool
|
||||
/**
|
||||
* Force an address starting at the current day
|
||||
* on the Household.
|
||||
*
|
||||
* This will force the startDate's address on today.
|
||||
*
|
||||
* Used on household creation.
|
||||
*
|
||||
* @Serializer\Groups({"create"})
|
||||
*/
|
||||
public function setForceAddress(Address $address)
|
||||
{
|
||||
return $this->waitingForBirth;
|
||||
$address->setValidFrom(new DateTime('today'));
|
||||
$this->addAddress($address);
|
||||
}
|
||||
|
||||
public function setWaitingForBirth(bool $waitingForBirth): self
|
||||
@@ -410,12 +403,7 @@ class Household
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWaitingForBirthDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->waitingForBirthDate;
|
||||
}
|
||||
|
||||
public function setWaitingForBirthDate(?\DateTimeImmutable $waitingForBirthDate): self
|
||||
public function setWaitingForBirthDate(?DateTimeImmutable $waitingForBirthDate): self
|
||||
{
|
||||
$this->waitingForBirthDate = $waitingForBirthDate;
|
||||
|
||||
@@ -425,14 +413,34 @@ class Household
|
||||
public function validate(ExecutionContextInterface $context, $payload)
|
||||
{
|
||||
$addresses = $this->getAddresses();
|
||||
$cond = True;
|
||||
for ($i=0; $i < count($addresses) - 1; $i++) {
|
||||
$cond = true;
|
||||
|
||||
for ($i = 0; count($addresses) - 1 > $i; ++$i) {
|
||||
if ($addresses[$i]->getValidFrom() != $addresses[$i + 1]->getValidTo()) {
|
||||
$cond = False;
|
||||
$cond = false;
|
||||
$context->buildViolation('The address are not sequentials. The validFrom date of one address should be equal to the validTo date of the previous address.')
|
||||
->atPath('addresses')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function buildCriteriaCurrentMembers(?DateTimeImmutable $now = null): Criteria
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = null === $now ? (new DateTimeImmutable('today')) : $now;
|
||||
|
||||
$criteria
|
||||
->where($expr->orX(
|
||||
$expr->isNull('startDate'),
|
||||
$expr->lte('startDate', $date)
|
||||
))
|
||||
->andWhere($expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gt('endDate', $date)
|
||||
));
|
||||
|
||||
return $criteria;
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Entity\Household;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use LogicException;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="chill_person_household_members"
|
||||
* )
|
||||
* name="chill_person_household_members"
|
||||
* )
|
||||
*/
|
||||
class HouseholdMember
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?string $comment = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\GreaterThan(
|
||||
* propertyPath="startDate",
|
||||
* message="household_membership.The end date must be after start date",
|
||||
* groups={"household_memberships"}
|
||||
* )
|
||||
*/
|
||||
private ?DateTimeImmutable $endDate = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", options={"default": false})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private bool $holder = false;
|
||||
|
||||
/**
|
||||
* @var Household
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity="\Chill\PersonBundle\Entity\Household\Household"
|
||||
* )
|
||||
* @Assert\Valid(groups={"household_memberships"})
|
||||
* @Assert\NotNull(groups={"household_memberships"})
|
||||
*/
|
||||
private ?Household $household = null;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
@@ -27,52 +66,9 @@ class HouseholdMember
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Position::class)
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\NotNull(groups={"household_memberships_created"})
|
||||
*/
|
||||
private ?Position $position = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\NotNull(groups={"household_memberships"})
|
||||
*/
|
||||
private ?\DateTimeImmutable $startDate = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable= true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\GreaterThan(
|
||||
* propertyPath="startDate",
|
||||
* message="household_membership.The end date must be after start date",
|
||||
* groups={"household_memberships"}
|
||||
* )
|
||||
*/
|
||||
private ?\DateTimeImmutable $endDate = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?string $comment = NULL;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", name="sharedhousehold")
|
||||
*/
|
||||
private bool $shareHousehold = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", options={"default": false})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private bool $holder = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Person
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity="\Chill\PersonBundle\Entity\Person"
|
||||
* targetEntity="\Chill\PersonBundle\Entity\Person"
|
||||
* )
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\Valid(groups={"household_memberships"})
|
||||
@@ -81,74 +77,52 @@ class HouseholdMember
|
||||
private ?Person $person = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Household
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity="\Chill\PersonBundle\Entity\Household\Household"
|
||||
* )
|
||||
* @Assert\Valid(groups={"household_memberships"})
|
||||
* @ORM\ManyToOne(targetEntity=Position::class)
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\NotNull(groups={"household_memberships_created"})
|
||||
*/
|
||||
private ?Position $position = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", name="sharedhousehold")
|
||||
*/
|
||||
private bool $shareHousehold = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Assert\NotNull(groups={"household_memberships"})
|
||||
*/
|
||||
private ?Household $household = null;
|
||||
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPosition(): ?Position
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function setPosition(Position $position): self
|
||||
{
|
||||
if ($this->position instanceof Position) {
|
||||
throw new \LogicException("The position is already set. You cannot change ".
|
||||
"a position of a membership");
|
||||
}
|
||||
|
||||
$this->position = $position;
|
||||
$this->shareHousehold = $position->getShareHousehold();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStartDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
public function setStartDate(\DateTimeImmutable $startDate): self
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEndDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
public function setEndDate(?\DateTimeImmutable $endDate = null): self
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
private ?DateTimeImmutable $startDate = null;
|
||||
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
public function setComment(?string $comment): self
|
||||
public function getEndDate(): ?DateTimeImmutable
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
return $this;
|
||||
public function getHousehold(): ?Household
|
||||
{
|
||||
return $this->household;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPerson(): ?Person
|
||||
{
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
public function getPosition(): ?Position
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,44 +133,35 @@ class HouseholdMember
|
||||
return $this->shareHousehold;
|
||||
}
|
||||
|
||||
public function setShareHousehold(bool $shareHousehold): self
|
||||
public function getStartDate(): ?DateTimeImmutable
|
||||
{
|
||||
$this->shareHousehold = $shareHousehold;
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
public function isCurrent(?DateTimeImmutable $at = null): bool
|
||||
{
|
||||
$at = null === $at ? new DateTimeImmutable('now') : $at;
|
||||
|
||||
return $this->getStartDate() < $at && (
|
||||
null === $this->getEndDate() || $this->getEndDate() > $at
|
||||
);
|
||||
}
|
||||
|
||||
public function isHolder(): bool
|
||||
{
|
||||
return $this->holder;
|
||||
}
|
||||
|
||||
public function setComment(?string $comment): self
|
||||
{
|
||||
$this->comment = $comment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPerson(): ?Person
|
||||
public function setEndDate(?DateTimeImmutable $endDate = null): self
|
||||
{
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
public function setPerson(?Person $person): self
|
||||
{
|
||||
if ($this->person instanceof Person) {
|
||||
throw new \LogicException("You cannot change person ".
|
||||
"on a membership");
|
||||
}
|
||||
|
||||
$this->person = $person;
|
||||
$this->person->addHouseholdParticipation($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHousehold(): ?Household
|
||||
{
|
||||
return $this->household;
|
||||
}
|
||||
|
||||
public function setHousehold(?Household $household): self
|
||||
{
|
||||
if ($this->household instanceof Household) {
|
||||
throw new \LogicException("You cannot change household ".
|
||||
"on a membership");
|
||||
}
|
||||
|
||||
$this->household = $household;
|
||||
$this->endDate = $endDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -208,17 +173,55 @@ class HouseholdMember
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isHolder(): bool
|
||||
public function setHousehold(?Household $household): self
|
||||
{
|
||||
return $this->holder;
|
||||
if ($this->household instanceof Household) {
|
||||
throw new LogicException('You cannot change household ' .
|
||||
'on a membership');
|
||||
}
|
||||
|
||||
$this->household = $household;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isCurrent(\DateTimeImmutable $at = null): bool
|
||||
public function setPerson(?Person $person): self
|
||||
{
|
||||
$at = NULL === $at ? new \DateTimeImmutable('now'): $at;
|
||||
if ($this->person instanceof Person) {
|
||||
throw new LogicException('You cannot change person ' .
|
||||
'on a membership');
|
||||
}
|
||||
|
||||
return $this->getStartDate() < $at && (
|
||||
NULL === $this->getEndDate() || $at < $this->getEndDate()
|
||||
);
|
||||
$this->person = $person;
|
||||
$this->person->addHouseholdParticipation($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPosition(Position $position): self
|
||||
{
|
||||
if ($this->position instanceof Position) {
|
||||
throw new LogicException('The position is already set. You cannot change ' .
|
||||
'a position of a membership');
|
||||
}
|
||||
|
||||
$this->position = $position;
|
||||
$this->shareHousehold = $position->getShareHousehold();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setShareHousehold(bool $shareHousehold): self
|
||||
{
|
||||
$this->shareHousehold = $shareHousehold;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setStartDate(DateTimeImmutable $startDate): self
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Entity\Household;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
@@ -36,6 +44,26 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
*/
|
||||
class PersonHouseholdAddress
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity=Address::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $address;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity=Household::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $household;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity=Person::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $person;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable")
|
||||
@@ -47,52 +75,9 @@ class PersonHouseholdAddress
|
||||
*/
|
||||
private $validTo;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity=Person::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $person;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity=Household::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $household;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\ManyToOne(targetEntity=Address::class)
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $address;
|
||||
|
||||
/**
|
||||
* The start date of the intersection address/household
|
||||
*
|
||||
* (this is not the startdate of the household, not
|
||||
* the startdate of the address)
|
||||
*/
|
||||
public function getValidFrom(): ?\DateTimeInterface
|
||||
public function getAddress(): ?Address
|
||||
{
|
||||
return $this->validFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* The end date of the intersection address/household
|
||||
*
|
||||
* (this is not the enddate of the household, not
|
||||
* the enddate of the address)
|
||||
*/
|
||||
public function getValidTo(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->validTo;
|
||||
}
|
||||
|
||||
public function getPerson(): ?Person
|
||||
{
|
||||
return $this->person;
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
public function getHousehold(): ?Household
|
||||
@@ -100,8 +85,30 @@ class PersonHouseholdAddress
|
||||
return $this->relation;
|
||||
}
|
||||
|
||||
public function getAddress(): ?Address
|
||||
public function getPerson(): ?Person
|
||||
{
|
||||
return $this->address;
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
/**
|
||||
* The start date of the intersection address/household.
|
||||
*
|
||||
* (this is not the startdate of the household, not
|
||||
* the startdate of the address)
|
||||
*/
|
||||
public function getValidFrom(): ?DateTimeInterface
|
||||
{
|
||||
return $this->validFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* The end date of the intersection address/household.
|
||||
*
|
||||
* (this is not the enddate of the household, not
|
||||
* the enddate of the address)
|
||||
*/
|
||||
public function getValidTo(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->validTo;
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Entity\Household;
|
||||
|
||||
use Chill\PersonBundle\Repository\Household\PositionRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
@@ -10,11 +16,17 @@ use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="chill_person_household_position")
|
||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "household_position"=Position::class
|
||||
* })
|
||||
* "household_position": Position::class
|
||||
* })
|
||||
*/
|
||||
class Position
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private bool $allowHolder = false;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
@@ -29,23 +41,22 @@ class Position
|
||||
*/
|
||||
private array $label = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="float")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private float $ordering = 0.00;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private bool $shareHouseHold = true;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private bool $allowHolder = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="float")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private float $ordering = 0.00;
|
||||
public function getAllowHolder(): bool
|
||||
{
|
||||
return $this->allowHolder;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
@@ -57,11 +68,9 @@ class Position
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(array $label): self
|
||||
public function getOrdering(): float
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
return $this->ordering;
|
||||
}
|
||||
|
||||
public function getShareHousehold(): bool
|
||||
@@ -69,18 +78,6 @@ class Position
|
||||
return $this->shareHouseHold;
|
||||
}
|
||||
|
||||
public function setShareHousehold(bool $shareHouseHold): self
|
||||
{
|
||||
$this->shareHouseHold = $shareHouseHold;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAllowHolder(): bool
|
||||
{
|
||||
return $this->allowHolder;
|
||||
}
|
||||
|
||||
public function isAllowHolder(): bool
|
||||
{
|
||||
return $this->getAllowHolder();
|
||||
@@ -93,9 +90,11 @@ class Position
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrdering(): float
|
||||
public function setLabel(array $label): self
|
||||
{
|
||||
return $this->ordering;
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOrdering(float $ordering): self
|
||||
@@ -104,4 +103,11 @@ class Position
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setShareHousehold(bool $shareHouseHold): self
|
||||
{
|
||||
$this->shareHouseHold = $shareHouseHold;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user