mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
fix cs
This commit is contained in:
@@ -128,6 +128,44 @@ class SocialAction
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* In a SocialIssues's collection, find the elements which are an ancestor of
|
||||
* other elements.
|
||||
*
|
||||
* The difference of the given list (thus, the elements which are **not** kept
|
||||
* in the returned collection) are the most-grand-child elements of the list.
|
||||
*
|
||||
* Removing those elements of the Collection (which is not done by this method)
|
||||
* will ensure that only the most descendent elements are present in the collection,
|
||||
* (any ancestor of another element are present).
|
||||
*
|
||||
* @param Collection|SocialAction[] $socialActions
|
||||
*
|
||||
* @return Collection|SocialAction[] a list with the elements of the given list which are parent of other elements in the given list
|
||||
*/
|
||||
public static function findAncestorSocialActions(Collection $socialActions): Collection
|
||||
{
|
||||
$ancestors = new ArrayCollection();
|
||||
|
||||
foreach ($socialActions as $candidateChild) {
|
||||
if ($ancestors->contains($candidateChild)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($socialActions as $candidateParent) {
|
||||
if ($ancestors->contains($candidateParent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($candidateChild->isDescendantOf($candidateParent)) {
|
||||
$ancestors->add($candidateParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ancestors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|self[]
|
||||
*/
|
||||
@@ -233,6 +271,23 @@ class SocialAction
|
||||
return $this->getParent() instanceof self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive method which return true if the current $action
|
||||
* is a descendant of the $action given in parameter.
|
||||
*/
|
||||
public function isDescendantOf(SocialAction $action): bool
|
||||
{
|
||||
if (!$this->hasParent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getParent() === $action) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->getParent()->isDescendantOf($action);
|
||||
}
|
||||
|
||||
public function removeChild(self $child): self
|
||||
{
|
||||
if ($this->children->removeElement($child)) {
|
||||
@@ -307,59 +362,4 @@ class SocialAction
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive method which return true if the current $action
|
||||
* is a descendant of the $action given in parameter.
|
||||
*/
|
||||
public function isDescendantOf(SocialAction $action): bool
|
||||
{
|
||||
if (!$this->hasParent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getParent() === $action) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->getParent()->isDescendantOf($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* In a SocialIssues's collection, find the elements which are an ancestor of
|
||||
* other elements.
|
||||
*
|
||||
* The difference of the given list (thus, the elements which are **not** kept
|
||||
* in the returned collection) are the most-grand-child elements of the list.
|
||||
*
|
||||
* Removing those elements of the Collection (which is not done by this method)
|
||||
* will ensure that only the most descendent elements are present in the collection,
|
||||
* (any ancestor of another element are present).
|
||||
*
|
||||
* @param Collection|SocialAction[] $socialActions
|
||||
*
|
||||
* @return Collection|SocialAction[] a list with the elements of the given list which are parent of other elements in the given list
|
||||
*/
|
||||
public static function findAncestorSocialActions(Collection $socialActions): Collection
|
||||
{
|
||||
$ancestors = new ArrayCollection();
|
||||
|
||||
foreach ($socialActions as $candidateChild) {
|
||||
if ($ancestors->contains($candidateChild)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($socialActions as $candidateParent) {
|
||||
if ($ancestors->contains($candidateParent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($candidateChild->isDescendantOf($candidateParent)) {
|
||||
$ancestors->add($candidateParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ancestors;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user