-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small optimization.
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; | ||
} | ||
|
There was a problem hiding this comment.
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.
1473557
to
c79bf30
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! ⭐
No description provided.