76 lines
2.6 KiB
PHP
76 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Artwork;
|
|
use App\Services\ArtworkService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Str;
|
|
|
|
class FeaturedArtworksController extends Controller
|
|
{
|
|
protected ArtworkService $artworks;
|
|
|
|
public function __construct(ArtworkService $artworks)
|
|
{
|
|
$this->artworks = $artworks;
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$perPage = 39;
|
|
|
|
$type = (int) ($request->query('type', 4));
|
|
|
|
$typeFilter = $type === 4 ? null : $type;
|
|
|
|
/** @var LengthAwarePaginator $artworks */
|
|
$artworks = $this->artworks->getFeaturedArtworks($typeFilter, $perPage);
|
|
|
|
$artworks->getCollection()->transform(function (Artwork $artwork) {
|
|
$primaryCategory = $artwork->categories->sortBy('sort_order')->first();
|
|
$categoryName = $primaryCategory->name ?? '';
|
|
$categorySlug = $primaryCategory->slug ?? '';
|
|
$gid = $primaryCategory ? ((int) $primaryCategory->id % 5) * 5 : 0;
|
|
$present = \App\Services\ThumbnailPresenter::present($artwork, 'md');
|
|
$username = $artwork->user->username ?? $artwork->user->name ?? 'Skinbase';
|
|
|
|
return (object) [
|
|
'id' => $artwork->id,
|
|
'name' => $artwork->title,
|
|
'slug' => $artwork->slug,
|
|
'url' => url('/art/' . $artwork->id . '/' . Str::slug($artwork->title ?? 'artwork')),
|
|
'content_type_name' => $primaryCategory?->contentType?->name ?? '',
|
|
'content_type_slug' => $primaryCategory?->contentType?->slug ?? '',
|
|
'category_name' => $categoryName,
|
|
'category_slug' => $categorySlug,
|
|
'gid_num' => $gid,
|
|
'thumb_url' => $present['url'],
|
|
'thumb_srcset' => $present['srcset'] ?? $present['url'],
|
|
'width' => $artwork->width,
|
|
'height' => $artwork->height,
|
|
'uname' => $artwork->user->name ?? 'Skinbase',
|
|
'username' => $username,
|
|
];
|
|
});
|
|
|
|
$artworkTypes = [
|
|
1 => 'Bronze Awards',
|
|
2 => 'Silver Awards',
|
|
3 => 'Gold Awards',
|
|
4 => 'Featured Artworks',
|
|
];
|
|
|
|
$pageTitle = $artworkTypes[$type] ?? 'Featured Artworks';
|
|
|
|
return view('web.featured-artworks', [
|
|
'artworks' => $artworks,
|
|
'type' => $type,
|
|
'artworkTypes' => $artworkTypes,
|
|
'page_title' => $pageTitle,
|
|
]);
|
|
}
|
|
}
|