ldc-legaulois/app/Http/Controllers/BreedingPageController.php

108 lines
3.6 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers;
use App\Enums\BreedingPageType;
use App\Enums\GeneralConfigType;
Ticket 689 Squashed commit of the following: commit e3861caa2e7046123be8adb2355e6c8b36e75f42 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:16:47 2022 +0100 Ticket689 : fix banner/title articles on breeding page commit 74a0c75844904b0639a86ed24c5ab9bfeedcd050 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:12:40 2022 +0100 Ticket677 : add migration for imgs on breeding page commit 48360d764cfb6de74d4c48ba3e5fe6def02ee673 Merge: 0eda4880 a120f51e Author: Olivier Legat <olivier.legat@ldc.fr> Date: Wed Mar 9 12:05:29 2022 +0000 Merge branch 'ticket689' of https://voight001.lesidc.com/legaulois2020 into ticket689 commit 0eda4880a9a39947009eb6137f2d493aa8cbfe4c Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit e80793ebb6efab07147200ad8b072eccca366624 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit 5f406faf0f961456f776969858fa95b80b15388d Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 89e129fcde9230912a26ccf0cdbe87e8a3a60c63 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit c4688e28870a228b38ecc13091296e0005e0e04a Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show) commit a120f51eb42c8a79b92cf41255026597179dd23e Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit 3d5c8a6251abb7a45ac6b3db777b8837aa64f2bf Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit bc6f67f4a340488eed2d86b198bd79e1541649e5 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 3493c2806696c4ff1321fadb08a1648fd4704e40 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit d7c63486ecdc0f91b7fb8d4a5a851e4b1e9fdc10 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show)
2022-03-14 14:09:43 +00:00
use App\Enums\InputType;
use App\Models\BreedingPage;
2022-05-31 16:44:41 +02:00
use App\Models\GeneralConfig;
use Illuminate\Support\Facades\View;
class BreedingPageController extends Controller
{
2022-05-31 16:44:41 +02:00
/**
* BreedingPageController
*/
public function __construct()
{
2022-05-31 16:44:41 +02:00
$this->middleware(function ($request, $next) {
View::share('generalConfig', GeneralConfig::getCachedConfig(
GeneralConfigType::breedingPage()
));
return $next($request);
});
}
2022-05-31 16:44:41 +02:00
/**
* Show Breeding Page index
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function index()
{
return view('front.breeding-page.index');
}
2022-05-31 16:44:41 +02:00
/**
* Show Breeding Pages within a type
*
* @param BreedingPageType $pageType
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function list(BreedingPageType $pageType)
{
2023-06-26 15:57:38 +02:00
$pages = BreedingPage::where('type', $pageType)->whereStatus(true)->get();
$bannerUrl = $this->getBannerUrlFromGeneralConfig($pageType);
2022-07-13 10:06:50 +00:00
$headerText = $this->getTextHeaderFromGeneralConfig($pageType);
Ticket 689 Squashed commit of the following: commit e3861caa2e7046123be8adb2355e6c8b36e75f42 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:16:47 2022 +0100 Ticket689 : fix banner/title articles on breeding page commit 74a0c75844904b0639a86ed24c5ab9bfeedcd050 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:12:40 2022 +0100 Ticket677 : add migration for imgs on breeding page commit 48360d764cfb6de74d4c48ba3e5fe6def02ee673 Merge: 0eda4880 a120f51e Author: Olivier Legat <olivier.legat@ldc.fr> Date: Wed Mar 9 12:05:29 2022 +0000 Merge branch 'ticket689' of https://voight001.lesidc.com/legaulois2020 into ticket689 commit 0eda4880a9a39947009eb6137f2d493aa8cbfe4c Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit e80793ebb6efab07147200ad8b072eccca366624 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit 5f406faf0f961456f776969858fa95b80b15388d Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 89e129fcde9230912a26ccf0cdbe87e8a3a60c63 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit c4688e28870a228b38ecc13091296e0005e0e04a Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show) commit a120f51eb42c8a79b92cf41255026597179dd23e Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit 3d5c8a6251abb7a45ac6b3db777b8837aa64f2bf Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit bc6f67f4a340488eed2d86b198bd79e1541649e5 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 3493c2806696c4ff1321fadb08a1648fd4704e40 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit d7c63486ecdc0f91b7fb8d4a5a851e4b1e9fdc10 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show)
2022-03-14 14:09:43 +00:00
2022-07-13 10:06:50 +00:00
return view('front.breeding-page.list', compact('pages', 'pageType', 'bannerUrl', 'headerText'));
}
2022-05-31 16:44:41 +02:00
/**
* Show specific breeder page
*
* @param BreedingPageType $pageType
* @param BreedingPage $page
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function show(BreedingPageType $pageType, BreedingPage $page)
{
2022-07-13 10:06:50 +00:00
$bannerUrl = $this->getBannerUrlFromGeneralConfig($pageType);
$headerText = $this->getTextHeaderFromGeneralConfig($pageType);
return view('front.breeding-page.show', compact('page', 'pageType', 'bannerUrl', 'headerText'));
2022-05-31 16:44:41 +02:00
}
Ticket 689 Squashed commit of the following: commit e3861caa2e7046123be8adb2355e6c8b36e75f42 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:16:47 2022 +0100 Ticket689 : fix banner/title articles on breeding page commit 74a0c75844904b0639a86ed24c5ab9bfeedcd050 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:12:40 2022 +0100 Ticket677 : add migration for imgs on breeding page commit 48360d764cfb6de74d4c48ba3e5fe6def02ee673 Merge: 0eda4880 a120f51e Author: Olivier Legat <olivier.legat@ldc.fr> Date: Wed Mar 9 12:05:29 2022 +0000 Merge branch 'ticket689' of https://voight001.lesidc.com/legaulois2020 into ticket689 commit 0eda4880a9a39947009eb6137f2d493aa8cbfe4c Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit e80793ebb6efab07147200ad8b072eccca366624 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit 5f406faf0f961456f776969858fa95b80b15388d Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 89e129fcde9230912a26ccf0cdbe87e8a3a60c63 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit c4688e28870a228b38ecc13091296e0005e0e04a Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show) commit a120f51eb42c8a79b92cf41255026597179dd23e Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit 3d5c8a6251abb7a45ac6b3db777b8837aa64f2bf Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit bc6f67f4a340488eed2d86b198bd79e1541649e5 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 3493c2806696c4ff1321fadb08a1648fd4704e40 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit d7c63486ecdc0f91b7fb8d4a5a851e4b1e9fdc10 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show)
2022-03-14 14:09:43 +00:00
2022-05-31 16:44:41 +02:00
/**
* Get banner url from general config
*
* @param BreedingPageType $pageType
* @return string
*/
private function getBannerUrlFromGeneralConfig(BreedingPageType $pageType): string
{
$generalConfig = GeneralConfig::getCachedConfig(GeneralConfigType::breedingPage());
/** @var string */
$key = \strval(collect($generalConfig->data)->filter(function (array $input) use ($pageType) {
return $input['inputType']['value'] === InputType::string()->value and
isset($input['type']) and
$input['type']['value'] === $pageType->value;
})->keys()->first());
Ticket 689 Squashed commit of the following: commit e3861caa2e7046123be8adb2355e6c8b36e75f42 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:16:47 2022 +0100 Ticket689 : fix banner/title articles on breeding page commit 74a0c75844904b0639a86ed24c5ab9bfeedcd050 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 10 16:12:40 2022 +0100 Ticket677 : add migration for imgs on breeding page commit 48360d764cfb6de74d4c48ba3e5fe6def02ee673 Merge: 0eda4880 a120f51e Author: Olivier Legat <olivier.legat@ldc.fr> Date: Wed Mar 9 12:05:29 2022 +0000 Merge branch 'ticket689' of https://voight001.lesidc.com/legaulois2020 into ticket689 commit 0eda4880a9a39947009eb6137f2d493aa8cbfe4c Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit e80793ebb6efab07147200ad8b072eccca366624 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit 5f406faf0f961456f776969858fa95b80b15388d Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 89e129fcde9230912a26ccf0cdbe87e8a3a60c63 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit c4688e28870a228b38ecc13091296e0005e0e04a Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show) commit a120f51eb42c8a79b92cf41255026597179dd23e Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Mon Mar 7 11:46:17 2022 +0100 Ticket 677 : add json key 'alt' in mini-crud commit 3d5c8a6251abb7a45ac6b3db777b8837aa64f2bf Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:42:35 2022 +0100 add drop-down breeding menu in main header commit bc6f67f4a340488eed2d86b198bd79e1541649e5 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:40:33 2022 +0100 supp header articles breeding pages commit 3493c2806696c4ff1321fadb08a1648fd4704e40 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Fri Mar 4 09:39:53 2022 +0100 fix title/banner breeding pages commit d7c63486ecdc0f91b7fb8d4a5a851e4b1e9fdc10 Author: Alexis Gousseau <alexis.gousseau@ldc.fr> Date: Thu Mar 3 12:56:42 2022 +0100 adds breadcrumb on breeding pages (index, list, show)
2022-03-14 14:09:43 +00:00
2022-05-31 16:44:41 +02:00
/** @var string banner url or empty */
return collect($generalConfig->data)->get(str_replace('_text', '_img2', $key))['value'] ?? '';
}
2022-07-13 10:06:50 +00:00
/**
* Get text header from general config
*
* @param BreedingPageType $pageType
* @return string
*/
private function getTextHeaderFromGeneralConfig(BreedingPageType $pageType): string
{
$generalConfig = GeneralConfig::getCachedConfig(GeneralConfigType::breedingPage());
/** @var string */
$key = \strval(collect($generalConfig->data)->filter(function (array $input) use ($pageType) {
return $input['inputType']['value'] === InputType::string()->value and
isset($input['type']) and
$input['type']['value'] === $pageType->value;
})->keys()->first());
/** @var string banner url or empty */
return collect($generalConfig->data)->get(str_replace('_text', '_img2', $key))['text'] ?? '';
}
}