From 0f98d18adedbd7be1999843d0c1e0423f6fac3dc Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Mon, 11 Dec 2023 14:27:40 +0100 Subject: [PATCH 01/11] 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, From ad898cc94861b74505d63b94b966b4c049570e64 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 10:13:23 +0100 Subject: [PATCH 02/11] feat(ZMS-1711): fix custom template --- zmsdb/src/Zmsdb/Calldisplay.php | 1 - .../src/Zmsentities/Helper/Messaging.php | 33 ++++++------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/zmsdb/src/Zmsdb/Calldisplay.php b/zmsdb/src/Zmsdb/Calldisplay.php index 220efa74c..b525f5531 100644 --- a/zmsdb/src/Zmsdb/Calldisplay.php +++ b/zmsdb/src/Zmsdb/Calldisplay.php @@ -86,7 +86,6 @@ public function readImage(Entity $entity) ->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 65272ce37..fc0090d10 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -115,9 +115,10 @@ public static function getMailContent( } $template = self::getTemplate('mail', $status, $mainProcess); - if ($initiator) { - $template = self::getTemplate('admin', $status); - } + return $template; + //if ($initiator) { + // $template = self::getTemplate('admin', $status); + //} if (!$template) { $exception = new \BO\Zmsentities\Exception\TemplateNotFound("Template for status $status not found"); $exception->data = $status; @@ -195,11 +196,13 @@ public static function getNotificationContent(Process $process, Config $config, protected static function getTemplate($type, $status, ?Process $process = null) { - $providerName = $process->getCurrentScope()->getProvider()->getDisplayName(); - $providerTemplate = 'custom/' . $type . '/' . $status . '/' . (self::slugify($providerName)) . '.twig'; + if ($process) { + $providerName = $process->getCurrentScope()->getProvider()->getName(); + $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerName . '.twig'; - if (file_exists('messaging/' . $providerTemplate)) { - return $providerTemplate; + if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplate)) { + return $providerTemplate; + } } $template = null; @@ -211,22 +214,6 @@ protected static function getTemplate($type, $status, ?Process $process = null) 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, From b19f436687500976c696867a8ed3edb064dc2600 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 10:14:57 +0100 Subject: [PATCH 03/11] feat(ZMS-1711): fix custom template --- zmsentities/src/Zmsentities/Helper/Messaging.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index fc0090d10..39e7fbc2d 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -115,10 +115,9 @@ public static function getMailContent( } $template = self::getTemplate('mail', $status, $mainProcess); - return $template; - //if ($initiator) { - // $template = self::getTemplate('admin', $status); - //} + if ($initiator) { + $template = self::getTemplate('admin', $status); + } if (!$template) { $exception = new \BO\Zmsentities\Exception\TemplateNotFound("Template for status $status not found"); $exception->data = $status; From b7324e35598ec8fc6690adf9c0ed5d314f4b11fa Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 11:25:24 +0100 Subject: [PATCH 04/11] feat(ZMS-1711): fix template --- zmsentities/src/Zmsentities/Helper/Messaging.php | 1 + .../B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" | 1 + 2 files changed, 2 insertions(+) create mode 100644 "zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index 39e7fbc2d..af673258a 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -197,6 +197,7 @@ protected static function getTemplate($type, $status, ?Process $process = null) { if ($process) { $providerName = $process->getCurrentScope()->getProvider()->getName(); + $providerName = str_replace(['(', ')', '/'], '', $providerName); $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerName . '.twig'; if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplate)) { diff --git "a/zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" "b/zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" new file mode 100644 index 000000000..2e65e8aba --- /dev/null +++ "b/zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" @@ -0,0 +1 @@ +dasldsapdsaasdsa \ No newline at end of file From 5415e6e05f55c252a090c0ba974cc26f66d6faa5 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 11:26:23 +0100 Subject: [PATCH 05/11] feat(ZMS-1711): remove custom template --- .../B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" diff --git "a/zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" "b/zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" deleted file mode 100644 index 2e65e8aba..000000000 --- "a/zmsentities/templates/messaging/custom/mail/appointment/B\303\274rgerb\303\274ro Forstenrieder Allee KVR-II234.twig" +++ /dev/null @@ -1 +0,0 @@ -dasldsapdsaasdsa \ No newline at end of file From 36de873783d0c5fad19ed6d470395c43c0616e30 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 11:56:12 +0100 Subject: [PATCH 06/11] feat(ZMS-1711): custom scope template --- zmsentities/src/Zmsentities/Helper/Messaging.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index af673258a..bcaa12942 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -196,12 +196,12 @@ public static function getNotificationContent(Process $process, Config $config, protected static function getTemplate($type, $status, ?Process $process = null) { if ($process) { - $providerName = $process->getCurrentScope()->getProvider()->getName(); - $providerName = str_replace(['(', ')', '/'], '', $providerName); - $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerName . '.twig'; + $scopeName = $process->getCurrentScope()->getName(); + $scopeName = str_replace(['(', ')', '/'], '', $scopeName); + $scopeTemplate = 'custom/' . $type . '/' . $status . '/' . $scopeName . '.twig'; - if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplate)) { - return $providerTemplate; + if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $scopeTemplate)) { + return $scopeTemplate; } } From 29d66c88abac579ffc013e1474e91c6f57fb911e Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 14:23:26 +0100 Subject: [PATCH 07/11] feat(ZMS-1711): fix loading template --- zmsentities/src/Zmsentities/Helper/Messaging.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index bcaa12942..478d0eb87 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -196,12 +196,13 @@ public static function getNotificationContent(Process $process, Config $config, protected static function getTemplate($type, $status, ?Process $process = null) { if ($process) { - $scopeName = $process->getCurrentScope()->getName(); - $scopeName = str_replace(['(', ')', '/'], '', $scopeName); - $scopeTemplate = 'custom/' . $type . '/' . $status . '/' . $scopeName . '.twig'; + $provider = $process->getCurrentScope()->getProvider(); + $providerName = $provider->getDisplayName() ?? $provider->getName(); + $providerName = str_replace(['(', ')', '/'], '', $providerName); + $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerName . '.twig'; - if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $scopeTemplate)) { - return $scopeTemplate; + if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplate)) { + return $providerTemplate; } } From 1dc3a74fcfe52809c1fe558d9f163c4a93758808 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 16:43:06 +0100 Subject: [PATCH 08/11] feat(ZMS-1711): fix template --- .../src/Zmsentities/Helper/Messaging.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index 478d0eb87..e851399c0 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -198,8 +198,8 @@ protected static function getTemplate($type, $status, ?Process $process = null) if ($process) { $provider = $process->getCurrentScope()->getProvider(); $providerName = $provider->getDisplayName() ?? $provider->getName(); - $providerName = str_replace(['(', ')', '/'], '', $providerName); - $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerName . '.twig'; + $providerTemplateName = self::getProviderTemplateName($providerName); + $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerTemplateName . '.twig'; if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplate)) { return $providerTemplate; @@ -215,6 +215,26 @@ protected static function getTemplate($type, $status, ?Process $process = null) 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, From a926588e153a2bfacb7c363c2267d9d81593a2bb Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 17:12:05 +0100 Subject: [PATCH 09/11] feat(ZMS-1711): fix template --- zmsentities/src/Zmsentities/Helper/Messaging.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index e851399c0..9040d17df 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -196,7 +196,7 @@ public static function getNotificationContent(Process $process, Config $config, protected static function getTemplate($type, $status, ?Process $process = null) { if ($process) { - $provider = $process->getCurrentScope()->getProvider(); + $provider = $process->getFirstAppointment()->getScope()->getProvider(); $providerName = $provider->getDisplayName() ?? $provider->getName(); $providerTemplateName = self::getProviderTemplateName($providerName); $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerTemplateName . '.twig'; From f26c7f76360e66bb184b1785b8a48b73db93e668 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Wed, 13 Dec 2023 17:25:13 +0100 Subject: [PATCH 10/11] feat(ZMS-1711): fix template --- zmsentities/src/Zmsentities/Helper/Messaging.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index 9040d17df..73a8a2304 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -196,8 +196,8 @@ public static function getNotificationContent(Process $process, Config $config, protected static function getTemplate($type, $status, ?Process $process = null) { if ($process) { - $provider = $process->getFirstAppointment()->getScope()->getProvider(); - $providerName = $provider->getDisplayName() ?? $provider->getName(); + $provider = $process->scope->provider; + $providerName = $provider->displayName; $providerTemplateName = self::getProviderTemplateName($providerName); $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerTemplateName . '.twig'; From 7ee1ca6aac2f4999079f979c1d7c583611381175 Mon Sep 17 00:00:00 2001 From: Igor Manjencic Date: Thu, 14 Dec 2023 15:18:52 +0100 Subject: [PATCH 11/11] feat(ZMS-1711): reorganize custom templates --- .../src/Zmsentities/Helper/Messaging.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/zmsentities/src/Zmsentities/Helper/Messaging.php b/zmsentities/src/Zmsentities/Helper/Messaging.php index 73a8a2304..e730c83c4 100644 --- a/zmsentities/src/Zmsentities/Helper/Messaging.php +++ b/zmsentities/src/Zmsentities/Helper/Messaging.php @@ -195,23 +195,24 @@ public static function getNotificationContent(Process $process, Config $config, 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); - $providerTemplate = 'custom/' . $type . '/' . $status . '/' . $providerTemplateName . '.twig'; + $providerTemplateFolder = 'custom/' . $providerTemplateName . '/'; - if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplate)) { - return $providerTemplate; + if (file_exists(TemplateFinder::getTemplatePath() . '/messaging/' . $providerTemplateFolder . $template)) { + return $providerTemplateFolder . $template; } } - $template = null; - if (Property::__keyExists($type, self::$templates)) { - if (Property::__keyExists($status, self::$templates[$type])) { - $template = self::$templates[$type][$status]; - } - } return $template; }