refactor scopes
This commit is contained in:
@@ -16,48 +16,19 @@ class TagGroups
|
||||
{
|
||||
$data = [];
|
||||
$tags = Tag::withCountArticlesByCategory($category_id)->get()->toArray();
|
||||
dump($tags);
|
||||
exit;
|
||||
$tagGroups = TagGroup::pluck('name', 'id')->toArray();
|
||||
foreach ($tags as $tag) {
|
||||
if (! $tag['articles_count']) {
|
||||
continue;
|
||||
}
|
||||
$data[$tag['tag_group_id']]['name'] = $tagGroups[$tag['tag_group_id']];
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
'count' => $tag['articles_count'],
|
||||
'count' => $tag['direct_article_count'] + $tag['indirect_article_count'],
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getWithTagsAndCountOffers2($categoryId = false)
|
||||
{
|
||||
return Tag::withCount([
|
||||
'articles as direct_article_count' => function ($query) use ($categoryId) {
|
||||
$query->byCategoryParent($categoryId);
|
||||
},
|
||||
'articles as indirect_article_count' => function ($query) use ($categoryId) {
|
||||
$query->whereHasMorph('product', [Variety::class], function ($subQuery) use ($categoryId) {
|
||||
$subQuery->whereHas('categories', function ($categoryQuery) use ($categoryId) {
|
||||
$categoryQuery->byCategoryParent($categoryId);
|
||||
});
|
||||
});
|
||||
},
|
||||
])
|
||||
->get()
|
||||
->map(function ($tag) {
|
||||
$tag->total_articles = $tag->direct_article_count + $tag->indirect_article_count;
|
||||
return $tag;
|
||||
})
|
||||
->filter(function ($tag) {
|
||||
return $tag->total_articles > 0; // Garde uniquement les tags ayant des articles
|
||||
});
|
||||
}
|
||||
|
||||
public static function isTagGroupHaveSelected($tagsSelected, $tags)
|
||||
{
|
||||
foreach ($tags as $tag) {
|
||||
|
||||
Reference in New Issue
Block a user