mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
create api for social issue consistency
This commit is contained in:
@@ -233,4 +233,57 @@ class SocialIssue
|
||||
|
||||
return $recursiveSocialActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive method which return true if the current $issue is a descendant
|
||||
* of the $issue given in parameter.
|
||||
*
|
||||
* @param SocialIssue $issue
|
||||
* @return bool
|
||||
*/
|
||||
public function isDescendantOf(SocialIssue $issue): bool
|
||||
{
|
||||
if (!$this->hasParent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getParent() === $issue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->getParent()->isDescendantOf($issue);
|
||||
}
|
||||
|
||||
/**
|
||||
* In a SocialIssues's collection, find the elements which are an ancestor of
|
||||
* other elements.
|
||||
*
|
||||
* 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|SocialIssue[] $socialIssues
|
||||
* @return Collection|SocialIssue[]
|
||||
*/
|
||||
public static function findAncestorSocialIssues(Collection $socialIssues): Collection
|
||||
{
|
||||
$ancestors = new ArrayCollection();
|
||||
|
||||
foreach ($socialIssues as $candidateChild) {
|
||||
if ($ancestors->contains($candidateChild)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($socialIssues as $candidateParent) {
|
||||
if ($ancestors->contains($candidateParent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($candidateChild->isDescendantOf($candidateParent)) {
|
||||
$ancestors->add($candidateParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ancestors;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user