ldc-legaulois/app/Http/Controllers/Fo/CommitmentController.php

89 lines
2.7 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers\Fo;
use App\Enums\StaticPageType;
use App\Http\Controllers\Controller;
use App\Models\StaticPage;
2026-09-25 16:25:31 +02:00
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
class CommitmentController extends Controller
{
2026-06-11 10:47:10 +02:00
/**
* Build the list of commitment navigation models from cached static pages.
*
* @return \Illuminate\Support\Collection<int, array{picto: array<string, string>, type: string, link: string}>
*/
2026-09-25 16:25:31 +02:00
private function getCommitmentModels(): Collection
2026-06-11 10:47:10 +02:00
{
return StaticPage::getCachedCommitmentsStaticPages()
2026-09-25 16:25:31 +02:00
->map(fn ($page) => [
'title' => $page->type->label(),
'picto' => $page->data['picto_navigation'] ?? null,
'activePicto' => $page->data['picto_banner'] ?? null,
'type' => $page->type->value,
'link' => route($page->type->routeForCommitments()),
2026-06-11 10:47:10 +02:00
])
2026-09-25 16:25:31 +02:00
->filter(fn ($item) => ! empty($item['picto']['value']))
2026-06-11 10:47:10 +02:00
->values();
}
/**
* Render a commitment page view with its static page model and navigation models.
*
2026-09-25 16:25:31 +02:00
* @param StaticPageType $type The commitment page type to load.
* @param string $view The fully qualified Blade view name to render.
2026-06-11 10:47:10 +02:00
*/
2026-09-25 16:25:31 +02:00
private function renderPage(StaticPageType $type, string $view): View
2026-06-11 10:47:10 +02:00
{
$staticPageModel = StaticPage::getCachedStaticPage($type);
$staticPageModel->load(['sections.blocks', 'sections.pictos']);
return view($view, [
'staticPageModel' => $staticPageModel,
'commitmentModels' => $this->getCommitmentModels(),
]);
}
/**
* Display the given commitment page.
*/
2026-09-25 16:25:31 +02:00
public function getRestpectEarthPage(): View
{
2026-06-11 10:47:10 +02:00
return $this->renderPage(StaticPageType::respectTheEarth, 'fo.pages.commitments.respect');
}
2026-06-11 10:47:10 +02:00
/**
* Display the given commitment page.
*/
2026-09-25 16:25:31 +02:00
public function getLivingToghether(): View
{
2026-06-11 10:47:10 +02:00
return $this->renderPage(StaticPageType::forLivingTogether, 'fo.pages.commitments.life');
}
2026-06-11 10:47:10 +02:00
/**
* Display the given commitment brand poultry page.
*/
2026-09-25 16:25:31 +02:00
public function getBrandPoultry(): View
{
2026-06-11 10:47:10 +02:00
return $this->renderPage(StaticPageType::poultryBrand, 'fo.pages.commitments.brand');
}
/**
* Display the given page.
*/
2026-09-25 16:25:31 +02:00
public function getRaiseSustainably(): View
{
2026-06-11 10:47:10 +02:00
return $this->renderPage(StaticPageType::raiseSustainably, 'fo.pages.commitments.raise');
}
/**
* Display the given page.
*/
2026-09-25 16:25:31 +02:00
public function getFeedProperly(): View
2026-06-11 10:47:10 +02:00
{
return $this->renderPage(StaticPageType::feedProperly, 'fo.pages.commitments.eat');
}
}