98 lines
3.2 KiB
PHP
98 lines
3.2 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(Request $request, ContactFormType $type = null)
|
|
{
|
|
$status = $request->status;
|
|
$user = null;
|
|
$type = $type ?? ContactFormType::none();
|
|
return view('front.contact.contact', compact('type', 'user', 'status'));
|
|
}
|
|
|
|
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 response()->redirectToRoute('contact-us', ['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(Request $request)
|
|
{
|
|
return $this->contact($request, 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 response()->redirectToRoute('product-request', ['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);
|
|
}
|
|
}
|