ldc-bien-etre-animal/app/Http/Controllers/Front/CommunityController.php
2026-08-14 18:19:25 +02:00

100 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Front;
use Inertia\Inertia;
use Inertia\Response;
use Uwil\LaravelCommon\Controllers\CommonController;
class CommunityController extends CommonController
{
public function index(): Response
{
$trans = trans('gouvernance_page');
$communityTrans = trans('community_detail_page');
return Inertia::render('front/Pages/Community/Gouvernance', [
'sections' => collect($trans['sections'])->map(fn ($s) => [
'title' => $s['title'],
'bgColor' => $s['bg_color'],
'textColor' => $s['text_color'],
'rotation' => $s['rotation'],
'maxWidth' => $s['max_width'] ?? 'max-w-[1000px]',
'edgeOffset' => $s['edge_offset'] ?? '',
'texts' => $s['texts'],
'list' => $s['list'] ?? null,
'textAfterList' => $s['text_after_list'] ?? null,
'image' => $s['image'] ?? null,
'imageCaption' => $s['image_caption'] ?? null,
])->all(),
'communities' => collect($communityTrans['communities'])
->map(fn ($c, $key) => [
'number' => $c['number'],
'title' => $c['header']['title'],
'rotation' => $c['rotation'],
'href' => route('front.communities.show',$key),
])
->values()
->all(),
]);
}
public function show(string $slug): Response
{
$trans = trans('community_detail_page');
$community = $trans['communities'][$slug] ?? null;
if (!$community) {
abort(404);
}
return Inertia::render('front/Pages/Community/DetailCommunity', [
'metaTitle' => $community['meta']['title'],
'metaDescription' => $community['meta']['description'],
'headerTitle' => $community['header']['title'],
'heading' => $community['heading'],
'roleTitle' => $community['role_title'],
'roleText' => $community['role_text'],
'compositionTitle' => $community['composition_title'],
'compositionItems' => $community['composition_items'],
'closingText' => $community['closing_text'],
'testimonials' => $this->getTestimonials($community),
'otherCommunities' => $this->getOtherCommunities($trans, $slug),
'governanceHref' => route('front.gouvernance.index'),
]);
}
/**
* @param array<string, mixed> $community
* @return array<int, array<string, mixed>>
*/
private function getTestimonials(array $community): array
{
return collect($community['testimonials'] ?? [])
->map(fn($t) => [
'quote' => $t['quote'],
'authorName' => $t['author_name'],
'authorRole' => $t['author_role'],
'authorPhoto' => $t['author_photo'],
'logo' => $t['logo'],
])->all();
}
/**
* @param array<string, mixed> $trans
* @return array<int, array<string, mixed>>
*/
private function getOtherCommunities(array $trans, string $excludeSlug): array
{
return collect($trans['communities'])
->reject(fn($c, $key) => $key === $excludeSlug)
->map(fn($c, $key) => [
'number' => $c['number'],
'title' => $c['header']['title'],
'rotation' => $c['rotation'],
'href' => route('front.communities.show', $key),
])->values()->all();
}
}