Wire admin studio SSR and search infrastructure
This commit is contained in:
@@ -84,16 +84,29 @@ class GroupReputationService
|
||||
|
||||
public function trustSignals(Group $group): array
|
||||
{
|
||||
$releaseCount = (int) $group->releases()->where('status', GroupRelease::STATUS_RELEASED)->count();
|
||||
$recentReleaseCount = (int) $group->releases()
|
||||
->where('status', GroupRelease::STATUS_RELEASED)
|
||||
->where('released_at', '>=', now()->subDays(45))
|
||||
->count();
|
||||
$activeMembers = (int) $group->members()->where('status', Group::STATUS_ACTIVE)->count() + 1;
|
||||
$approvedArtworks = (int) Artwork::query()
|
||||
->where('group_id', $group->id)
|
||||
->where('group_review_status', 'approved')
|
||||
->count();
|
||||
$releaseCount = isset($group->public_releases_count)
|
||||
? (int) $group->public_releases_count
|
||||
: (int) $group->releases()->where('status', GroupRelease::STATUS_RELEASED)->count();
|
||||
|
||||
$recentReleaseCount = isset($group->recent_public_releases_count)
|
||||
? (int) $group->recent_public_releases_count
|
||||
: (int) $group->releases()
|
||||
->where('status', GroupRelease::STATUS_RELEASED)
|
||||
->where('released_at', '>=', now()->subDays(45))
|
||||
->count();
|
||||
|
||||
$activeMembers = (isset($group->active_members_count)
|
||||
? (int) $group->active_members_count
|
||||
: ($group->relationLoaded('members')
|
||||
? (int) $group->members->where('status', Group::STATUS_ACTIVE)->count()
|
||||
: (int) $group->members()->where('status', Group::STATUS_ACTIVE)->count())) + 1;
|
||||
|
||||
$approvedArtworks = isset($group->approved_group_artworks_count)
|
||||
? (int) $group->approved_group_artworks_count
|
||||
: (int) Artwork::query()
|
||||
->where('group_id', $group->id)
|
||||
->where('group_review_status', 'approved')
|
||||
->count();
|
||||
|
||||
$signals = [];
|
||||
|
||||
@@ -165,10 +178,15 @@ class GroupReputationService
|
||||
|
||||
public function groupBadges(Group $group, int $limit = 6): array
|
||||
{
|
||||
return $group->badges()
|
||||
->latest('awarded_at')
|
||||
->limit(max(1, min(24, $limit)))
|
||||
->get()
|
||||
$badges = $group->relationLoaded('badges')
|
||||
? $group->badges->sortByDesc(fn (GroupBadge $badge) => $badge->awarded_at?->getTimestamp() ?? 0)
|
||||
->take(max(1, min(24, $limit)))
|
||||
: $group->badges()
|
||||
->latest('awarded_at')
|
||||
->limit(max(1, min(24, $limit)))
|
||||
->get();
|
||||
|
||||
return $badges
|
||||
->map(fn (GroupBadge $badge): array => [
|
||||
'key' => (string) $badge->badge_key,
|
||||
'label' => $this->badgeLabel('group', (string) $badge->badge_key),
|
||||
@@ -382,16 +400,40 @@ class GroupReputationService
|
||||
private function awardMemberBadges(Group $group): void
|
||||
{
|
||||
$stats = GroupContributorStat::query()->where('group_id', $group->id)->get();
|
||||
$userIds = $stats->pluck('user_id')->map(static fn ($id): int => (int) $id)->unique()->values();
|
||||
|
||||
$projectLeadIds = GroupProject::query()
|
||||
->where('group_id', $group->id)
|
||||
->whereIn('lead_user_id', $userIds)
|
||||
->pluck('lead_user_id')
|
||||
->map(static fn ($id): int => (int) $id)
|
||||
->flip();
|
||||
|
||||
$assetCounts = $group->assets()
|
||||
->selectRaw('uploaded_by_user_id, COUNT(*) as aggregate')
|
||||
->whereIn('uploaded_by_user_id', $userIds)
|
||||
->groupBy('uploaded_by_user_id')
|
||||
->pluck('aggregate', 'uploaded_by_user_id');
|
||||
|
||||
$foundingMemberIds = GroupMember::query()
|
||||
->where('group_id', $group->id)
|
||||
->whereIn('user_id', $userIds)
|
||||
->when($group->created_at, fn ($query) => $query->where('accepted_at', '<=', $group->created_at->copy()->addDays(30)))
|
||||
->pluck('user_id')
|
||||
->map(static fn ($id): int => (int) $id)
|
||||
->flip();
|
||||
|
||||
foreach ($stats as $stat) {
|
||||
$userId = (int) $stat->user_id;
|
||||
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'first_group_contribution', (int) $stat->credited_artworks_count >= 1);
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'ten_group_contributions', (int) $stat->credited_artworks_count >= 10);
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'release_contributor', (int) $stat->release_count >= 1);
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'project_lead', GroupProject::query()->where('group_id', $group->id)->where('lead_user_id', $stat->user_id)->exists());
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'reliable_reviewer', (int) $stat->review_actions_count >= 5);
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'long_term_collaborator', ((int) $stat->project_count + (int) $stat->release_count) >= 5);
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'founding_member', $this->isFoundingMember($group, (int) $stat->user_id));
|
||||
$this->awardMemberBadge($group, (int) $stat->user_id, 'asset_builder', $group->assets()->where('uploaded_by_user_id', $stat->user_id)->count() >= 3);
|
||||
$this->awardMemberBadge($group, $userId, 'project_lead', $projectLeadIds->has($userId));
|
||||
$this->awardMemberBadge($group, $userId, 'reliable_reviewer', (int) $stat->review_actions_count >= 5);
|
||||
$this->awardMemberBadge($group, $userId, 'long_term_collaborator', ((int) $stat->project_count + (int) $stat->release_count) >= 5);
|
||||
$this->awardMemberBadge($group, $userId, 'founding_member', (int) $group->owner_user_id === $userId || $foundingMemberIds->has($userId));
|
||||
$this->awardMemberBadge($group, $userId, 'asset_builder', (int) ($assetCounts[$userId] ?? 0) >= 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user