Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix listing display of Group Entries [WEB-2918] #488

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

web-dev-trev
Copy link
Member

No description provided.

Copy link
Member

@nikhiltri nikhiltri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small optimization.

Comment on lines 62 to 76
public function countAllChildren($entity)
{
$count = 0;
foreach ($entity->children as $child) {
if ($child->type !== DigitalPublicationArticleType::Grouping) {
$count += 1;
}

if ($child->children && $child->children->count() > 0) {
$count += $this->countAllChildren($child);
}
}
return $count;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NestedSet package includes a descendants method that retrieves all children recursively: https://github.com/lazychaser/laravel-nestedset?tab=readme-ov-file#ancestors-and-descendants.

So rather than writing your own recursive method here, I think you can call $entity->descendants, ->filter() out items that have the type Grouping, then count the results.

Copy link

sonarcloud bot commented Aug 23, 2024

Copy link
Member

@nikhiltri nikhiltri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! ⭐

@nikhiltri nikhiltri merged commit 531823e into develop Aug 23, 2024
3 checks passed
@nikhiltri nikhiltri deleted the fix/count-articles-recursively branch August 23, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants