akaunting 3.0 (the last dance)
This commit is contained in:
@ -6,11 +6,19 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification as BaseNotification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
abstract class Notification extends BaseNotification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Custom mail subject, body, etc.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $custom_mail;
|
||||
|
||||
/**
|
||||
* Create a notification instance.
|
||||
*/
|
||||
@ -33,31 +41,38 @@ abstract class Notification extends BaseNotification implements ShouldQueue
|
||||
/**
|
||||
* Initialise the mail representation of the notification.
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function initMessage()
|
||||
public function initMailMessage(): MailMessage
|
||||
{
|
||||
app('url')->defaults(['company_id' => company_id()]);
|
||||
|
||||
$message = (new MailMessage)
|
||||
->from(config('mail.from.address'), config('mail.from.name'))
|
||||
->subject($this->getSubject())
|
||||
->view('partials.email.body', ['body' => $this->getBody()]);
|
||||
->view('components.email.body', ['body' => $this->getBody()]);
|
||||
|
||||
if (!empty($this->custom_mail['cc'])) {
|
||||
$message->cc($this->custom_mail['cc']);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function getSubject()
|
||||
public function getSubject(): string
|
||||
{
|
||||
return $this->replaceTags($this->template->subject);
|
||||
return !empty($this->custom_mail['subject'])
|
||||
? $this->custom_mail['subject']
|
||||
: $this->replaceTags($this->template->subject);
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->replaceTags($this->template->body);
|
||||
$body = !empty($this->custom_mail['body']) ? $this->custom_mail['body'] : $this->replaceTags($this->template->body);
|
||||
|
||||
return $body . $this->getFooter();
|
||||
}
|
||||
|
||||
public function replaceTags($content)
|
||||
public function replaceTags(string $content): string
|
||||
{
|
||||
$pattern = $this->getTagsPattern();
|
||||
$replacement = $this->applyQuote($this->getTagsReplacement());
|
||||
@ -65,7 +80,16 @@ abstract class Notification extends BaseNotification implements ShouldQueue
|
||||
return $this->revertQuote(preg_replace($pattern, $replacement, $content));
|
||||
}
|
||||
|
||||
public function getTagsPattern()
|
||||
public function getFooter()
|
||||
{
|
||||
$url = 'https://akaunting.com/lp/accounting-software?utm_source=email&utm_medium=software&utm_campaign=footer&utm_content=' . $this->template->alias;
|
||||
|
||||
$get_started = '<a href="' . $url . '" style="color: #676ba2; text-decoration: none;">' . trans('footer.get_started') . '</a>';
|
||||
|
||||
return view('components.email.footer', compact('url', 'get_started'));
|
||||
}
|
||||
|
||||
public function getTagsPattern(): array
|
||||
{
|
||||
$pattern = [];
|
||||
|
||||
@ -76,17 +100,35 @@ abstract class Notification extends BaseNotification implements ShouldQueue
|
||||
return $pattern;
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
public function getTags(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTagsReplacement()
|
||||
public function getTagsReplacement(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function applyQuote($vars)
|
||||
public function getTagsBinding(): array
|
||||
{
|
||||
$bindings = [];
|
||||
|
||||
$tags = $this->getTags();
|
||||
$replacements = $this->getTagsReplacement();
|
||||
|
||||
$wrappers = ['{', '}'];
|
||||
|
||||
foreach ($tags as $index => $tag) {
|
||||
$key = Str::replace($wrappers, '', $tag);
|
||||
|
||||
$bindings[$key] = $replacements[$index];
|
||||
}
|
||||
|
||||
return $bindings;
|
||||
}
|
||||
|
||||
public function applyQuote(array $vars): array
|
||||
{
|
||||
$new_vars = [];
|
||||
|
||||
@ -97,8 +139,16 @@ abstract class Notification extends BaseNotification implements ShouldQueue
|
||||
return $new_vars;
|
||||
}
|
||||
|
||||
public function revertQuote($content)
|
||||
public function revertQuote(string $content): string
|
||||
{
|
||||
return str_replace('\\', '', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 3.0
|
||||
*/
|
||||
public function initMessage()
|
||||
{
|
||||
return $this->initMailMessage();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user