70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Exceptions\AbortContactMailer;
|
|
use App\Models\MailContactData;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\File;
|
|
use League\Csv\Reader;
|
|
use League\Csv\Statement;
|
|
use League\Csv\XMLConverter;
|
|
|
|
class ContactComplain extends Contact
|
|
{
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* The order instance.
|
|
*
|
|
* @var MailContactData
|
|
*/
|
|
protected $data;
|
|
|
|
/**
|
|
* Where to store XML FilePath
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $xmlFilePath;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(MailContactData $data, string $xmlFilePath)
|
|
{
|
|
$this->data = $data;
|
|
$this->xmlFilePath = $xmlFilePath;
|
|
}
|
|
|
|
/**
|
|
* Build the message.
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function build()
|
|
{
|
|
$this->joinFileIfProvided();
|
|
$this->makeXmlFile();
|
|
return $this->view('emails.contact')
|
|
->subject(sprintf('Nouveau message consommateur Le Gaulois (%s)', $this->data->type->label))
|
|
->text('emails.contact-plain')
|
|
->with('data', $this->data)
|
|
->attach($this->xmlFilePath, [
|
|
'as' => sprintf('LEGAULOIS_PASS_MESSAGE_%d.xml', date("YmdHis")),
|
|
'mime' => 'application/xml',
|
|
]);
|
|
}
|
|
|
|
private function makeXmlFile()
|
|
{
|
|
$d = $this->data->exportToPasserelleDataArray();
|
|
if (!File::put($this->xmlFilePath, view('emails.passerelle-xml', ['data' => $d])->render())) {
|
|
throw new AbortContactMailer(sprintf('Could save create %s', $this->xmlFilePath));
|
|
}
|
|
}
|
|
}
|