ldc-legaulois/app/Http/Controllers/ContactController.php
Jérémy Munsch db234ced3d Add One page
- add npm jquery, fancybox, jquery-devrama-slider-2 (forked)
     odometer, owl.carousel
 -  compile onepage.js app-onepage.css
 - Onepage Controller, calls ContactController to use form
 -  change app default locale to 'fr'
 - add more resources assets (images, documents flamand)
 - add more icons svg
2021-02-17 16:48:08 +01:00

97 lines
3.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Enums\ContactFormType;
use App\Exceptions\AbortContactMailer;
use App\Http\Requests\ContactFormRequest;
use App\Mail\Contact as MailsContact;
use App\Mail\ContactComplain as MailsContactComplain;
use App\Models\Contact as ModelsContact;
use App\Models\MailContactData;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
class ContactController extends Controller
{
public function contact(ContactFormType $type = null)
{
$user = null;
$type = $type ?? ContactFormType::none();
return view('front.contact.contact', compact('type', 'user'));
}
public function contactSubmit(ContactFormRequest $request)
{
try {
$data = new MailContactData();
$data->fill($request->all());
Mail::to(config('mail.contactsList.contact'))
->send(
new MailsContact(
$data,
realpath($this->getContactFilePathArchadia()) .
DIRECTORY_SEPARATOR .
sprintf('contact_le_gaulois_%d_%d.csv', time(), rand(1000, 9999))
)
);
ModelsContact::incrementStat($data->type);
return back()->with('status', true);
} catch (AbortContactMailer $e) {
Log::error('Fail to build mail from contact page ', ['exception' => $e]);
}
return back()->withInput()->with('status', false);
}
public function complain()
{
return $this->contact(ContactFormType::complain());
}
public function complainSubmit(ContactFormRequest $request)
{
try {
$data = new MailContactData();
$data->fill($request->all());
Mail::to(config('mail.contactsList.passerelle'))
->send(new MailsContactComplain(
$data,
realpath($this->getContactFilePathPasserelle()) .
DIRECTORY_SEPARATOR .
sprintf('LEGAULOIS_PASS_MESSAGE-%s.xml', date("YmdHis"))
));
ModelsContact::incrementStat($data->type);
return back()->with('status', true);
} catch (AbortContactMailer $e) {
Log::error('Fail to build mail from complain page ', ['exception' => $e]);
}
return back()->withInput()->with('status', false);
}
private function getContactFilePathArchadia($passerelle = false): string
{
$path = !$passerelle ?
config('contactfiles.dossierFichiersArchadia') :
config('contactfiles.dossierFichiersPasserelle');
if (!File::isDirectory($path)) {
if (!File::makeDirectory($path, 0007, true, true)) {
throw new AbortContactMailer(sprintf('Could not create %s', $path));
}
}
return $path;
}
private function getContactFilePathPasserelle(): string
{
return $this->getContactFilePathArchadia(true);
}
}