Merge branch 'master' into features/sql-vue-from-household-address-to-person

This commit is contained in:
2021-06-15 22:53:21 +02:00
208 changed files with 9047 additions and 6038 deletions

View File

@@ -53,36 +53,36 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
{
/**
* Mark an accompanying period as "occasional"
*
*
* used in INTENSITY
*/
public const INTENSITY_OCCASIONAL = 'occasional';
/**
* Mark an accompanying period as "regular"
*
*
* used in INTENSITY
*/
public const INTENSITY_REGULAR = 'regular';
public const INTENSITIES = [self::INTENSITY_OCCASIONAL, self::INTENSITY_REGULAR];
/**
* Mark an accompanying period as "draft".
*
* This means that the accompanying period is not yet
*
* This means that the accompanying period is not yet
* confirmed by the creator
*/
public const STEP_DRAFT = 'DRAFT';
/**
* Mark an accompanying period as "confirmed".
*
* This means that the accompanying period **is**
*
* This means that the accompanying period **is**
* confirmed by the creator
*/
public const STEP_CONFIRMED = 'CONFIRMED';
/**
* @var integer
*
@@ -176,7 +176,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* @Groups({"read"})
*/
private $step = self::STEP_DRAFT;
/**
* @ORM\ManyToOne(targetEntity=Origin::class)
* @ORM\JoinColumn(nullable=true)
@@ -274,7 +274,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* )
*/
private User $updatedBy;
/**
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
*/
@@ -412,7 +412,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
{
if (NULL !== $this->initialComment) {
$this->removeComment($this->initialComment);
}
}
if ($comment instanceof Comment) {
$this->addComment($comment);
}
@@ -471,7 +471,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
}
/**
* Return true if the accompanying period contains a person.
* Return true if the accompanying period contains a person.
*
* **Note**: this participation can be opened or not.
*/
@@ -518,7 +518,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $participation;
}
/**
* Remove Person
@@ -822,6 +822,44 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
$this->socialIssues->removeElement($socialIssue);
}
/**
* @return Collection|SocialIssues[] All social issues and their descendants
*/
public function getRecursiveSocialIssues(): Collection
{
$recursiveSocialIssues = new ArrayCollection();
foreach( $this->socialIssues as $socialIssue) {
foreach ($socialIssue->getDescendantsWithThis() as $descendant) {
if(! $recursiveSocialIssues->contains($descendant)) {
$recursiveSocialIssues->add($descendant);
}
}
}
return $recursiveSocialIssues;
}
/**
* @return Collection|SocialAction[] All the descendant social actions of all
* the descendants of the entity
*/
public function getRecursiveSocialActions(): Collection
{
$recursiveSocialActions = new ArrayCollection();
foreach( $this->socialIssues as $socialIssue) {
foreach ($socialIssue->getRecursiveSocialActions() as $descendant) {
if(! $recursiveSocialActions->contains($descendant)) {
$recursiveSocialActions->add($descendant);
}
}
}
return $recursiveSocialActions;
}
/**
* Get a list of all persons which are participating to this course
*

View File

@@ -5,6 +5,7 @@ namespace Chill\PersonBundle\Entity\Household;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -107,6 +108,78 @@ class Household
return $this->members;
}
public function getCurrentMembers(?\DateTimeImmutable $now = null): 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->gte('endDate', $date)
));
return $this->getMembers()->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 getNonCurrentMembers(\DateTimeImmutable $now = null): Collection
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $now === null ? (new \DateTimeImmutable('today')) : $now;
$criteria
->where(
$expr->gt('startDate', $date)
)
->orWhere(
$expr->andX(
$expr->lt('endDate', $date),
$expr->neq('endDate', null)
)
);
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)
{
$criteria = new Criteria();
$expr = Criteria::expr();
$criteria->where($expr->eq('position', $position));
return $this->getNonCurrentMembers($now)->matching($criteria);
}
public function addMember(HouseholdMember $member): self
{
if (!$this->members->contains($member)) {

View File

@@ -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;
}
@@ -120,7 +120,7 @@ class HouseholdMember
return $this->endDate;
}
public function setEndDate(\DateTimeImmutable $endDate): self
public function setEndDate(?\DateTimeImmutable $endDate = null): self
{
$this->endDate = $endDate;
@@ -144,7 +144,7 @@ class HouseholdMember
*/
public function getShareHousehold(): ?bool
{
return $this->sharedHousehold;
return $this->shareHousehold;
}

View File

