bottom chart and responsive changes

This commit is contained in:
itsAzaria
2026-02-20 20:55:58 +00:00
parent ee3b46e468
commit a0c65ca3d7
6 changed files with 278 additions and 192 deletions
@@ -0,0 +1,34 @@
<?php
namespace App\Models\Concerns;
trait BuildsEmoteAggregates
{
protected static function aggregateSummaryAndUsageByType(
$baseQuery,
string $usageCountColumn,
string $emoteIdColumn,
?string $userIdColumn = null
): array {
$summaryQuery = (clone $baseQuery)
->selectRaw("COALESCE(SUM({$usageCountColumn}), 0) as total_usage")
->selectRaw("COUNT(DISTINCT {$emoteIdColumn}) as unique_emotes");
if ($userIdColumn !== null) {
$summaryQuery->selectRaw("COUNT(DISTINCT {$userIdColumn}) as unique_users");
}
$summary = $summaryQuery->first();
$usageByType = (clone $baseQuery)
->select('emotes.type')
->selectRaw("COALESCE(SUM({$usageCountColumn}), 0) as total_usage")
->groupBy('emotes.type')
->pluck('total_usage', 'type');
return [
'summary' => $summary,
'usage_by_type' => $usageByType,
];
}
}