2024-05-17 23:54:03 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\View\Components;
|
|
|
|
|
|
|
|
use App\Models\Mod;
|
2024-07-15 23:13:51 -04:00
|
|
|
use App\Models\ModVersion;
|
2024-05-17 23:54:03 -04:00
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2024-07-15 23:13:51 -04:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2024-05-17 23:54:03 -04:00
|
|
|
use Illuminate\View\Component;
|
|
|
|
|
|
|
|
class ModListSection extends Component
|
|
|
|
{
|
2024-05-21 21:02:49 -04:00
|
|
|
public Collection $modsFeatured;
|
2024-05-22 01:00:37 -04:00
|
|
|
|
2024-05-17 23:54:03 -04:00
|
|
|
public Collection $modsLatest;
|
2024-05-22 01:00:37 -04:00
|
|
|
|
2024-05-17 23:54:03 -04:00
|
|
|
public Collection $modsUpdated;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
2024-05-21 21:02:49 -04:00
|
|
|
$this->modsFeatured = $this->fetchFeaturedMods();
|
2024-05-17 23:54:03 -04:00
|
|
|
$this->modsLatest = $this->fetchLatestMods();
|
|
|
|
$this->modsUpdated = $this->fetchUpdatedMods();
|
|
|
|
}
|
|
|
|
|
2024-05-21 21:02:49 -04:00
|
|
|
private function fetchFeaturedMods(): Collection
|
2024-05-17 23:54:03 -04:00
|
|
|
{
|
2024-07-15 23:13:51 -04:00
|
|
|
return Cache::remember('homepage-featured-mods', now()->addMinutes(5), function () {
|
|
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
|
|
|
|
->withTotalDownloads()
|
|
|
|
->with(['latestSptVersion', 'users:id,name'])
|
|
|
|
->where('featured', true)
|
|
|
|
->latest()
|
|
|
|
->limit(6)
|
|
|
|
->get();
|
|
|
|
});
|
2024-05-17 23:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function fetchLatestMods(): Collection
|
|
|
|
{
|
2024-07-15 23:13:51 -04:00
|
|
|
return Cache::remember('homepage-latest-mods', now()->addMinutes(5), function () {
|
|
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at'])
|
|
|
|
->withTotalDownloads()
|
|
|
|
->with(['latestSptVersion', 'users:id,name'])
|
|
|
|
->latest()
|
|
|
|
->limit(6)
|
|
|
|
->get();
|
|
|
|
});
|
2024-05-17 23:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function fetchUpdatedMods(): Collection
|
|
|
|
{
|
2024-07-15 23:13:51 -04:00
|
|
|
return Cache::remember('homepage-updated-mods', now()->addMinutes(5), function () {
|
|
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured'])
|
|
|
|
->withTotalDownloads()
|
|
|
|
->with(['lastUpdatedVersion', 'users:id,name'])
|
|
|
|
->orderByDesc(
|
|
|
|
ModVersion::select('updated_at')
|
|
|
|
->whereColumn('mod_id', 'mods.id')
|
|
|
|
->orderByDesc('updated_at')
|
|
|
|
->take(1)
|
|
|
|
)
|
|
|
|
->limit(6)
|
|
|
|
->get();
|
|
|
|
});
|
2024-05-17 23:54:03 -04:00
|
|
|
}
|
|
|
|
|
2024-07-04 22:10:48 -04:00
|
|
|
public function render(): View
|
|
|
|
{
|
|
|
|
return view('components.mod-list-section', [
|
|
|
|
'sections' => $this->getSections(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-05-17 23:54:03 -04:00
|
|
|
public function getSections(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
2024-05-21 21:02:49 -04:00
|
|
|
'title' => 'Featured Mods',
|
|
|
|
'mods' => $this->modsFeatured,
|
2024-05-24 17:06:02 -04:00
|
|
|
'versionScope' => 'latestSptVersion',
|
2024-05-17 23:54:03 -04:00
|
|
|
],
|
|
|
|
[
|
2024-05-24 17:06:02 -04:00
|
|
|
'title' => 'Newest Mods',
|
2024-05-17 23:54:03 -04:00
|
|
|
'mods' => $this->modsLatest,
|
2024-05-24 17:06:02 -04:00
|
|
|
'versionScope' => 'latestSptVersion',
|
2024-05-17 23:54:03 -04:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'title' => 'Recently Updated Mods',
|
|
|
|
'mods' => $this->modsUpdated,
|
2024-05-24 17:06:02 -04:00
|
|
|
'versionScope' => 'lastUpdatedVersion',
|
2024-05-17 23:54:03 -04:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|