configure SocialIssue consistency on Activity and AccompanyingPeriod

This commit is contained in:
2021-08-22 00:01:24 +02:00
parent 09e5cc1545
commit 075f22e79c
9 changed files with 54 additions and 11 deletions

View File

@@ -17,7 +17,7 @@ use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
*/
interface AccompanyingPeriodLinkedWithSocialIssuesEntityInterface
{
public function getAccompanyingPeriod(): AccompanyingPeriod;
public function getAccompanyingPeriod(): ?AccompanyingPeriod;
/**
* @return Collection|SocialIssue[]

View File

@@ -39,14 +39,15 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListener
private function ensureConsistencyEntity(AccompanyingPeriodLinkedWithSocialIssuesEntityInterface $entity): void
{
if (NULL === $period = $entity->getAccompanyingPeriod()) {
return;
}
// remove issues parents on the entity itself
$ancestors = SocialIssue::findAncestorSocialIssues($entity->getSocialIssues());
foreach ($ancestors as $ancestor) {
$entity->removeSocialIssue($ancestor);
}
$period = $entity->getAccompanyingPeriod();
foreach ($entity->getSocialIssues() as $issue) {
// the entity itself test if the social issue is already associated, or not
$period->addSocialIssue($issue);