mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Descendants for socialActions & Issues
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user