ldc-volena/app/Http/Controllers/Fo/StaticPageController.php
2024-03-26 12:23:04 +01:00

299 lines
12 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Fo;
use App\Enums\Listen\ObjectEnum;
use App\Enums\Sections\PageSectionEnum;
use App\Enums\Slides\SliderTypeEnum;
use App\Enums\StaticPageType;
use App\Enums\Testimonials\TypeEnum;
use App\Http\Controllers\Controller;
use App\Http\Requests\Fo\ListenFormRequest;
use App\Mail\SendConfirmationMail;
use App\Mail\SendContactMail;
use App\Models\HistoricalMilestone;
use App\Models\JobVideo;
use App\Models\News;
use App\Models\Section;
use App\Models\Site;
use App\Models\Slide;
use App\Models\StaticPage;
use App\Models\Strip;
use App\Models\Testimonial;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
class StaticPageController extends Controller
{
/**
* 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)
->orderBy('publish_at', 'DESC')
->limit(6)
->with('news')
->get();
$newsModels = News::query()->where('published', true)
->orderBy('publish_at', 'DESC')
->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();
return view('fo.pages.home', compact(
'staticPageModel',
'sectionModels',
'stripModels',
'newsModels',
'slideModels',
'missionSection',
'ambitionSection',
'teamSection',
'lifeSection',
));
}
/**
* 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();
$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();
$viewBox = null;
$initialZoom = null;
// * Calcul Viewbox leaflet map ().
// Carte  page “on se dévoile” : Point central = Laval + rayon = 100 km 
/** @var \App\Models\Site|null $lavalSite */
// @phpstan-ignore-next-line
$lavalSite = $siteModelList->first(fn (Site $site) => Str::contains($site->name, 'Laval'));
if ($lavalSite) {
$viewBox = (object)[
'lat' => $lavalSite->latitude,
'lng' => $lavalSite->longitude
];
$initialZoom = 9;
}
return view('fo.pages.unveil', compact(
'viewBox',
'initialZoom',
'staticPageModel',
'sectionModels',
'historicalMilestoneModels',
'siteModelList',
'keySection',
'missionsSection',
'localSection',
'siteSection',
'historySection',
'commitmentSection'
));
}
/**
* Display the 'commitments' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function commit(): \Illuminate\Contracts\View\View
{
$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)->get();
$slideEarthModels = Slide::query()->where('type', SliderTypeEnum::respect_earth)->get();
$testimonialModels = Testimonial::query()
->whereIn('type', [
TypeEnum::breeding->value,
TypeEnum::better_life->value,
TypeEnum::respect_earth->value,
TypeEnum::feed->value,
TypeEnum::volena->value,
])->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();
return view('fo.pages.commitments', compact(
'staticPageModel',
'sectionModels',
'slideLifeModels',
'slideEarthModels',
'testimonialModels',
'ambitionSection',
'breedingSection',
'lifeSection',
'earthSection',
'feedSection',
'testimonialsSection',
));
}
/**
* 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();
return view('fo.pages.legals', compact(
'staticPageModel',
));
}
/**
* Display the 'we_produce' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function produce(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_produce)->first();
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
$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();
return view('fo.pages.produce.show', compact(
'staticPageModel',
'localSection',
'gmsSection',
'rhdSection',
'exportSection',
'qualitySection'
));
}
/**
* Display the 'we_listen' page.
*
* @return \Illuminate\Contracts\View\View
*/
public function listen(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_listen)->first();
return view('fo.pages.listen', compact(
'staticPageModel',
));
}
/**
* 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()));
return redirect()->route('fo.listen.show')
->with('success', trans(
'Bonjour, votre message a bien été transmis, nous vous en remercions. Cordialement, l’équipe :appName.',
['appName' => config('app.name')]
));
}
/**
* 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
{
if ($site->order === Site::query()->max('order')) {
$nextSiteModel = Site::query()->orderBy('order')->first();
} else {
$nextSiteModel = Site::query()->orderBy('order')->where('order', '>', $site->order)->first();
}
$viewBox = (object)[
'lat' => $site->latitude,
'lng' => $site->longitude
];
$initialZoom = 9;
return view('fo.pages.site', [
'siteModel' => $site,
'nextSiteModel' => $nextSiteModel,
'viewBox' => $viewBox,
'initialZoom' => $initialZoom,
]);
}
}