mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Reimplimented customer email templating in laravel5 branch.
Usable raw invoice variables/travaersial and custom translations.
This commit is contained in:
parent
b9c00a0531
commit
f1aac048b6
@ -677,4 +677,29 @@ class Utils
|
||||
|
||||
fwrite($output, "\n");
|
||||
}
|
||||
|
||||
public static function stringToObjectResolution($baseObject, $rawPath)
|
||||
{
|
||||
$val = '';
|
||||
|
||||
if (!is_object($baseObject)) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
$path = preg_split('/->/', $rawPath);
|
||||
$node = $baseObject;
|
||||
|
||||
while (($prop = array_shift($path)) !== null) {
|
||||
if (property_exists($node, $prop)) {
|
||||
$val = $node->$prop;
|
||||
$node = $node->$prop;
|
||||
} else if (is_object($node) && isset($node->$prop)) {
|
||||
$node = $node->{$prop};
|
||||
} else if ( method_exists($node, $prop)) {
|
||||
$val = call_user_func(array($node, $prop));
|
||||
}
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ class ContactMailer extends Mailer
|
||||
$emailTemplate = $invoice->account->getEmailTemplate($entityType);
|
||||
$invoiceAmount = Utils::formatMoney($invoice->getRequestedAmount(), $invoice->client->getCurrencyId());
|
||||
|
||||
$this->initClosure($invoice);
|
||||
|
||||
foreach ($invoice->invitations as $invitation) {
|
||||
if (!$invitation->user || !$invitation->user->email || $invitation->user->trashed()) {
|
||||
return false;
|
||||
@ -40,7 +42,8 @@ class ContactMailer extends Mailer
|
||||
'$client' => $invoice->client->getDisplayName(),
|
||||
'$account' => $accountName,
|
||||
'$contact' => $invitation->contact->getDisplayName(),
|
||||
'$amount' => $invoiceAmount
|
||||
'$amount' => $invoiceAmount,
|
||||
'$advancedRawInvoice->' => '$'
|
||||
];
|
||||
|
||||
// Add variables for available payment types
|
||||
@ -49,6 +52,7 @@ class ContactMailer extends Mailer
|
||||
}
|
||||
|
||||
$data['body'] = str_replace(array_keys($variables), array_values($variables), $emailTemplate);
|
||||
$data['body'] = preg_replace_callback('/\{\{\$?(.*)\}\}/', $this->advancedTemplateHandler, $data['body']);
|
||||
$data['link'] = $invitation->getLink();
|
||||
$data['entityType'] = $entityType;
|
||||
$data['invoice_id'] = $invoice->id;
|
||||
@ -123,4 +127,22 @@ class ContactMailer extends Mailer
|
||||
|
||||
$this->sendTo($email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
|
||||
}
|
||||
|
||||
private function initClosure($object)
|
||||
{
|
||||
$this->advancedTemplateHandler = function($match) use ($object) {
|
||||
for ($i = 1; $i < count($match); $i++) {
|
||||
$blobConversion = $match[$i];
|
||||
|
||||
if (isset($$blobConversion)) {
|
||||
return $$blobConversion;
|
||||
} else if (preg_match('/trans\(([\w\.]+)\)/', $blobConversion, $regexTranslation)) {
|
||||
return trans($regexTranslation[1]);
|
||||
} else if (strpos($blobConversion, '->') !== false) {
|
||||
return Utils::stringToObjectResolution($object, $blobConversion);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user