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

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