1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/app/Mail/TemplateEmail.php
David Bomba e5a230e0c7
Performance improvements (#3634)
* Adjustments for tests

* Implement handling of temp downloading resources

* Refactor paths

* Refactors for file paths

* Refactor paths

* Add in S3 adapter

* Refactor company Documment URL

* Refactor for entity pdf performance

* Refactors for invoice generation

* Enhancements for emails invoices

* Emails

* Fixes for client portal queries
2020-04-16 18:41:25 +10:00

75 lines
2.3 KiB
PHP

<?php
namespace App\Mail;
use App\Models\Client;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class TemplateEmail extends Mailable
{
use Queueable, SerializesModels;
private $build_email;
private $user; //the user the email will be sent from
private $client;
private $footer;
public function __construct($build_email, User $user, Client $client)
{
$this->build_email = $build_email;
$this->user = $user; //this is inappropriate here, need to refactor 'user' in this context the 'user' could also be the 'system'
$this->client = $client;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
/*Alter Run Time Mailer configuration (driver etc etc) to regenerate the Mailer Singleton*/
//if using a system level template
$template_name = 'email.template.' . $this->build_email->getTemplate();
$settings = $this->client->getMergedSettings();
$company = $this->client->company;
$message = $this->from($this->user->email, $this->user->present()->name())//todo this needs to be fixed to handle the hosted version
->subject($this->build_email->getSubject())
->text('email.template.plain', [
'body' => $this->build_email->getBody(),
'footer' => $this->build_email->getFooter()
])
->view($template_name, [
'body' => $this->build_email->getBody(),
'footer' => $this->build_email->getFooter(),
'view_link' => $this->build_email->getViewLink(),
'view_text' => $this->build_email->getViewText(),
'title' => $this->build_email->getSubject(),
'signature' => $settings->email_signature,
'settings' => $settings,
'company' => $company
]);
//conditionally attach files
if ($settings->pdf_email_attachment !== false && !empty($this->build_email->getAttachments())) {
foreach ($this->build_email->getAttachments() as $file) {
$message->attach($file);
}
}
return $message;
}
}