diff --git a/app/Http/Controllers/Bo/SlideController.php b/app/Http/Controllers/Bo/SlideController.php index 06b59f5..fb2b69b 100644 --- a/app/Http/Controllers/Bo/SlideController.php +++ b/app/Http/Controllers/Bo/SlideController.php @@ -38,7 +38,7 @@ class SlideController extends Controller $slideModels, $search, null, - 'slider', + 'type', 'title', ); } diff --git a/app/Models/Section.php b/app/Models/Section.php index 608df75..2ed3eb5 100644 --- a/app/Models/Section.php +++ b/app/Models/Section.php @@ -12,6 +12,8 @@ use App\Traits\Models\MiniCrudModel; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; +use App\Models\StaticPage; +use App\Enums\StaticPageType; /** * @property \App\Enums\Sections\PageSectionEnum $section Slider that contains the slide. @@ -443,6 +445,36 @@ class Section extends Model return $data; } + /** + * Returns the list of sections for a page type. + * + * @param \App\Enums\StaticPageType $type + * @return \Illuminate\Database\Eloquent\Collection + */ + public static function getSections(StaticPageType $type): \Illuminate\Database\Eloquent\Collection + { + $staticPageModel = StaticPage::query()->where('type', $type)->first(); + $sectionModels = self::where('page_id', $staticPageModel->id)->get(); + + return $sectionModels; + } + + /** + * Get the active section for a type page + * + * @param \App\Enums\StaticPageType $type + * @return boolean + */ + public static function isActive(StaticPageType $type) + { + $staticPage = StaticPage::getStaticPage($type); + return $staticPage->sections->contains( + function ($section) { + return request()->is("bo/sections/$section->id/edit"); + } + ); + } + // * RELATIONS /** diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php index 1fcffdd..1f5e157 100644 --- a/app/Models/StaticPage.php +++ b/app/Models/StaticPage.php @@ -150,4 +150,28 @@ class StaticPage extends Model ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id); ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id); } + + /** + * Returns the static page for a page type. + * + * @param \App\Enums\StaticPageType $type + * @return \App\Models\StaticPage + */ + public static function getStaticPage(StaticPageType $type): \App\Models\StaticPage + { + $query = (new self())->where('type', $type)->first(); + return $query; + } + + // * RELATIONS + + /** + * + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function sections(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Section::class, 'page_id'); + } } diff --git a/app/Providers/ViewServiceProvider.php b/app/Providers/ViewServiceProvider.php index 8b35765..ef08cff 100644 --- a/app/Providers/ViewServiceProvider.php +++ b/app/Providers/ViewServiceProvider.php @@ -7,6 +7,10 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; +use App\Enums\StaticPageType; +use App\Enums\Slides\SliderTypeEnum; +use App\Models\StaticPage; +use App\Models\Section; class ViewServiceProvider extends ServiceProvider { @@ -34,6 +38,53 @@ class ViewServiceProvider extends ServiceProvider } else { Paginator::useBootstrapFive(); } - } + + collect([ + ['name' => 'homeStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::home)], + ['name' => 'veilStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::unveil)], + ['name' => 'hireStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::we_hire)], + ['name' => 'commitStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::we_commit)], + ['name' => 'moveStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::we_move)], + ['name' => 'produceStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::we_produce)], + ['name' => 'listenStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::we_listen)], + ['name' => 'confidentialityStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::confidentiality)], + ['name' => 'legalsStaticPageModel', 'value' => StaticPage::getStaticPage(StaticPageType::legals)], + // * HOME SECTIONS + ['name' => 'homeSections', 'value' => Section::getSections(StaticPageType::home)], + // * UNVEIL SECTION + ['name' => 'veilSections', 'value' => Section::getSections(StaticPageType::unveil)], + // * WE HIRE SECTION + ['name' => 'hireSections', 'value' => Section::getSections(StaticPageType::we_hire)], + // * WE COMMIT SECTION + ['name' => 'commitSections', 'value' => Section::getSections(StaticPageType::we_commit)], + // * WE MOVE SECTION + ['name' => 'moveSections', 'value' => Section::getSections(StaticPageType::we_move)], + // * WE PRODUCE SECTION + ['name' => 'produceSections', 'value' => Section::getSections(StaticPageType::we_produce)], + // * WE LISTEN SECTION + ['name' => 'listenSections', 'value' => Section::getSections(StaticPageType::we_listen)], + // * RESPECT HEARTH SLIDE + ['name' => 'respectSlides', 'value' => SliderTypeEnum::respect_earth], + ])->map(function ($array) { + View::share($array['name'], (function () use ($array) { + return $array['value'] ?: null; + })()); + }); + + // * HOME ACTIVE SECTIONS + View::share('isActiveHome', Section::isActive(StaticPageType::home)); + // * UNVEIL ACTIVE SECTIONS + View::share('isActiveVeil', Section::isActive(StaticPageType::unveil)); + // * UNVEIL ACTIVE SECTIONS + View::share('isActiveHire', Section::isActive(StaticPageType::we_hire)); + // * WE HIRE ACTIVE SECTIONS + View::share('isActiveCommit', Section::isActive(StaticPageType::we_commit)); + // * WE COMMIT ACTIVE SECTIONS + View::share('isActiveMove', Section::isActive(StaticPageType::we_move)); + // * WE PRODUCE ACTIVE SECTIONS + View::share('isActiveProduce', Section::isActive(StaticPageType::we_produce)); + // * WE LISTEN ACTIVE SECTIONS + View::share('isActiveListen', Section::isActive(StaticPageType::we_listen)); + } //end if } } diff --git a/resources/views/bo/layouts/nav-list.blade.php b/resources/views/bo/layouts/nav-list.blade.php index da75a07..8645367 100644 --- a/resources/views/bo/layouts/nav-list.blade.php +++ b/resources/views/bo/layouts/nav-list.blade.php @@ -6,49 +6,104 @@ {{ __('Accueil') }} + {{-- HOME --}}