Skip to content

Commit

Permalink
Merge pull request #74 from it-at-m/feature-1711-custom-mail-templates
Browse files Browse the repository at this point in the history
Feature 1711 custom mail templates
  • Loading branch information
manjencic authored Dec 18, 2023
2 parents d9fba05 + 7ee1ca6 commit a1d5af2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions zmsdb/src/Zmsdb/Calldisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function readImage(Entity $entity)
->fetchOne((new Query\Calldisplay(Query\Base::SELECT))
->getQueryImage(), ['name' => "logo.png"]);
}

$mime = pathinfo($image['name'], PATHINFO_EXTENSION);
$image['mime'] = ($mime == 'jpg') ? 'jpeg' : $mime;
return $image;
Expand Down
36 changes: 34 additions & 2 deletions zmsentities/src/Zmsentities/Helper/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function getMailContent(
$client = $mainProcess->getFirstClient();
}

$template = self::getTemplate('mail', $status);
$template = self::getTemplate('mail', $status, $mainProcess);
if ($initiator) {
$template = self::getTemplate('admin', $status);
}
Expand Down Expand Up @@ -193,17 +193,49 @@ public static function getNotificationContent(Process $process, Config $config,
return $message;
}

protected static function getTemplate($type, $status)
protected static function getTemplate($type, $status, ?Process $process = null)
{
$template = null;
if (Property::__keyExists($type, self::$templates)) {
if (Property::__keyExists($status, self::$templates[$type])) {
$template = self::$templates[$type][$status];
}
}

if ($process) {
$provider = $process->scope->provider;
$providerName = $provider->displayName;
$providerTemplateName = self::getProviderTemplateName($providerName);
$providerTemplateFolder = 'custom/' . $providerTemplateName . '/';

if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplateFolder . $template)) {
return $providerTemplateFolder . $template;
}
}

return $template;
}

private static function getProviderTemplateName($providerName)
{
if (strpos($providerName, '(')) {
$providerName = substr($providerName, 0, strpos($providerName, '('));
}
$divider = '-';
$providerTemplate = preg_replace('~[^\pL\d]+~u', $divider, $providerName);
$providerTemplate = iconv('utf-8', 'us-ascii//TRANSLIT', $providerTemplate);
$providerTemplate = preg_replace('~[^-\w]+~', '', $providerTemplate);
$providerTemplate = trim($providerTemplate, $divider);
$providerTemplate = preg_replace('~-+~', $divider, $providerTemplate);
$providerTemplate = strtolower($providerTemplate);

if (empty($providerTemplate)) {
return 'none';
}

return $providerTemplate;
}

public static function getMailSubject(
Process $process,
Config $config,
Expand Down

0 comments on commit a1d5af2

Please sign in to comment.