2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Helpers\Email;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\Quote;
|
|
|
|
use League\CommonMark\CommonMarkConverter;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
class EmailBuilder
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-04-30 13:45:47 +02:00
|
|
|
public $subject;
|
|
|
|
public $body;
|
|
|
|
public $recipients;
|
|
|
|
public $attachments;
|
|
|
|
public $footer;
|
|
|
|
public $template_style;
|
|
|
|
public $variables = [];
|
|
|
|
public $contact = null;
|
|
|
|
public $view_link;
|
|
|
|
public $view_text;
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
private function parseTemplate(string $data, bool $is_markdown = true, $contact = null): string
|
|
|
|
{
|
|
|
|
//process variables
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! empty($this->variables)) {
|
2020-02-15 10:01:15 +01:00
|
|
|
$data = str_replace(array_keys($this->variables), array_values($this->variables), $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//process markdown
|
|
|
|
if ($is_markdown) {
|
|
|
|
$converter = new CommonMarkConverter([
|
|
|
|
'html_input' => 'allow',
|
|
|
|
'allow_unsafe_links' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$data = $converter->convertToHtml($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $footer
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setFooter($footer)
|
|
|
|
{
|
|
|
|
$this->footer = $footer;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setVariables($variables)
|
|
|
|
{
|
|
|
|
$this->variables = $variables;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $contact
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setContact($contact)
|
|
|
|
{
|
|
|
|
$this->contact = $contact;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $subject
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setSubject($subject)
|
|
|
|
{
|
2020-04-15 02:30:52 +02:00
|
|
|
//$this->subject = $this->parseTemplate($subject, false, $this->contact);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
|
|
|
if (! empty($this->variables)) {
|
2020-04-15 02:30:52 +02:00
|
|
|
$subject = str_replace(array_keys($this->variables), array_values($this->variables), $subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->subject = $subject;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $body
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setBody($body)
|
|
|
|
{
|
2020-04-15 02:30:52 +02:00
|
|
|
//$this->body = $this->parseTemplate($body, true);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
|
|
|
if (! empty($this->variables)) {
|
2020-04-15 02:30:52 +02:00
|
|
|
$body = str_replace(array_keys($this->variables), array_values($this->variables), $body);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->body = $body;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $template_style
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setTemplate($template_style)
|
|
|
|
{
|
|
|
|
$this->template_style = $template_style;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
public function setAttachments($attachments)
|
|
|
|
{
|
|
|
|
$this->attachments[] = $attachments;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setViewLink($link)
|
|
|
|
{
|
|
|
|
$this->view_link = $link;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return $this;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
public function setViewText($text)
|
|
|
|
{
|
|
|
|
$this->view_text = $text;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getSubject()
|
|
|
|
{
|
|
|
|
return $this->subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getBody()
|
|
|
|
{
|
|
|
|
return $this->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getRecipients()
|
|
|
|
{
|
|
|
|
return $this->recipients;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getAttachments()
|
|
|
|
{
|
|
|
|
return $this->attachments;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getFooter()
|
|
|
|
{
|
|
|
|
return $this->footer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getTemplate()
|
|
|
|
{
|
|
|
|
return $this->template_style;
|
|
|
|
}
|
2020-04-15 02:30:52 +02:00
|
|
|
|
|
|
|
public function getViewLink()
|
|
|
|
{
|
|
|
|
return $this->view_link;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewText()
|
|
|
|
{
|
|
|
|
return $this->view_text;
|
|
|
|
}
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|