*/ public array $content = []; /** @var array> */ public array $projects = []; public string $bg = ''; public int $limit = 0; public function mount(string $bg = '', int $limit = 0): void { $section = cms_theme_section('reference_projects'); $this->content = is_array($section) ? $section : []; $this->bg = $bg; $this->limit = $limit; $projects = $this->fromReferences(); if ($projects === []) { $projects = $this->fromBrandGalleries(); } $this->projects = $this->limit > 0 ? array_slice($projects, 0, $this->limit) : $projects; } /** * @return array> */ private function fromReferences(): array { $references = CmsReference::query()->published()->ordered()->get(); if ($references->isEmpty()) { return []; } $brands = CmsBrand::forFrontend(); $projects = []; foreach ($references as $reference) { $gallery = CmsReference::normalizeGallery($reference->gallery); $image = (string) ($reference->image ?: ($gallery[0]['image'] ?? '')); if ($image === '') { continue; } $projects[] = [ 'key' => 'ref-'.$reference->id, 'image' => $image, 'caption' => (string) $reference->title, 'meta' => implode(' · ', array_filter([$reference->location, $reference->year])), 'description' => (string) $reference->description, 'gallery' => array_values(array_filter($gallery, fn (array $item) => $item['image'] !== $image)), 'brands' => $reference->resolveBrands($brands), ]; } return $projects; } /** * @return array> */ private function fromBrandGalleries(): array { $projects = []; foreach (CmsBrand::forFrontend() as $slug => $brand) { foreach (CmsBrand::groupGallery($brand['gallery'] ?? [])['projects'] as $index => $item) { $projects[] = [ 'key' => $slug.'-'.$index, 'image' => $item['image'], 'caption' => $item['caption'], 'meta' => '', 'description' => '', 'gallery' => [], 'brands' => [[ 'slug' => $slug, 'name' => (string) ($brand['name'] ?? ''), 'link' => ! empty($brand['has_detail_page']) ? '/marken/'.$slug : null, ]], ]; } } return $projects; } public function render() { return view('livewire.web.components.sections.reference-projects'); } }