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-08-31 01:19:22 -04:00
|
|
|
use Illuminate\Support\Facades\DB;
|
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-08-31 01:19:22 -04:00
|
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'downloads'])
|
2024-08-29 15:46:10 -04:00
|
|
|
->with([
|
|
|
|
'latestVersion',
|
|
|
|
'latestVersion.latestSptVersion:id,version,color_class',
|
|
|
|
'users:id,name',
|
|
|
|
'license:id,name,link',
|
|
|
|
])
|
2024-08-31 01:19:22 -04:00
|
|
|
->whereFeatured(true)
|
|
|
|
->inRandomOrder()
|
2024-08-29 15:46:10 -04:00
|
|
|
->limit(6)
|
|
|
|
->get();
|
2024-05-17 23:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function fetchLatestMods(): Collection
|
|
|
|
{
|
2024-08-31 01:19:22 -04:00
|
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at', 'downloads'])
|
2024-08-29 15:46:10 -04:00
|
|
|
->with([
|
|
|
|
'latestVersion',
|
|
|
|
'latestVersion.latestSptVersion:id,version,color_class',
|
|
|
|
'users:id,name',
|
|
|
|
'license:id,name,link',
|
|
|
|
])
|
|
|
|
->latest()
|
|
|
|
->limit(6)
|
|
|
|
->get();
|
2024-05-17 23:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function fetchUpdatedMods(): Collection
|
|
|
|
{
|
2024-08-31 01:19:22 -04:00
|
|
|
return Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'downloads'])
|
2024-08-29 15:46:10 -04:00
|
|
|
->with([
|
2024-08-31 01:19:22 -04:00
|
|
|
'lastUpdatedVersion',
|
|
|
|
'lastUpdatedVersion.latestSptVersion:id,version,color_class',
|
2024-08-29 15:46:10 -04:00
|
|
|
'users:id,name',
|
|
|
|
'license:id,name,link',
|
|
|
|
])
|
2024-08-31 01:19:22 -04:00
|
|
|
->joinSub(
|
|
|
|
ModVersion::select('mod_id', DB::raw('MAX(updated_at) as latest_updated_at'))->groupBy('mod_id'),
|
|
|
|
'latest_versions',
|
|
|
|
'mods.id',
|
|
|
|
'=',
|
|
|
|
'latest_versions.mod_id'
|
2024-08-29 15:46:10 -04:00
|
|
|
)
|
2024-08-31 01:19:22 -04:00
|
|
|
->orderByDesc('latest_versions.latest_updated_at')
|
2024-08-29 15:46:10 -04:00
|
|
|
->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-08-31 01:19:22 -04:00
|
|
|
'title' => __('Featured Mods'),
|
2024-05-21 21:02:49 -04:00
|
|
|
'mods' => $this->modsFeatured,
|
2024-07-23 21:21:55 -04:00
|
|
|
'versionScope' => 'latestVersion',
|
2024-09-09 16:20:54 -04:00
|
|
|
'link' => '/mods?featured=only',
|
2024-05-17 23:54:03 -04:00
|
|
|
],
|
|
|
|
[
|
2024-08-31 01:19:22 -04:00
|
|
|
'title' => __('Newest Mods'),
|
2024-05-17 23:54:03 -04:00
|
|
|
'mods' => $this->modsLatest,
|
2024-07-23 21:21:55 -04:00
|
|
|
'versionScope' => 'latestVersion',
|
2024-09-09 16:20:54 -04:00
|
|
|
'link' => '/mods',
|
2024-05-17 23:54:03 -04:00
|
|
|
],
|
|
|
|
[
|
2024-08-31 01:19:22 -04:00
|
|
|
'title' => __('Recently Updated Mods'),
|
2024-05-17 23:54:03 -04:00
|
|
|
'mods' => $this->modsUpdated,
|
2024-05-24 17:06:02 -04:00
|
|
|
'versionScope' => 'lastUpdatedVersion',
|
2024-09-09 16:20:54 -04:00
|
|
|
'link' => '/mods?order=updated',
|
2024-05-17 23:54:03 -04:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|