82 lines
2 KiB
PHP
82 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\MailContactData;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Attachment;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ContactComplainMail extends ContactMail
|
|
{
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* The order instance.
|
|
*
|
|
* @var MailContactData
|
|
*/
|
|
protected $data;
|
|
protected $file;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @param \App\Models\MailContactData $data
|
|
* @param string|null $file
|
|
* @return void
|
|
*/
|
|
public function __construct(MailContactData $data, string|null $file)
|
|
{
|
|
$this->data = $data;
|
|
$this->file = $file;
|
|
}
|
|
|
|
/**
|
|
* Build the message.
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function build()
|
|
{
|
|
if ($this->file) {
|
|
$this->joinedFileName = sprintf(
|
|
'LEGAULOIS_PASS_MESSAGE-PJ-%s.%s',
|
|
date("YmdHis"),
|
|
File::extension($this->file)
|
|
);
|
|
}
|
|
|
|
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)
|
|
->attachData(
|
|
view('emails.passerelle-xml', ['data' => $this->data->exportToPasserelleDataArray()])->render(),
|
|
sprintf('LEGAULOIS_PASS_MESSAGE_%d.xml', date("YmdHis")),
|
|
['mime' => 'application/xml']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the attachments for the message.
|
|
*
|
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
|
*/
|
|
public function attachments(): array
|
|
{
|
|
if (!$this->file) {
|
|
return [];
|
|
}
|
|
return [
|
|
Attachment::fromPath($this->file)->as(sprintf(
|
|
'LEGAULOIS_PASS_MESSAGE-PJ-%s.%s',
|
|
date("YmdHis"),
|
|
File::extension($this->file)
|
|
)),
|
|
];
|
|
}
|
|
}
|