1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
TemplateManager.php
См. документацию.
1<?php
2
3namespace Bitrix\MessageService\Providers\Edna\WhatsApp;
4
5use Bitrix\Main\ArgumentException;
6use Bitrix\Main\Web\Json;
7use Bitrix\MessageService\Providers\Constants\InternalOption;
8use Bitrix\MessageService\Providers\Edna\EdnaRu;
9
11{
12
13 protected EdnaRu $utils;
15
17 {
18 parent::__construct($providerId);
19
20 $this->utils = $utils;
21 $this->emoji = $emoji;
22 }
23
28 public function getTemplatesList(array $context = null): array
29 {
30 $templatesResult = $this->utils->getMessageTemplates();
31 if (!$templatesResult->isSuccess())
32 {
33 return [];
34 }
35
36 $templates = $templatesResult->getData();
37 if (!is_array($templates))
38 {
39 return [];
40 }
41
42 $result = [];
43 foreach ($templates as $template)
44 {
45 $tmp = [
46 'ID' => Json::encode($template['content']),
47 'ORIGINAL_ID' => (int)$template['id'],
48 'TITLE' => $template['name'],
49 'PREVIEW' => $template['content']['text'] ?? '',
50 ];
51
52 if (!empty($template['content']['header']['text']))
53 {
54 $tmp['HEADER'] = $template['content']['header']['text'];
55 }
56 if (!empty($template['content']['footer']['text']))
57 {
58 $tmp['FOOTER'] = $template['content']['footer']['text'];
59 }
60 if (!empty($template['content']['keyboard']['rows']))
61 {
62 $tmp['KEYBOARD'] = $template['content']['keyboard'];
63 }
64 if (!empty($template['placeholders']))
65 {
66 $tmp['PLACEHOLDERS'] = [];
67 }
68 if (!empty($template['placeholders']['text']))
69 {
70 $tmp['PLACEHOLDERS']['PREVIEW'] = $template['placeholders']['text'];
71 }
72 if (!empty($template['placeholders']['header']))
73 {
74 $tmp['PLACEHOLDERS']['HEADER'] = $template['placeholders']['header'];
75 }
76 if (!empty($template['placeholders']['footer']))
77 {
78 $tmp['PLACEHOLDERS']['FOOTER'] = $template['placeholders']['footer'];
79 }
80
81 $result[] = $tmp;
82 }
83
84 return $result;
85 }
86
87 public function prepareTemplate($templateData): array
88 {
89 try
90 {
91 $messageTemplateDecoded = Json::decode($templateData);
92 $messageTemplateDecoded =
93 $this->emoji->convertEmojiInTemplate($messageTemplateDecoded, InternalOption::EMOJI_ENCODE);
94 }
95 catch (\Bitrix\Main\ArgumentException $e)
96 {
97 throw new ArgumentException('Incorrect message template');
98 }
99
100 return $messageTemplateDecoded;
101 }
102
103 public function isTemplatesBased(): bool
104 {
105 return true;
106 }
107
108}
__construct(string $providerId, EdnaRu $utils, EmojiConverter $emoji)
Определения TemplateManager.php:16
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
$template
Определения file_edit.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$context
Определения csv_new_setup.php:223