Merge branch 'master' into household_filiation

This commit is contained in:
2021-11-12 17:20:46 +01:00
298 changed files with 8036 additions and 3185 deletions

View File

@@ -28,6 +28,7 @@ use Chill\MainBundle\Entity\HasCentersInterface;
use Chill\MainBundle\Entity\HasScopesInterface;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
@@ -44,6 +45,9 @@ use Chill\MainBundle\Entity\User;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\GroupSequenceProviderInterface;
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap;
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck;
/**
* AccompanyingPeriod Class
@@ -53,9 +57,10 @@ use Symfony\Component\Validator\Constraints as Assert;
* @DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period"=AccompanyingPeriod::class
* })
* @Assert\GroupSequenceProvider
*/
class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface,
HasScopesInterface, HasCentersInterface
HasScopesInterface, HasCentersInterface, GroupSequenceProviderInterface
{
/**
* Mark an accompanying period as "occasional"
@@ -131,6 +136,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_DRAFT})
*/
private $comments;
@@ -146,9 +152,10 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* @var Collection
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
* mappedBy="accompanyingPeriod",
* mappedBy="accompanyingPeriod", orphanRemoval=true,
* cascade={"persist", "refresh", "remove", "merge", "detach"})
* @Groups({"read"})
* @ParticipationOverlap(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED})
*/
private $participations;
@@ -187,6 +194,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* @ORM\ManyToOne(targetEntity=Origin::class)
* @ORM\JoinColumn(nullable=true)
* @Groups({"read", "write"})
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private $origin;
@@ -194,8 +202,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* @var string
* @ORM\Column(type="string", nullable=true)
* @Groups({"read", "write"})
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private $intensity;
private $intensity = self::INTENSITY_OCCASIONAL;
/**
* @var Collection
@@ -209,6 +218,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
* )
* @Groups({"read"})
* @Assert\Count(min=1, groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private $scopes;
@@ -255,6 +265,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* orphanRemoval=true
* )
* @Groups({"read"})
* @ResourceDuplicateCheck(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED, "Default", "default"})
*/
private $resources;
@@ -266,6 +277,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
* name="chill_person_accompanying_period_social_issues"
* )
* @Groups({"read"})
* @Assert\Count(min=1, groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private Collection $socialIssues;
@@ -502,7 +514,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $collection->count() > 0 ? $collection->first() : NULL;
}
public function getOPenParticipations(): Collection
public function getOpenParticipations(): Collection
{
return $this
->getParticipations()
@@ -513,6 +525,11 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
);
}
public function getCurrentParticipations(): Collection
{
return $this->getOpenParticipations();
}
/**
* Return an array with open participations sorted by household
* [
@@ -600,6 +617,14 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $participation;
}
/**
* Remove Participation
*/
public function removeParticipation(AccompanyingPeriodParticipation $participation)
{
$participation->setAccompanyingPeriod(null);
}
/**
* Remove Person
@@ -1015,6 +1040,15 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $this->addressLocation;
}
public function getCenter(): ?Center
{
if (count($this->getPersons()) === 0){
return null;
} else {
return $this->getPersons()->first()->getCenter();
}
}
/**
* @Groups({"write"})
*/
@@ -1100,4 +1134,17 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $centers ?? null;
}
public function getGroupSequence()
{
if($this->getStep() == self::STEP_DRAFT)
{
return [[self::STEP_DRAFT]];
}
if($this->getStep() == self::STEP_CONFIRMED)
{
return [[self::STEP_DRAFT, self::STEP_CONFIRMED]];
}
}
}

View File

@@ -167,7 +167,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\OneToMany(
* targetEntity=AccompanyingPeriodWorkEvaluation::class,
* mappedBy="accompanyingPeriodWork",
* cascade={"persist"},
* cascade={"remove", "persist"},
* orphanRemoval=true
* )
* @Serializer\Groups({"read"})

View File

@@ -70,7 +70,8 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
/**
* @ORM\ManyToOne(
* targetEntity=StoredObject::class
* targetEntity=StoredObject::class,
* cascade={"remove"},
* )
* @Serializer\Groups({"read"})
*/

View File

@@ -33,7 +33,13 @@ use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity
* @ORM\Table(name="chill_person_accompanying_period_resource")
* @ORM\Table(
* name="chill_person_accompanying_period_resource",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="person_unique", columns={"person_id", "accompanyingperiod_id"}),
* @ORM\UniqueConstraint(name="thirdparty_unique", columns={"thirdparty_id", "accompanyingperiod_id"})
* }
* )
* @DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period_resource"=Resource::class
* })

