Skip to content

Commit

Permalink
Add method to count children of children that aren't Groupings [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 ba79c7b commit 213657d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/Presenters/Admin/DigitalPublicationArticlePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Str;
use App\Presenters\BasePresenter;
use App\Enums\DigitalPublicationArticleType;

class DigitalPublicationArticlePresenter extends BasePresenter
{
Expand Down Expand Up @@ -40,10 +41,11 @@ public function getArticleUrl($digitalPublication, $article = null)

public function getBrowseMoreLink($showAll = false)
{
if ($this->entity->children->count() > 0 && !$showAll) {
if ($this->entity->children->count() > 0 && !$showAll) {
$totalChildrenCount = $this->countAllChildren($this->entity);
return [
[
'label' => 'Browse all ' . $this->entity->children->count() . ' ' . $this->entity->title,
'label' => 'Browse all ' . $totalChildrenCount . ' ' . $this->entity->title,
'href' => route(
'collection.publications.digital-publications.showListing',
[
Expand All @@ -56,6 +58,20 @@ public function getBrowseMoreLink($showAll = false)
}
return '';
}

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;
}

public function references()
{
Expand Down

0 comments on commit 213657d

Please sign in to comment.