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

101 lines
3.1 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) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-08-06 05:04:09 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Mail;
2020-02-15 12:49:31 +01:00
use App\Models\Client;
2021-02-02 09:51:12 +01:00
use App\Models\ClientContact;
2020-02-15 12:49:31 +01:00
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class TemplateEmail extends Mailable
{
2020-02-15 12:49:31 +01:00
private $build_email;
2020-02-15 12:49:31 +01:00
private $client;
2021-02-02 06:11:33 +01:00
private $contact;
2021-02-18 22:43:47 +01:00
private $company;
2021-02-22 01:18:52 +01:00
private $invitation;
public function __construct($build_email, ClientContact $contact, $invitation = null)
{
$this->build_email = $build_email;
2020-02-15 12:49:31 +01:00
2021-02-02 06:11:33 +01:00
$this->contact = $contact;
$this->client = $contact->client;
2021-02-18 22:43:47 +01:00
$this->company = $contact->company;
2021-02-22 01:18:52 +01:00
$this->invitation = $invitation;
}
public function build()
{
$template_name = 'email.template.'.$this->build_email->getTemplate();
2020-02-15 12:49:31 +01:00
$settings = $this->client->getMergedSettings();
$company = $this->client->company;
2021-02-18 22:43:47 +01:00
$this->from(config('mail.from.address'), $this->company->present()->name());
2021-02-24 00:39:37 +01:00
2021-02-18 23:20:09 +01:00
if (strlen($settings->bcc_email) > 1)
$this->bcc($settings->bcc_email, $settings->bcc_email);
2020-11-25 15:19:52 +01:00
$this->subject($this->build_email->getSubject())
2020-02-15 12:49:31 +01:00
->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, [
2021-02-02 06:11:33 +01:00
'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]),
'body' => $this->build_email->getBody(),
'footer' => $this->build_email->getFooter(),
'view_link' => $this->build_email->getViewLink(),
'view_text' => $this->build_email->getViewText(),
2020-11-08 06:21:18 +01:00
'title' => '',
'signature' => $settings->email_signature,
'settings' => $settings,
'company' => $company,
2020-09-28 23:54:12 +02:00
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
2021-02-16 13:56:12 +01:00
])
->withSwiftMessage(function ($message) use($company){
$message->getHeaders()->addTextHeader('Tag', $company->company_key);
2021-02-22 01:18:52 +01:00
$message->invitation = $this->invitation;
2021-02-17 01:25:30 +01:00
});
//conditionally attach files
if ($settings->pdf_email_attachment !== false && ! empty($this->build_email->getAttachments())) {
2021-01-08 11:19:26 +01:00
2021-01-09 05:15:53 +01:00
//hosted | plan check here
foreach ($this->build_email->getAttachments() as $file) {
2021-01-08 11:19:26 +01:00
if(is_string($file))
2021-01-08 11:19:26 +01:00
$this->attach($file);
elseif(is_array($file))
$this->attach($file['path'], ['as' => $file['name'], 'mime' => $file['mime']]);
2021-01-08 11:19:26 +01:00
}
}
return $this;
}
}