Descendants for socialActions & Issues

This commit is contained in:
Marc Ducobu 2021-06-04 12:14:31 +02:00
parent 330234981c
commit bb71b9f908
4 changed files with 141 additions and 12 deletions

View File

@ -111,7 +111,7 @@ class ActivityType extends AbstractType
return $this->translatableStringHelper->localize($socialIssue->getTitle()); return $this->translatableStringHelper->localize($socialIssue->getTitle());
}, },
'multiple' => true, 'multiple' => true,
'choices' => $accompanyingPeriod->getSocialIssues(), 'choices' => $accompanyingPeriod->getRecursiveSocialIssues(),
]); ]);
} }
@ -124,7 +124,7 @@ class ActivityType extends AbstractType
return $this->translatableStringHelper->localize($socialAction->getTitle()); return $this->translatableStringHelper->localize($socialAction->getTitle());
}, },
'multiple' => true, 'multiple' => true,
'choices' => $accompanyingPeriod->getSocialActions(), 'choices' => $accompanyingPeriod->getRecursiveSocialActions(),
]); ]);
} }

View File

@ -824,20 +824,41 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
} }
/** /**
* List of all the social actions of the accompanyingPeriod * @return Collection|SocialIssues[] All social issues and their descendants
* i.e. social actions From social issues from the accompanyingPeriod
*/ */
public function getSocialActions(): Collection public function getRecursiveSocialIssues(): Collection
{ {
$ret = new ArrayCollection(); $recursiveSocialIssues = new ArrayCollection();
$this->socialIssues->forAll(function($key, $socialIssue) use ($ret) { foreach( $this->socialIssues as $socialIssue) {
$socialIssue->getSocialActions()->forAll(function($key, $socialAction) use ($ret) { foreach ($socialIssue->getDescendantsWithThis() as $descendant) {
$ret->add($socialAction); 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;
} }
/** /**

View File

@ -139,6 +139,41 @@ class SocialAction
return $this; 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 public function getDefaultNotificationDelay(): ?\DateInterval
{ {
return $this->defaultNotificationDelay; return $this->defaultNotificationDelay;

View File

@ -107,6 +107,42 @@ class SocialIssue
return $this; 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 public function getDesactivationDate(): ?\DateTimeInterface
{ {
return $this->desactivationDate; return $this->desactivationDate;
@ -160,4 +196,41 @@ class SocialIssue
return $this; 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;
}
} }