fix calculation on indirect articles by tags
This commit is contained in:
@@ -15,14 +15,23 @@ class TagGroups
|
||||
public static function getWithTagsAndCountOffers($category_id = false)
|
||||
{
|
||||
$data = [];
|
||||
$tags = Tag::withCountArticlesByCategory($category_id)->get()->toArray();
|
||||
$tagGroups = TagGroup::pluck('name', 'id')->toArray();
|
||||
foreach ($tags as $tag) {
|
||||
$data[$tag['tag_group_id']]['name'] = $tagGroups[$tag['tag_group_id']];
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
$tagsDirect = Tag::withCountDirectArticlesByCategory($category_id)->get()->toArray();
|
||||
$tagsIndirect = Tag::withCountIndirectArticlesByCategory($category_id)->get()->toArray();
|
||||
foreach ($tagsDirect as $tag) {
|
||||
$data[$tag['tag_group_id']]['name'] = $tag['group'];
|
||||
$data[$tag['tag_group_id']]['tags'][$tag['id']] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
'count' => $tag['direct_article_count'] + $tag['indirect_article_count'],
|
||||
'count' => $tag['direct_article_count'],
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($tagsIndirect as $tag) {
|
||||
$data[$tag['tag_group_id']]['name'] = $tag['group'];
|
||||
$data[$tag['tag_group_id']]['tags'][$tag['id']] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
'count' => ($data[$tag['tag_group_id']]['tags'][$tag['id']]['count'] ?? 0) + $tag['indirect_article_count'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user