ldc-volena/app/Http/Controllers/Fo/StaticPageController.php

327 lines
13 KiB
PHP
Raw Normal View History

2024-02-27 13:59:16 +01:00
<?php
namespace App\Http\Controllers\Fo;
2024-03-11 15:07:25 +01:00
use App\Enums\Listen\ObjectEnum;
2024-03-13 12:20:44 +01:00
use App\Enums\Sections\PageSectionEnum;
2024-03-11 15:07:25 +01:00
use App\Enums\Slides\SliderTypeEnum;
2024-02-27 13:59:16 +01:00
use App\Enums\StaticPageType;
2024-03-11 15:07:25 +01:00
use App\Enums\Testimonials\TypeEnum;
2024-02-27 13:59:16 +01:00
use App\Http\Controllers\Controller;
2024-03-11 15:07:25 +01:00
use App\Http\Requests\Fo\ListenFormRequest;
use App\Mail\SendConfirmationMail;
use App\Mail\SendContactMail;
2024-02-27 13:59:16 +01:00
use App\Models\HistoricalMilestone;
2024-03-18 16:10:01 +01:00
use App\Models\JobVideo;
use App\Models\Network;
2024-03-20 17:39:24 +01:00
use App\Models\News;
2024-02-27 13:59:16 +01:00
use App\Models\Section;
use App\Models\Site;
2024-03-11 15:07:25 +01:00
use App\Models\Slide;
2024-02-27 13:59:16 +01:00
use App\Models\StaticPage;
2024-03-20 17:39:24 +01:00
use App\Models\Strip;
2024-03-11 15:07:25 +01:00
use App\Models\Testimonial;
use Illuminate\Database\Eloquent\Builder;
2024-03-11 15:07:25 +01:00
use Illuminate\Support\Facades\Mail;
2024-03-26 12:23:04 +01:00
use Illuminate\Support\Str;
2024-02-27 13:59:16 +01:00
class StaticPageController extends Controller
{
2024-03-20 17:39:24 +01:00
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\View
*/
public function show(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::home)->first();
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
$stripModels = Strip::query()
->where('published', true)
2024-03-20 17:39:24 +01:00
->orderBy('publish_at', 'DESC')
->limit(6)
->with('news')
->whereHas('news', function (Builder $query) {
$query->where('published', true);
})
2024-03-20 17:39:24 +01:00
->get();
$newsModels = News::query()
->where('published', true)
->orderBy('displayed_date', 'DESC')
2024-03-20 17:39:24 +01:00
->limit(4)
->get();
$slideModels = Slide::query()->where('type', SliderTypeEnum::home)->get();
$missionSection = $sectionModels->where('section', PageSectionEnum::home_missions)->first();
$ambitionSection = $sectionModels->where('section', PageSectionEnum::home_ambition)->first();
$teamSection = $sectionModels->where('section', PageSectionEnum::home_team)->first();
$lifeSection = $sectionModels->where('section', PageSectionEnum::home_life)->first();
2024-08-02 16:17:48 +02:00
$slideTeams = Slide::query()->where('type', SliderTypeEnum::team)->get();
2024-03-20 17:39:24 +01:00
return view('fo.pages.home', compact(
'staticPageModel',
'sectionModels',
'stripModels',
'newsModels',
'slideModels',
'missionSection',
'ambitionSection',
'teamSection',
'lifeSection',
2024-08-02 16:17:48 +02:00
'slideTeams',
2024-03-20 17:39:24 +01:00
));
}
2024-02-27 13:59:16 +01:00
/**
* Display the 'unveil' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function unveil(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::unveil)->first();
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
2024-03-20 17:39:24 +01:00
$historicalMilestoneModels = HistoricalMilestone::query()->orderBy('year', 'ASC')->get();
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Site> */
$siteModelList = Site::query()->orderBy('order')->get();
$keySection = $sectionModels->where('section', PageSectionEnum::unveil_pole)->first();
$missionsSection = $sectionModels->where('section', PageSectionEnum::unveil_missions)->first();
$localSection = $sectionModels->where('section', PageSectionEnum::unveil_local)->first();
$siteSection = $sectionModels->where('section', PageSectionEnum::unveil_sites)->first();
$historySection = $sectionModels->where('section', PageSectionEnum::unveil_history)->first();
$commitmentSection = $sectionModels->where('section', PageSectionEnum::unveil_commitments)->first();
2024-03-26 12:23:04 +01:00
$viewBox = null;
$initialZoom = null;
// * Calcul Viewbox leaflet map ().
// Carte page “on se dévoile” : Point central = Laval + rayon = 100 km
2024-03-26 12:23:04 +01:00
/** @var \App\Models\Site|null $lavalSite */
// @phpstan-ignore-next-line
$lavalSite = $siteModelList->first(fn(Site $site) => Str::contains($site->name, 'Laval'));
2024-03-26 12:23:04 +01:00
if ($lavalSite) {
$viewBox = (object)[
'lat' => $lavalSite->latitude,
'lng' => $lavalSite->longitude
];
$initialZoom = 9;
}
2024-02-27 13:59:16 +01:00
2024-03-11 15:07:25 +01:00
return view('fo.pages.unveil', compact(
'viewBox',
2024-03-26 12:23:04 +01:00
'initialZoom',
2024-03-11 15:07:25 +01:00
'staticPageModel',
'sectionModels',
'historicalMilestoneModels',
'siteModelList',
2024-03-20 17:39:24 +01:00
'keySection',
'missionsSection',
'localSection',
'siteSection',
'historySection',
'commitmentSection'
2024-03-11 15:07:25 +01:00
));
}
/**
* Display the 'commitments' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function commit(): \Illuminate\Contracts\View\View
{
2024-03-20 17:39:24 +01:00
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_commit)->first();
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
$slideLifeModels = Slide::query()->where('type', SliderTypeEnum::better_life)->latest()->get();
$slideEarthModels = Slide::query()->where('type', SliderTypeEnum::respect_earth)->latest()->get();
2024-03-20 17:39:24 +01:00
$testimonialModels = Testimonial::query()
2024-03-11 15:07:25 +01:00
->whereIn('type', [
TypeEnum::breeding->value,
TypeEnum::better_life->value,
TypeEnum::respect_earth->value,
TypeEnum::feed->value,
TypeEnum::volena->value,
2024-03-13 12:20:44 +01:00
])->get();
$ambitionSection = $sectionModels->where('section', PageSectionEnum::commit_ambition)->first();
$breedingSection = $sectionModels->where('section', PageSectionEnum::commit_breeding)->first();
$lifeSection = $sectionModels->where('section', PageSectionEnum::commit_living)->first();
$earthSection = $sectionModels->where('section', PageSectionEnum::commit_respect_earth)->first();
$feedSection = $sectionModels->where('section', PageSectionEnum::commit_feed)->first();
$testimonialsSection = $sectionModels->where('section', PageSectionEnum::commit_commitments)->first();
2024-03-11 15:07:25 +01:00
return view('fo.pages.commitments', compact(
'staticPageModel',
'sectionModels',
2024-03-20 17:39:24 +01:00
'slideLifeModels',
'slideEarthModels',
2024-03-13 12:20:44 +01:00
'testimonialModels',
'ambitionSection',
'breedingSection',
'lifeSection',
'earthSection',
'feedSection',
'testimonialsSection',
2024-03-11 15:07:25 +01:00
));
}
/**
* Display the 'legals' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function legals(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::legals)->first();
return view('fo.pages.legals', compact(
'staticPageModel',
));
}
/**
* Display the 'confidentiality' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function confidentiality(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::confidentiality)->first();
2024-03-20 17:39:24 +01:00
return view('fo.pages.legals', compact(
2024-03-11 15:07:25 +01:00
'staticPageModel',
));
}
2024-03-14 10:09:22 +01:00
/**
* Display the 'we_produce' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function produce(): \Illuminate\Contracts\View\View
{
// MODELS
2024-03-14 10:09:22 +01:00
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_produce)->first();
2024-03-14 15:25:04 +01:00
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
$networkModels = Network::query()->where('published', true)->orderBy('order')->get();
// SECTIONS
2024-03-14 15:25:04 +01:00
$localSection = $sectionModels->where('section', PageSectionEnum::produce_local)->first();
$gmsSection = $sectionModels->where('section', PageSectionEnum::produce_gms)->first();
$rhdSection = $sectionModels->where('section', PageSectionEnum::produce_rhd)->first();
$exportSection = $sectionModels->where('section', PageSectionEnum::produce_export)->first();
$qualitySection = $sectionModels->where('section', PageSectionEnum::produce_quality)->first();
$networkSection = $sectionModels->where('section', PageSectionEnum::produce_networks)->first();
2024-03-14 10:09:22 +01:00
2024-03-14 15:25:04 +01:00
return view('fo.pages.produce.show', compact(
2024-03-14 10:09:22 +01:00
'staticPageModel',
'networkModels',
2024-03-14 15:25:04 +01:00
'localSection',
'gmsSection',
'rhdSection',
'exportSection',
'qualitySection',
'networkSection',
2024-03-14 10:09:22 +01:00
));
}
2024-03-11 15:07:25 +01:00
/**
* Display the 'we_listen' page.
* This page is used to send a contact form.
2024-03-11 15:07:25 +01:00
*
* @return \Illuminate\Contracts\View\View
*/
public function listen(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_listen)->first();
$sectionModel = Section::query()->where('page_id', $staticPageModel->id)->first();
2024-03-11 15:07:25 +01:00
return view('fo.pages.listen', compact(
'staticPageModel',
'sectionModel',
2024-03-11 15:07:25 +01:00
));
}
/**
* Send listen form data.
*
* @param \App\Http\Requests\Fo\ListenFormRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function listenForm(ListenFormRequest $request): \Illuminate\Http\RedirectResponse
{
Mail::to(config('mail.contact.' . ObjectEnum::make(intval($request->validated()['object']))->name()))
->send(new SendContactMail((object)$request->validated()));
Mail::to($request->validated()['email'])->send(new SendConfirmationMail((object)$request->validated()));
2024-03-14 10:09:22 +01:00
return redirect()->route('fo.listen.show')
2024-03-11 15:07:25 +01:00
->with('success', trans(
'Bonjour, votre message a bien été transmis, nous vous en remercions. Cordialement, l’équipe :appName.',
['appName' => config('app.name')]
));
2024-02-27 13:59:16 +01:00
}
2024-03-18 16:10:01 +01:00
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\View
*/
public function hire(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_hire)->first();
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
$videoModels = JobVideo::query()->inRandomOrder()->simplePaginate(4);
$testimonialModels = Testimonial::query()->where('type', TypeEnum::hire)->get();
$compagnyLifeSection = $sectionModels->where('section', PageSectionEnum::hire_life)->first();
$formationSection = $sectionModels->where('section', PageSectionEnum::hire_formation)->first();
$testimonialSection = $sectionModels->where('section', PageSectionEnum::hire_grow)->first();
$paritySection = $sectionModels->where('section', PageSectionEnum::hire_parity)->first();
$findSection = $sectionModels->where('section', PageSectionEnum::hire_find)->first();
return view('fo.pages.hire', \compact(
'staticPageModel',
'sectionModels',
'videoModels',
'testimonialModels',
'compagnyLifeSection',
'formationSection',
'testimonialSection',
'paritySection',
'findSection'
));
}
/**
* Display a listing of the resource.
*
* @param \App\Models\Site $site
* @return \Illuminate\Contracts\View\View
*/
public function site(Site $site): \Illuminate\Contracts\View\View
{
2024-03-26 14:20:34 +01:00
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Site> */
$siteModels = Site::query()->orderBy('order')->get();
$siteModelList = $siteModels->keyBy('order');
$nextSiteModel = $siteModelList->where(
'order',
'>',
$site->order
)->first();
if ($siteModelList->last()->is($site)) {
$nextSiteModel = $siteModelList->first();
}
2024-03-18 16:10:01 +01:00
2024-03-26 12:23:04 +01:00
$viewBox = (object)[
'lat' => $site->latitude,
'lng' => $site->longitude
];
2024-03-26 14:20:34 +01:00
$initialZoom = 10;
2024-03-26 12:23:04 +01:00
2024-03-18 16:10:01 +01:00
return view('fo.pages.site', [
2024-03-26 14:20:34 +01:00
'siteModelList' => $siteModelList,
2024-03-18 16:10:01 +01:00
'siteModel' => $site,
2024-03-26 12:23:04 +01:00
'nextSiteModel' => $nextSiteModel,
'viewBox' => $viewBox,
'initialZoom' => $initialZoom,
2024-03-18 16:10:01 +01:00
]);
}
2024-03-26 12:23:04 +01:00
}