ldc-volena/app/Http/Controllers/Fo/StaticPageController.php
2024-03-18 16:10:01 +01:00

225 lines
8.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

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\Section;
use App\Models\Site;
use App\Models\Slide;
use App\Models\StaticPage;
use App\Models\Testimonial;
use Illuminate\Support\Facades\Mail;
class StaticPageController extends Controller
{
/**
* 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();
$siteModel = Site::query()->first();
return view('fo.pages.unveil', compact(
'staticPageModel',
'sectionModels',
'historicalMilestoneModels',
'siteModel'
));
}
/**
* 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();
$slideModels = Slide::query()
->whereIn('slider', [SliderTypeEnum::better_life->value, SliderTypeEnum::respect_earth->value])
->get();
$testimonialModels = Testimonial::query()
->whereIn('type', [
TypeEnum::breeding->value,
TypeEnum::better_life->value,
TypeEnum::respect_earth->value,
TypeEnum::feed->value,
TypeEnum::volena->value,
])->get();
/** Get all sections */
$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',
'slideModels',
'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.confidentiality', 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();
}
return view('fo.pages.site', [
'siteModel' => $site,
'nextSiteModel' => $nextSiteModel
]);
}
}