Commit workspace changes
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Leaderboard;
|
||||
use App\Models\Tag;
|
||||
use App\Services\ArtworkSearchService;
|
||||
use App\Services\EarlyGrowth\EarlyGrowth;
|
||||
@@ -14,10 +15,12 @@ use App\Services\UserPreferenceService;
|
||||
use App\Support\AvatarUrl;
|
||||
use App\Models\Collection as CollectionModel;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Database\QueryException;
|
||||
use cPad\Plugins\News\Models\NewsArticle;
|
||||
|
||||
/**
|
||||
* HomepageService
|
||||
@@ -45,6 +48,8 @@ final class HomepageService
|
||||
private readonly CollectionDiscoveryService $collectionDiscovery,
|
||||
private readonly CollectionService $collectionService,
|
||||
private readonly CollectionSurfaceService $collectionSurfaces,
|
||||
private readonly GroupDiscoveryService $groupDiscovery,
|
||||
private readonly LeaderboardService $leaderboards,
|
||||
) {}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
@@ -65,6 +70,7 @@ final class HomepageService
|
||||
'collections_trending' => $this->getTrendingCollections(),
|
||||
'collections_editorial' => $this->getEditorialCollections(),
|
||||
'collections_community' => $this->getCommunityCollections(),
|
||||
'groups' => $this->getHomepageGroups(),
|
||||
'tags' => $this->getPopularTags(),
|
||||
'creators' => $this->getCreatorSpotlight(),
|
||||
'news' => $this->getNews(),
|
||||
@@ -101,6 +107,7 @@ final class HomepageService
|
||||
'collections_trending' => $this->getTrendingCollections(),
|
||||
'collections_editorial' => $this->getEditorialCollections(),
|
||||
'collections_community' => $this->getCommunityCollections(),
|
||||
'groups' => $this->getHomepageGroups($user),
|
||||
'by_tags' => $this->getByTags($prefs['top_tags'] ?? []),
|
||||
'by_categories' => $this->getByCategories($prefs['top_categories'] ?? []),
|
||||
'suggested_creators' => $this->getSuggestedCreators($user, $prefs),
|
||||
@@ -236,6 +243,21 @@ final class HomepageService
|
||||
);
|
||||
}
|
||||
|
||||
public function getHomepageGroups(?\App\Models\User $viewer = null): array
|
||||
{
|
||||
$featured = $this->groupDiscovery->surfaceCards($viewer, 'featured', 4);
|
||||
$spotlight = $featured[0] ?? null;
|
||||
|
||||
return [
|
||||
'spotlight' => $spotlight,
|
||||
'featured' => $featured,
|
||||
'recruiting' => $this->groupDiscovery->surfaceCards($viewer, 'recruiting', 4),
|
||||
'rising' => $this->groupDiscovery->surfaceCards($viewer, 'new_rising', 4),
|
||||
'leaderboard' => $this->leaderboards->getLeaderboard(Leaderboard::TYPE_GROUP, Leaderboard::PERIOD_MONTHLY, 5),
|
||||
'count' => $this->groupDiscovery->publicGroupCount(),
|
||||
];
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
// Sections
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
@@ -515,6 +537,24 @@ final class HomepageService
|
||||
{
|
||||
return Cache::remember("homepage.news.{$limit}", self::CACHE_TTL, function () use ($limit): array {
|
||||
try {
|
||||
$articles = NewsArticle::query()
|
||||
->with('category')
|
||||
->published()
|
||||
->editorialOrder()
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
if ($articles->isNotEmpty()) {
|
||||
return $articles->map(fn (NewsArticle $article) => [
|
||||
'id' => $article->id,
|
||||
'title' => $article->title,
|
||||
'date' => $article->published_at,
|
||||
'url' => route('news.show', ['slug' => $article->slug]),
|
||||
'eyebrow' => $article->category?->name ?: $article->type_label,
|
||||
'excerpt' => Str::limit(strip_tags((string) ($article->excerpt ?: $article->rendered_content)), 120),
|
||||
])->values()->all();
|
||||
}
|
||||
|
||||
$items = DB::table('forum_threads as t')
|
||||
->leftJoin('forum_categories as c', 'c.id', '=', 't.category_id')
|
||||
->select('t.id', 't.title', 't.created_at', 't.slug as thread_slug')
|
||||
@@ -528,10 +568,10 @@ final class HomepageService
|
||||
->get();
|
||||
|
||||
return $items->map(fn ($row) => [
|
||||
'id' => $row->id,
|
||||
'id' => $row->id,
|
||||
'title' => $row->title,
|
||||
'date' => $row->created_at,
|
||||
'url' => '/forum/thread/' . $row->id . '-' . ($row->thread_slug ?? 'post'),
|
||||
'date' => $row->created_at,
|
||||
'url' => '/forum/thread/' . $row->id . '-' . ($row->thread_slug ?? 'post'),
|
||||
])->values()->all();
|
||||
} catch (QueryException $e) {
|
||||
Log::warning('HomepageService::getNews DB error', [
|
||||
|
||||
Reference in New Issue
Block a user