2019-12-10 21:25:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Mail;
|
|
|
|
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
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 $template; //the template to use
|
|
|
|
|
|
|
|
private $message; //the message array (subject and body)
|
|
|
|
|
|
|
|
private $user; //the user the email will be sent from
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
private $client;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($message, $template, $user, $client)
|
2019-12-10 21:25:54 +01:00
|
|
|
{
|
|
|
|
$this->message = $message;
|
|
|
|
$this->template = $template;
|
2019-12-16 12:34:38 +01:00
|
|
|
$this->user = $user; //this is inappropriate here, need to refactor 'user' in this context the 'user' could also be the 'system'
|
|
|
|
$this->client = $client;
|
2019-12-10 21:25:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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->template;
|
|
|
|
|
2019-12-16 12:34:38 +01:00
|
|
|
$settings = $this->client->getMergedSettings();
|
|
|
|
|
|
|
|
$company = $this->client->company;
|
|
|
|
|
2019-12-10 21:25:54 +01:00
|
|
|
return $this->from($this->user->email, $this->user->present()->name()) //todo this needs to be fixed to handle the hosted version
|
|
|
|
->subject($this->message['subject'])
|
2019-12-16 12:34:38 +01:00
|
|
|
->text('email.template.plain', ['body' => $this->message['body'], 'footer' => $this->message['footer']])
|
2019-12-10 21:25:54 +01:00
|
|
|
->view($template_name, [
|
|
|
|
'body' => $this->message['body'],
|
|
|
|
'footer' => $this->message['footer'],
|
|
|
|
'title' => $this->message['title'],
|
2019-12-16 12:34:38 +01:00
|
|
|
'settings' => $settings,
|
|
|
|
'company' => $company
|
2019-12-10 21:25:54 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|