feat: ship creator journey v2 and profile updates
This commit is contained in:
@@ -7,31 +7,45 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Models\ContentType;
|
||||
use App\Services\ContentTypes\ContentTypeSlugResolver;
|
||||
|
||||
class PhotographyController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(ArtworkService $artworks)
|
||||
public function __construct(
|
||||
ArtworkService $artworks,
|
||||
private readonly ContentTypeSlugResolver $contentTypeResolver,
|
||||
)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Legacy group mapping: Photography => id 3
|
||||
// Determine the requested content type from the first URL segment (photography|wallpapers|skins)
|
||||
$segment = strtolower($request->segment(1) ?? 'photography');
|
||||
$contentSlug = in_array($segment, ['photography','wallpapers','skins','other']) ? $segment : 'photography';
|
||||
$resolution = $this->contentTypeResolver->resolve($segment);
|
||||
|
||||
// Human-friendly group name (used by legacy templates)
|
||||
$group = ucfirst($contentSlug);
|
||||
if (! $resolution->found() || $resolution->contentType === null) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$contentType = $resolution->contentType;
|
||||
$contentSlug = strtolower((string) $contentType->slug);
|
||||
|
||||
if ($resolution->requiresRedirect()) {
|
||||
$target = url('/' . $contentSlug);
|
||||
|
||||
if ($request->getQueryString()) {
|
||||
$target .= '?' . $request->getQueryString();
|
||||
}
|
||||
|
||||
return redirect()->to($target, 301);
|
||||
}
|
||||
|
||||
// Try to load legacy category id only for photography (legacy mapping); otherwise prefer authoritative ContentType
|
||||
$id = null;
|
||||
if ($contentSlug === 'photography') {
|
||||
$id = 3; // legacy root id for photography in oldSite (kept for backward compatibility)
|
||||
$id = 3;
|
||||
}
|
||||
|
||||
// Fetch legacy category info if available (only when we have an id)
|
||||
@@ -47,25 +61,20 @@ class PhotographyController extends Controller
|
||||
$category = null;
|
||||
}
|
||||
|
||||
// Page title and description: prefer legacy category when present, otherwise use ContentType data
|
||||
$ct = ContentType::where('slug', $contentSlug)->first();
|
||||
$page_title = $category->category_name ?? ($ct->name ?? ucfirst($contentSlug));
|
||||
$tidy = $category->description ?? ($ct->description ?? null);
|
||||
$page_title = $category->category_name ?? ($contentType->name ?? ucfirst($contentSlug));
|
||||
$tidy = $category->description ?? ($contentType->description ?? null);
|
||||
|
||||
$perPage = 40;
|
||||
$sort = (string) $request->get('sort', 'latest');
|
||||
|
||||
// Load artworks for the requested content type using standard pagination
|
||||
try {
|
||||
$artworks = $this->artworks->getArtworksByContentType($contentSlug, $perPage, $sort);
|
||||
} catch (\Throwable $e) {
|
||||
// Return an empty paginator so views using ->links() / ->firstItem() work
|
||||
$artworks = new \Illuminate\Pagination\LengthAwarePaginator([], 0, $perPage, 1, [
|
||||
'path' => url()->current(),
|
||||
]);
|
||||
}
|
||||
|
||||
// Load subcategories: prefer legacy table when id present and data exists, otherwise use ContentType root categories
|
||||
$subcategories = collect();
|
||||
try {
|
||||
if ($id !== null && Schema::hasTable('artworks_categories')) {
|
||||
@@ -79,18 +88,13 @@ class PhotographyController extends Controller
|
||||
}
|
||||
|
||||
if (! $subcategories || $subcategories->count() === 0) {
|
||||
if ($ct) {
|
||||
$subcategories = $ct->rootCategories()
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn ($c) => (object) ['category_id' => $c->id, 'category_name' => $c->name, 'slug' => $c->slug]);
|
||||
} else {
|
||||
$subcategories = collect();
|
||||
}
|
||||
$subcategories = $contentType->rootCategories()
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn ($c) => (object) ['category_id' => $c->id, 'category_name' => $c->name, 'slug' => $c->slug]);
|
||||
}
|
||||
|
||||
// Coerce collections to a paginator so the view's pagination helpers work
|
||||
if ($artworks instanceof \Illuminate\Database\Eloquent\Collection || $artworks instanceof \Illuminate\Support\Collection) {
|
||||
$page = (int) ($request->query('page', 1));
|
||||
$artworks = new \Illuminate\Pagination\LengthAwarePaginator($artworks->values()->all(), $artworks->count(), $perPage, $page, [
|
||||
@@ -99,11 +103,7 @@ class PhotographyController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
// Prepare variables for the modern content-type view
|
||||
$contentType = ContentType::where('slug', $contentSlug)->first();
|
||||
$rootCategories = $contentType
|
||||
? $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get()
|
||||
: collect();
|
||||
$rootCategories = $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get();
|
||||
|
||||
$page_meta_description = $tidy;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user