1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Mail/TemplateEmail.php

87 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2020-08-06 05:04:09 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-08-06 05:04:09 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Mail;
2020-02-15 12:49:31 +01:00
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;
2020-02-15 12:49:31 +01:00
private $build_email;
2020-02-15 12:49:31 +01:00
private $user; //the user the email will be sent from
2020-02-15 12:49:31 +01:00
private $client;
private $footer;
2020-02-15 12:49:31 +01:00
public function __construct($build_email, User $user, Client $client)
{
$this->build_email = $build_email;
2020-02-15 12:49:31 +01:00
$this->user = $user; //this is inappropriate here, need to refactor 'user' in this context the 'user' could also be the 'system'
2020-02-15 12:49:31 +01:00
$this->client = $client;
}
/**
* Build the message.
*
* @return $this
2020-10-28 11:10:49 +01:00
* @throws \Laracasts\Presenter\Exceptions\PresenterException
*/
public function build()
{
2020-02-15 12:49:31 +01:00
$template_name = 'email.template.'.$this->build_email->getTemplate();
2020-02-15 12:49:31 +01:00
$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
2020-02-15 12:49:31 +01:00
->subject($this->build_email->getSubject())
->text('email.template.plain', [
'body' => $this->build_email->getBody(),
'footer' => $this->build_email->getFooter(),
2020-10-20 01:37:33 +02:00
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
'settings' => $settings,
2020-02-15 12:49:31 +01:00
])
->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,
2020-09-28 23:54:12 +02:00
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
]);
//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;
}
}