1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Attachment links

This commit is contained in:
David Bomba 2023-03-09 10:38:08 +11:00
parent 92294d8379
commit 686b48c42b
3 changed files with 36 additions and 15 deletions

View File

@ -14,12 +14,16 @@ namespace App\Services\Email;
use App\Models\Document;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Attachment;
use Illuminate\Support\Facades\URL;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Headers;
use Illuminate\Mail\Mailables\Envelope;
class EmailMailable extends Mailable
{
public int $max_attachment_size = 3000000;
/**
* Create a new message instance.
*
@ -53,6 +57,16 @@ class EmailMailable extends Mailable
*/
public function content()
{
$links = Document::whereIn('id',$this->email_object->documents)
->where('size', '>', $this->max_attachment_size)
->cursor()
->map(function ($document){
return "<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>";
});
return new Content(
view: $this->email_object->html_template,
text: $this->email_object->text_template,
@ -64,7 +78,8 @@ class EmailMailable extends Mailable
'logo' => $this->email_object->logo,
'signature' => $this->email_object->signature,
'company' => $this->email_object->company,
'greeting' => ''
'greeting' => '',
'links' => array_merge($this->email_object->links, $links->toArray()),
]
);
}
@ -78,18 +93,20 @@ class EmailMailable extends Mailable
{
$attachments = [];
foreach ($this->email_object->attachments as $file) {
$attachments[] = Attachment::fromData(fn () => base64_decode($file['file']), $file['name']);
}
$attachments = collect($this->email_object->attachments)->map(function ($file){
return Attachment::fromData(fn () => base64_decode($file['file']), $file['name']);
});
foreach($this->email_object->documents as $doc_id){
$document = Document::find($doc_id);
$documents = Document::whereIn('id',$this->email_object->documents)
->where('size', '<', $this->max_attachment_size)
->cursor()
->map(function ($document){
if($document)
$attachments[] = Attachment::fromData(fn () => $document->getFile(), $document->name);
}
return Attachment::fromData(fn () => $document->getFile(), $document->name);
return $attachments;
});
return $attachments->merge($documents)->toArray();
}
/**

View File

@ -111,4 +111,6 @@ class EmailObject
public array $documents = [];
public ?string $template = null; //invoice //quote //reminder1
public array $links = [];
}

View File

@ -167,13 +167,15 @@
</a>
</div>
@isset($links)
<div>
@isset($links)
@foreach($links as $link)
{!! $link ?? '' !!}<br>
@endforeach
@endisset
<ul style="list-style-type: none;">
@foreach($links as $link)
<li>{!! $link ?? '' !!} <img height="15px" src="{{ asset('images/svg/dark/file.svg') }}"></li>
@endforeach
</ul>
</div>
@endisset
</div>
</td>
</tr>