mirror of
https://github.com/the-programmers-hangout/Hermes.git
synced 2026-09-09 07:56:20 +02:00
bottom chart and responsive changes
This commit is contained in:
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
trait BuildsEmoteUsageLists
|
||||
{
|
||||
protected static function emotesByType(
|
||||
$baseQuery,
|
||||
string $type,
|
||||
string $usageCountColumn,
|
||||
string $emoteIdColumn,
|
||||
string $direction = 'desc'
|
||||
): Collection {
|
||||
$query = (clone $baseQuery)
|
||||
->where('emotes.type', $type)
|
||||
->select(
|
||||
$emoteIdColumn.' as emote_id',
|
||||
'emotes.emote_name',
|
||||
'emotes.type',
|
||||
'emotes.image'
|
||||
)
|
||||
->selectRaw("COALESCE(SUM({$usageCountColumn}), 0) as total_usage")
|
||||
->groupBy(
|
||||
$emoteIdColumn,
|
||||
'emotes.emote_name',
|
||||
'emotes.type',
|
||||
'emotes.image'
|
||||
);
|
||||
|
||||
if ($direction === 'asc') {
|
||||
$query->orderBy('total_usage');
|
||||
} else {
|
||||
$query->orderByDesc('total_usage');
|
||||
}
|
||||
|
||||
return $query
|
||||
->limit(10)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user