View File

@@ -134,4 +134,11 @@ class AccompanyingPeriodParticipation
{
return $this->endDate === null;
}
private function checkSameStartEnd()
{
if($this->endDate == $this->startDate) {
$this->accompanyingPeriod->removeParticipation($this);
}
}
}

View File

@@ -41,7 +41,7 @@ class Household
* targetEntity="Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_person_household_to_addresses")
* @ORM\OrderBy({"validFrom" = "DESC"})
* @ORM\OrderBy({"validFrom" = "DESC", "id" = "DESC"})
* @Serializer\Groups({"write"})
*/
private Collection $addresses;
@@ -245,6 +245,16 @@ class Household
$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;
}
@@ -334,6 +344,26 @@ 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)
{
$criteria = new Criteria();
$expr = Criteria::expr();
$criteria->where($expr->isNull('position'));
return $this->getNonCurrentMembers($now)->matching($criteria);
}
public function addMember(HouseholdMember $member): self
{
if (!$this->members->contains($member)) {

View File

@@ -29,7 +29,7 @@ class HouseholdMember
/**
* @ORM\ManyToOne(targetEntity=Position::class)
* @Serializer\Groups({"read"})
* @Assert\NotNull(groups={"household_memberships"})
* @Assert\NotNull(groups={"household_memberships_created"})
*/
private ?Position $position = null;
@@ -159,6 +159,12 @@ class HouseholdMember
return $this->shareHousehold;
}
public function setShareHousehold(bool $shareHousehold): self
{
$this->shareHousehold = $shareHousehold;
return $this;
}
public function getPerson(): ?Person
{

View File

@@ -41,14 +41,14 @@ class MaritalStatus
/**
* @var string array
* @ORM\Column(type="json_array")
* @ORM\Column(type="json")
*/
private $name;
/**
* Get id
*
* @return string
* @return string
*/
public function getId()
{
@@ -57,7 +57,7 @@ class MaritalStatus
/**
* Set id
*
*
* @param string $id
* @return MaritalStatus
*/
@@ -76,17 +76,17 @@ class MaritalStatus
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string array
* @return string array
*/
public function getName()
{
return $this->name;
}
}
}

View File

@@ -34,6 +34,7 @@ use Chill\PersonBundle\Entity\MaritalStatus;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\PersonBundle\Entity\Person\PersonCurrentAddress;
use DateTime;
@@ -212,6 +213,15 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
private $maritalStatus;
/**
* The marital status of the person
* @var Civility
*
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Civility")
* @ORM\JoinColumn(nullable=true)
*/
private $civility;
/**
* The date of the last marital status change of the person
* @var \DateTime
@@ -406,7 +416,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* Array where customfield's data are stored
* @var array
*
* @ORM\Column(type="json_array")
* @ORM\Column(type="json")
*/
private $cFData;
@@ -620,7 +630,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
{
$currentAccompanyingPeriods = [];
$currentDate = new DateTime();
foreach ($this->accompanyingPeriodParticipations as $participation)
{
$endDate = $participation->getEndDate();
@@ -988,6 +998,28 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->maritalStatus;
}
/**
* Set civility
*
* @param Civility $civility
* @return Person
*/
public function setCivility(Civility $civility = null)
{
$this->civility = $civility;
return $this;
}
/**
* Get civility
*
* @return Civility
*/
public function getCivility()
{
return $this->civility;
}
/**
* Set contactInfo
*
@@ -1309,11 +1341,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* get the address associated with the person at the given date
*
* If the `$at` parameter is now, use the method `getCurrentPersonAddress`, which is optimized
* on database side.
*
* @param DateTime|null $at
* @return Address|null
* @throws \Exception
*/
public function getCurrentPersonAddress(?\DateTime $at = null): ?Address
public function getAddressAt(?\DateTime $at = null): ?Address
{
$at ??= new DateTime('now');
@@ -1331,6 +1366,20 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
current($addresses);
}
/**
* Get the current person address
*
* @return Address|null
*/
public function getCurrentPersonAddress(): ?Address
{
if (null === $this->currentPersonAddress) {
return null;
}
return $this->currentPersonAddress->getAddress();
}
/**
* Validation callback that checks if the accompanying periods are valid
*