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

150 lines
5.2 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;
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-11 15:07:25 +01:00
use App\Models\Testimonial;
use Illuminate\Support\Facades\Mail;
2024-02-27 13:59:16 +01:00
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();
2024-03-11 15:07:25 +01:00
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,
2024-03-13 12:20:44 +01:00
])->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();
2024-03-11 15:07:25 +01:00
return view('fo.pages.commitments', compact(
'staticPageModel',
'sectionModels',
'slideModels',
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();
return view('fo.pages.confidentiality', compact(
'staticPageModel',
));
}
/**
* 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')
->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
}
}