1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 11:12:43 +01:00
invoiceninja/app/Helpers/Email/EmailBuilder.php
David Bomba f57339f185
Fixes and Refactors for Invoice Emails. (#3339)
* Working on emailing invoices

* Working on emailing and displaying email

* Working on emailing and displaying email

* Email invoices

* Fixes for html emails

* Ensure valid client prior to store

* Ensure client exists when storing an entity

* Update variable name send -> send_email for client_contacts

* Mailable download files

* Extend timeouts of password protected routes when a protected route is hit

* Add default portal design to company settings

* Minor fixes

* Fixes for Tests

* Fixes for invoicing emails

* Refactors for InvoiceEmail

* Implement abstractservice

* Refactors for services

* Refactors for emails

* Fixes for Invoice Emails
2020-02-17 20:37:44 +11:00

153 lines
2.8 KiB
PHP

<?php
namespace App\Helpers\Email;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Quote;
use League\CommonMark\CommonMarkConverter;
class EmailBuilder
{
protected $subject;
protected $body;
protected $recipients;
protected $attachments;
protected $footer;
protected $template_style;
protected $variables = [];
protected $contact = null;
private function parseTemplate(string $data, bool $is_markdown = true, $contact = null): string
{
//process variables
if (!empty($this->variables)) {
$data = str_replace(array_keys($this->variables), array_values($this->variables), $data);
}
//process markdown
if ($is_markdown) {
//$data = Parsedown::instance()->line($data);
$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;
return $this;
}
public function setVariables($variables)
{
$this->variables = $variables;
return $this;
}
/**
* @param $contact
* @return $this
*/
public function setContact($contact)
{
$this->contact = $contact;
return $this;
}
/**
* @param $subject
* @return $this
*/
public function setSubject($subject)
{
$this->subject = $this->parseTemplate($subject, false, $this->contact);
return $this;
}
/**
* @param $body
* @return $this
*/
public function setBody($body)
{
$this->body = $this->parseTemplate($body, true);
return $this;
}
/**
* @param $template_style
* @return $this
*/
public function setTemplate($template_style)
{
$this->template_style = $template_style;
return $this;
}
public function setAttachments($attachments)
{
$this->attachments[] = $attachments;
}
/**
* @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;
}
}