From 0f98d18adedbd7be1999843d0c1e0423f6fac3dc Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Mon, 11 Dec 2023 14:27:40 +0100 Subject: [PATCH] feat(ZMS-1711): use custom provider template --- zmsdb/src/Zmsdb/Calldisplay.php | 2 ++ .../src/Zmsentities/Helper/Messaging.php | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/zmsdb/src/Zmsdb/Calldisplay.php b/zmsdb/src/Zmsdb/Calldisplay.php index 95e4bbe8b..220efa74c 100644 --- a/zmsdb/src/Zmsdb/Calldisplay.php +++ b/zmsdb/src/Zmsdb/Calldisplay.php @@ -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; diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index 35f6136ba..65272ce37 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -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); } @@ -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])) { @@ -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,