83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\ProjectMailing;
|
|
use App\Models\ProjectMailingAttachment;
|
|
use App\Models\ProjectMosaic;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Attachment;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ReportMailer extends Mailable
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
public ProjectMailing $mailing;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*/
|
|
public function __construct(ProjectMailing $mailing)
|
|
{
|
|
$this->mailing = $mailing;
|
|
$this->withSwiftMessage(function ($message) use ($mailing) {
|
|
$message->getHeaders()->addTextHeader('X-Mailing-ID', $mailing->id);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the message envelope.
|
|
*/
|
|
public function envelope(): Envelope
|
|
{
|
|
return new Envelope(
|
|
subject:$this->mailing->subject,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the message content definition.
|
|
*/
|
|
public function content(): Content
|
|
{
|
|
return new Content(
|
|
markdown: 'emails.scheduled-report',
|
|
with: [
|
|
'mailingContent' => $this->mailing->message,
|
|
'logoPath'=> Storage::disk('app')->path('images/smartcane.png'),
|
|
'subject' => $this->mailing->subject,
|
|
],
|
|
//htmlString: $this->mailing->message
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the attachments for the message.
|
|
*
|
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
|
*/
|
|
public function attachments(): array
|
|
{
|
|
return $this->mailing->attachments()->get()->map(function (ProjectMailingAttachment $attachment) {
|
|
$mime = 'application/pdf'; // default MIME type
|
|
$extension = pathinfo($attachment->path, PATHINFO_EXTENSION);
|
|
|
|
if ($extension === 'docx') {
|
|
$mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
}
|
|
|
|
return Attachment::fromStorage(
|
|
path: $attachment->mailing->project->download_path."/".$attachment->path
|
|
)
|
|
->as($attachment->path)
|
|
->withMime($mime);
|
|
})->toArray();
|
|
}
|
|
}
|