current state
This commit is contained in:
81
app/Http/Controllers/Legacy/PhotographyController.php
Normal file
81
app/Http/Controllers/Legacy/PhotographyController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Legacy;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Models\ContentType;
|
||||
|
||||
class PhotographyController extends Controller
|
||||
{
|
||||
protected ArtworkService $artworks;
|
||||
|
||||
public function __construct(ArtworkService $artworks)
|
||||
{
|
||||
$this->artworks = $artworks;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Legacy group mapping: Photography => id 3
|
||||
$group = 'Photography';
|
||||
$id = 3;
|
||||
|
||||
// Fetch legacy category info if available
|
||||
$category = null;
|
||||
try {
|
||||
if (Schema::hasTable('artworks_categories')) {
|
||||
$category = DB::table('artworks_categories')
|
||||
->select('category_name', 'rootid', 'section_id', 'description', 'category_id')
|
||||
->where('category_id', $id)
|
||||
->first();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$category = null;
|
||||
}
|
||||
|
||||
$page_title = $category->category_name ?? 'Photography';
|
||||
$tidy = $category->description ?? null;
|
||||
|
||||
$perPage = 40;
|
||||
|
||||
// Use ArtworkService to get artworks for the content type 'photography'
|
||||
try {
|
||||
$artworks = $this->artworks->getArtworksByContentType('photography', $perPage);
|
||||
} catch (\Throwable $e) {
|
||||
$artworks = collect();
|
||||
}
|
||||
|
||||
// Load subcategories (legacy) if available
|
||||
$subcategories = collect();
|
||||
try {
|
||||
if (Schema::hasTable('artworks_categories')) {
|
||||
$subcategories = DB::table('artworks_categories')->select('category_id','category_name')->where('rootid', $id)->orderBy('category_name')->get();
|
||||
if ($subcategories->count() == 0 && !empty($category->rootid)) {
|
||||
$subcategories = DB::table('artworks_categories')->select('category_id','category_name')->where('rootid', $category->rootid)->orderBy('category_name')->get();
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$subcategories = collect();
|
||||
}
|
||||
|
||||
// Fallback to authoritative categories table when legacy table is missing/empty
|
||||
if (! $subcategories || $subcategories->count() === 0) {
|
||||
$ct = ContentType::where('slug', 'photography')->first();
|
||||
if ($ct) {
|
||||
$subcategories = $ct->rootCategories()
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn ($c) => (object) ['category_id' => $c->id, 'category_name' => $c->name]);
|
||||
} else {
|
||||
$subcategories = collect();
|
||||
}
|
||||
}
|
||||
|
||||
return view('legacy.photography', compact('page_title','tidy','group','artworks','subcategories','id'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user