ldc-legaulois/app/Http/Controllers/Fo/BreedingController.php
2026-05-07 15:51:26 +02:00

115 lines
3.9 KiB
PHP

<?php
namespace App\Http\Controllers\Fo;
use App\Enums\StaticPageType;
use App\Http\Controllers\Controller;
use App\Lib\Helpers\CollectionHelper;
use App\Models\CategoryApproach;
use App\Models\NewsBreeding;
use App\Models\OcbBreeder;
use App\Models\SectionApproach;
use App\Models\StaticPage;
use Illuminate\Database\Eloquent\Builder;
class BreedingController extends Controller
{
/**
* Display the given breeding page.
*
* @param \App\Models\StaticPage $staticPage
* @return \Illuminate\Contracts\View\View
*/
public function breedingPage(StaticPage $staticPage): \Illuminate\Contracts\View\View
{
$newsBreedingModels = NewsBreeding::getPublishedOrderedForType($staticPage);
return view('fo.pages.breeding.show', [
'staticPageModel' => $staticPage,
'newsBreedingModels' => $newsBreedingModels,
]);
}
/**
* Display the given breeding page.
*
* @return \Illuminate\Contracts\View\View
*/
public function ocbBreederPage(): \Illuminate\Contracts\View\View
{
$ocbBreederModels = OcbBreeder::getOcbBreederCards();
$staticPage = StaticPage::query()->where('type', StaticPageType::ouiCBon)->first();
$categoryApproachModels = CategoryApproach::all();
$sections = SectionApproach::query()
->with('category')
->where('page_id', $staticPage->id)
->get()
->groupBy(fn($section) => $section->category?->name);
return view('fo.pages.breeding.oui-c-est-bon', [
'ocbBreederModels' => $ocbBreederModels,
'staticPageModel' => $staticPage,
'categoryApproachModels' => $categoryApproachModels,
'sections' => $sections
]);
}
/**
* Display the given breeding article.
*
* @param \App\Models\StaticPage $staticPage
* @param \App\Models\NewsBreeding $newsBreeding
* @return \Illuminate\Contracts\View\View
*/
public function breedingArticle(StaticPage $staticPage, NewsBreeding $newsBreeding): \Illuminate\Contracts\View\View
{
$asideNewsModels = NewsBreeding::query()
->whereHas('staticpage', function (Builder $query) use ($staticPage) {
$query->where('type', $staticPage->type);
})
->where('published', true)
->whereNot('id', $newsBreeding->getKey())
->inRandomOrder()
->limit(2)
->get();
return view('fo.pages.breeding.article', [
'staticPageModel' => $staticPage,
'newsBreedingModel' => $newsBreeding,
'asideNewsModels' => $asideNewsModels
]);
}
/**
* Display the given breeding page.
*
* @return \Illuminate\Contracts\View\View
*/
public function exitOutsidePage(): \Illuminate\Contracts\View\View
{
$staticPage = StaticPage::query()->where('type', StaticPageType::exitOutside)->first();
$sliderImages = CollectionHelper::mapSlidesToFields($staticPage->data);
$categoryApproachModels = CategoryApproach::all();
$sections = SectionApproach::query()
->with('category')
->where('page_id', $staticPage->id)
->get()
->groupBy(fn($section) => $section->category?->name);
return view('fo.pages.breeding.sortant-a-l-exterieur', [
'staticPageModel' => $staticPage,
'sliderImages' => $sliderImages,
'categoryApproachModels' => $categoryApproachModels,
'sections' => $sections,
]);
}
/**
* Display our farms page.
*
* @return \Illuminate\Contracts\View\View
*/
public function ourFarmsPage(): \Illuminate\Contracts\View\View
{
$staticPage = StaticPage::query()->where('type', StaticPageType::ourFarms)->first();
return view('fo.pages.breeding.index', ['staticPageModel' => $staticPage]);
}
}