Skip to content

Commit

Permalink
Merge pull request #61 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 11, 2023
2 parents 1853c7d + 0f98d18 commit a0df6c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions zmsdb/src/Zmsdb/Calldisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function readImage(Entity $entity)
->fetchOne((new Query\Calldisplay(Query\Base::SELECT))
->getQueryImage(), ['name' => "logo.png"]);
}

return null;
$mime = pathinfo($image['name'], PATHINFO_EXTENSION);
$image['mime'] = ($mime == 'jpg') ? 'jpeg' : $mime;
return $image;
Expand Down
27 changes: 25 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,8 +193,15 @@ 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)
{
$providerName = $process->getCurrentScope()->getProvider()->getDisplayName();
$providerTemplate = 'custom/' . $type . '/' . $status . '/' . (self::slugify($providerName)) . '.twig';

if (file_exists('messaging/' . $providerTemplate)) {
return $providerTemplate;
}

$template = null;
if (Property::__keyExists($type, self::$templates)) {
if (Property::__keyExists($status, self::$templates[$type])) {
Expand All @@ -204,6 +211,22 @@ protected static function getTemplate($type, $status)
return $template;
}

private static function slugify($text, string $divider = '_')
{
$text = preg_replace('~[^\pL\d]+~u', $divider, $text);
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text = preg_replace('~[^-\w]+~', '', $text);
$text = trim($text, $divider);
$text = preg_replace('~-+~', $divider, $text);
$text = strtolower($text);

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

return $text;
}

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

0 comments on commit a0df6c6

Please sign in to comment.