93 lines
3.1 KiB
PHP
93 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\StaticPage;
|
|
|
|
class CommitmentController extends Controller
|
|
{
|
|
|
|
/**
|
|
* 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}>
|
|
*/
|
|
private function getCommitmentModels(): \Illuminate\Support\Collection
|
|
{
|
|
return StaticPage::getCachedCommitmentsStaticPages()
|
|
->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()),
|
|
])
|
|
->filter(fn($item) => !empty($item['picto']['value']))
|
|
->values();
|
|
}
|
|
|
|
/**
|
|
* Render a commitment page view with its static page model and navigation models.
|
|
*
|
|
* @param StaticPageType $type The commitment page type to load.
|
|
* @param string $view The fully qualified Blade view name to render.
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
private function renderPage(StaticPageType $type, string $view): \Illuminate\Contracts\View\View
|
|
{
|
|
$staticPageModel = StaticPage::getCachedStaticPage($type);
|
|
$staticPageModel->load(['sections.blocks', 'sections.pictos']);
|
|
|
|
return view($view, [
|
|
'staticPageModel' => $staticPageModel,
|
|
'commitmentModels' => $this->getCommitmentModels(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the given commitment page.
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function getRestpectEarthPage(): \Illuminate\Contracts\View\View
|
|
{
|
|
return $this->renderPage(StaticPageType::respectTheEarth, 'fo.pages.commitments.respect');
|
|
}
|
|
|
|
/**
|
|
* Display the given commitment page.
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function getLivingToghether(): \Illuminate\Contracts\View\View
|
|
{
|
|
return $this->renderPage(StaticPageType::forLivingTogether, 'fo.pages.commitments.life');
|
|
}
|
|
|
|
/**
|
|
* Display the given commitment brand poultry page.
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function getBrandPoultry(): \Illuminate\Contracts\View\View
|
|
{
|
|
return $this->renderPage(StaticPageType::poultryBrand, 'fo.pages.commitments.brand');
|
|
}
|
|
|
|
/**
|
|
* Display the given page.
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function getRaiseSustainably(): \Illuminate\Contracts\View\View
|
|
{
|
|
return $this->renderPage(StaticPageType::raiseSustainably, 'fo.pages.commitments.raise');
|
|
}
|
|
|
|
/**
|
|
* Display the given page.
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function getFeedProperly(): \Illuminate\Contracts\View\View
|
|
{
|
|
return $this->renderPage(StaticPageType::feedProperly, 'fo.pages.commitments.eat');
|
|
}
|
|
}
|