Skip to content

Commit

Permalink
Use descendants on tree instead of looping [WEB-2918]
Browse files Browse the repository at this point in the history
  • Loading branch information
web-dev-trev committed Aug 23, 2024
1 parent 5a7e911 commit c79bf30
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions app/Presenters/Admin/DigitalPublicationArticlePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,13 @@ public function getBrowseMoreLink($showAll = false)

public function countAllChildren($entity)
{
$count = 0;
foreach ($entity->children as $child) {
if ($child->type !== DigitalPublicationArticleType::Grouping) {
$count += 1;
}
$descendants = $entity->descendants;

if ($child->children && $child->children->count() > 0) {
$count += $this->countAllChildren($child);
}
}
return $count;
$filteredDescendants = $descendants->filter(function ($descendant) {
return $descendant->type !== DigitalPublicationArticleType::Grouping;
});

return $filteredDescendants->count();
}

public function references()
Expand Down

0 comments on commit c79bf30

Please sign in to comment.