@@ -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
@@ -21,34 +21,38 @@ class Position
* @ORM\Column(type="integer")
* @Serializer\Groups({ "read" })
*/
private $id;
private ?int $id;
/**
* @ORM\Column(type="json")
* @Serializer\Groups({ "read" })
*/
private $label = [];
private array $label = [];
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({ "read" })
*/
private $shareHouseHold;
private bool $shareHouseHold = true;
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({ "read" })
*/
private $allowHolder;
private bool $allowHolder = false;
/**
* @ORM\Column(type="float")
* @Serializer\Groups({ "read" })
*/
private $ordering;
private float $ordering = 0.00;
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?array
public function getLabel(): array
{
return $this->label;
}
@@ -60,7 +64,7 @@ class Position
return $this;
}
public function getShareHousehold(): ?bool
public function getShareHousehold(): bool
{
return $this->shareHouseHold;
}
@@ -72,11 +76,16 @@ class Position
return $this;
}
public function getAllowHolder(): ?bool
public function getAllowHolder(): bool
{
return $this->allowHolder;
}
public function isAllowHolder(): bool
{
return $this->getAllowHolder();
}
public function setAllowHolder(bool $allowHolder): self
{
$this->allowHolder = $allowHolder;
@@ -84,7 +93,7 @@ class Position
return $this;
}
public function getOrdering(): ?float
public function getOrdering(): float
{
return $this->ordering;
}

View File

@@ -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);
}
}

View File

@@ -102,6 +102,11 @@ class SocialAction
return $this->parent;
}
public function hasParent(): bool
{
return $this->getParent() instanceof self;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
@@ -139,6 +144,41 @@ class SocialAction
return $this;
}
/**
* @return Collection|self[] All the descendants (children, children of children, ...)
*/
public function getDescendants(): Collection
{
$descendants = new ArrayCollection();
foreach ($this->getChildren() as $child) {
if(! $descendants->contains($child)) {
$descendants->add($child);
foreach($child->getDescendants() as $descendantsOfChild) {
if(! $descendants->contains($descendantsOfChild)) {
$descendants->add($descendantsOfChild);
}
}
}
}
return $descendants;
}
/**
* @return Collection|self[] All the descendants with the current entity (this)
*/
public function getDescendantsWithThis(): Collection
{
$descendants = $this->getDescendants();
if(! $descendants->contains($this)) {
$descendants->add($this);
}
return $descendants;
}
public function getDefaultNotificationDelay(): ?\DateInterval
{
return $this->defaultNotificationDelay;

View File

@@ -107,6 +107,42 @@ class SocialIssue
return $this;
}
/**
* @return Collection|self[] All the descendants (children, children of children, ...)
*/
public function getDescendants(): Collection
{
$descendants = new ArrayCollection();
foreach ($this->getChildren() as $child) {
if(! $descendants->contains($child)) {
$descendants->add($child);
foreach($child->getDescendants() as $descendantsOfChild) {
if(! $descendants->contains($descendantsOfChild)) {
$descendants->add($descendantsOfChild);
}
}
}
}
return $descendants;
}
/**
* @return Collection|self[] All the descendants with the current entity (this)
*/
public function getDescendantsWithThis(): Collection
{
$descendants = $this->getDescendants();
if(! $descendants->contains($this)) {
$descendants->add($this);
}
return $descendants;
}
public function getDesactivationDate(): ?\DateTimeInterface
{
return $this->desactivationDate;
@@ -160,4 +196,41 @@ class SocialIssue
return $this;
}
/**
* @return Collection|SocialAction[] All the descendant social actions of the entity
*/
public function getDescendantsSocialActions(): Collection
{
$descendantsSocialActions = new ArrayCollection();
foreach ($this->getSocialActions() as $socialAction) {
foreach ($socialAction->getDescendantsWithThis() as $descendant) {
if(! $descendantsSocialActions->contains($descendant)) {
$descendantsSocialActions->add($descendant);
}
}
}
return $descendantsSocialActions;
}
/**
* @return Collection|SocialAction[] All the descendant social actions of all
* the descendants of the entity
*/
public function getRecursiveSocialActions(): Collection
{
$recursiveSocialActions = new ArrayCollection();
foreach ($this->getDescendantsWithThis() as $socialIssue) {
foreach ($socialIssue->getDescendantsSocialActions() as $descendant) {
if(! $recursiveSocialActions->contains($descendant)) {
$recursiveSocialActions->add($descendant);
}
}
}
return $recursiveSocialActions;
}
}