diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 2e2c68812..c2e443f1d 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -111,7 +111,7 @@ class ActivityType extends AbstractType return $this->translatableStringHelper->localize($socialIssue->getTitle()); }, 'multiple' => true, - 'choices' => $accompanyingPeriod->getSocialIssues(), + 'choices' => $accompanyingPeriod->getRecursiveSocialIssues(), ]); } @@ -124,7 +124,7 @@ class ActivityType extends AbstractType return $this->translatableStringHelper->localize($socialAction->getTitle()); }, 'multiple' => true, - 'choices' => $accompanyingPeriod->getSocialActions(), + 'choices' => $accompanyingPeriod->getRecursiveSocialActions(), ]); } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 9a5b442c7..12c413f92 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -824,20 +824,41 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface } /** - * List of all the social actions of the accompanyingPeriod - * i.e. social actions From social issues from the accompanyingPeriod + * @return Collection|SocialIssues[] All social issues and their descendants */ - public function getSocialActions(): Collection + public function getRecursiveSocialIssues(): Collection { - $ret = new ArrayCollection(); + $recursiveSocialIssues = new ArrayCollection(); - $this->socialIssues->forAll(function($key, $socialIssue) use ($ret) { - $socialIssue->getSocialActions()->forAll(function($key, $socialAction) use ($ret) { - $ret->add($socialAction); - }); - }); + foreach( $this->socialIssues as $socialIssue) { + foreach ($socialIssue->getDescendantsWithThis() as $descendant) { + if(! $recursiveSocialIssues->contains($descendant)) { + $recursiveSocialIssues->add($descendant); + } + } + } - return $ret; + 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; } /** diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index ff7291b45..0c83ab845 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -139,6 +139,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; diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index 6b2152cdf..ae1c573f5 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -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; + } }