mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch 'features/household-editor' into features/household-validation
This commit is contained in:
@@ -116,8 +116,7 @@ class Household
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = $now === null ? (new \DateTimeImmutable('now')) : $now;
|
||||
|
||||
$date = $now === null ? (new \DateTimeImmutable('today')) : $now;
|
||||
|
||||
$criteria
|
||||
->where($expr->orX(
|
||||
@@ -149,7 +148,7 @@ class Household
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = $now === null ? (new \DateTimeImmutable('now')) : $now;
|
||||
$date = $now === null ? (new \DateTimeImmutable('today')) : $now;
|
||||
|
||||
$criteria
|
||||
->where(
|
||||
|
@@ -50,9 +50,9 @@ class HouseholdMember
|
||||
private ?string $comment = NULL;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
* @ORM\Column(type="boolean", name="sharedhousehold")
|
||||
*/
|
||||
private bool $sharedHousehold = false;
|
||||
private bool $shareHousehold = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", options={"default": false})
|
||||
@@ -98,7 +98,7 @@ class HouseholdMember
|
||||
}
|
||||
|
||||
$this->position = $position;
|
||||
$this->sharedHousehold = $position->getShareHousehold();
|
||||
$this->shareHousehold = $position->getShareHousehold();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class HouseholdMember
|
||||
*/
|
||||
public function getShareHousehold(): ?bool
|
||||
{
|
||||
return $this->sharedHousehold;
|
||||
return $this->shareHousehold;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass=PositionRepository::class)
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="chill_person_household_position")
|
||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "household_position"=Position::class
|
||||
@@ -25,21 +25,25 @@ class Position
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
* @Serializer\Groups({ "read" })
|
||||
*/
|
||||
private array $label = [];
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
|
@@ -25,6 +25,7 @@ namespace Chill\PersonBundle\Entity;
|
||||
use ArrayIterator;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Country;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\MainBundle\Entity\HasCenterInterface;
|
||||
@@ -281,6 +282,11 @@ class Person implements HasCenterInterface
|
||||
*/
|
||||
private Collection $householdParticipations;
|
||||
|
||||
/**
|
||||
* Cache the computation of household
|
||||
*/
|
||||
private array $currentHouseholdAt = [];
|
||||
|
||||
/**
|
||||
* Person constructor.
|
||||
*
|
||||
@@ -1202,4 +1208,43 @@ class Person implements HasCenterInterface
|
||||
{
|
||||
return $this->householdParticipations;
|
||||
}
|
||||
|
||||
public function getCurrentHousehold(?\DateTimeImmutable $at = null): ?Household
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = NULL === $at ? new \DateTimeImmutable('now') : $at;
|
||||
$datef = $date->format('Y-m-d');
|
||||
|
||||
if (
|
||||
NULL !== ($this->currentHouseholdAt[$datef] ?? NULL)) {
|
||||
return $this->currentHouseholdAt[$datef];
|
||||
}
|
||||
|
||||
$criteria
|
||||
->where(
|
||||
$expr->andX(
|
||||
$expr->lte('startDate', $date),
|
||||
$expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gte('endDate', $date)
|
||||
),
|
||||
$expr->eq('shareHousehold', true)
|
||||
)
|
||||
);
|
||||
|
||||
$participations = $this->getHouseholdParticipations()
|
||||
->matching($criteria)
|
||||
;
|
||||
|
||||
return $participations->count() > 0 ?
|
||||
$this->currentHouseholdAt[$datef] = $participations->first()
|
||||
->getHousehold()
|
||||
: null;
|
||||
}
|
||||
|
||||
public function isSharingHousehold(?\DateTimeImmutable $at = null): bool
|
||||
{
|
||||
return NULL !== $this->getCurrentHousehold($at);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user