Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
rc.php
1<?php
9
11
19
20Loc::loadMessages(__FILE__);
21
26class Rc
27{
28 const IMAGE_DIR = '/images/sender/preset/events/';
29
38 public static function onPresetTemplateList($templateType = null, $templateId = null, $messageCode = null)
39 {
40 if($templateType && $templateType !== 'BASE')
41 {
42 return array();
43 }
44 if($messageCode && !in_array($messageCode, self::getProvidedMessageCodes()))
45 {
46 return array();
47 }
48
49 return self::getTemplates($templateId, $messageCode = null);
50 }
51
52 private static function getProvidedMessageCodes()
53 {
54 return [
55 'rc_lead',
56 'rc_deal',
57 ];
58 }
59
60 private static function getListByType()
61 {
62 $list = [
63 [
64 'CODE' => 'birthday',
65 'SEGMENT_CODES' => ['case_crm_client_birthday', 'case_crm_lead_birthday'],
66 'HINT' => Loc::getMessage('SENDER_PRESET_TEMPLATE_RC_HINT_EVERY_DAY'),
67 'DISPATCH' => [
68 'METHOD_CODE' => Dispatch\Method::SCHEDULE,
69 'TIMES_OF_DAY' => '09:00',
70 'DAYS_OF_WEEK' => "1,2,3,4,5,6,7",
71 ]
72 ],
73 [
74 'CODE' => 'nps',
75 'SEGMENT_CODES' => ['case_crm_client_aft_deal_clo'],
76 'HINT' => Loc::getMessage('SENDER_PRESET_TEMPLATE_RC_HINT_NPS'),
77 'DISPATCH' => [
78 'METHOD_CODE' => Dispatch\Method::SCHEDULE,
79 'TIMES_OF_DAY' => '09:00',
80 'DAYS_OF_WEEK' => "1,2,3,4,5,6,7",
81 ]
82 ],
83 ];
84
85 foreach ($list as $index => $item)
86 {
87 $code = mb_strtoupper($item['CODE']);
88 $msgPrefix = 'SENDER_PRESET_TEMPLATE_RC_' . $code . '_';
89 foreach (['NAME', 'DESC', 'TITLE', 'TEXT'] as $key)
90 {
91 $item[$key] = Loc::getMessage($msgPrefix . $key);
92 }
93
94 $list[$index] = $item;
95 }
96
97 foreach (Holiday::getList() as $holiday)
98 {
99 $code = $holiday->getCode();
100 $name = $holiday->getName();
101 $formattedDate = $holiday->formatDate();
102
103 $item = [
104 'CODE' => $holiday->getCode(),
105 'SEGMENT_CODES' => ["case_crm_client_$code"],
106 'HINT' => Loc::getMessage(
107 'SENDER_PRESET_TEMPLATE_RC_HINT_ONE_DAY',
108 [
109 '%run_date%' => PrettyDate::formatDate($holiday->getDateFrom()),
110 '%date_from%' => PrettyDate::formatDate($holiday->getDateFrom()),
111 '%date_to%' => PrettyDate::formatDate($holiday->getDateTo()),
112 ]
113 ),
114 'DISPATCH' => [
115 'METHOD_CODE' => Dispatch\Method::SCHEDULE,
116 'TIMES_OF_DAY' => '09:00',
117 'DAYS_OF_WEEK' => "1,2,3,4,5,6,7",
118 'DAYS_OF_MONTH' => $holiday->getDay(),
119 'MONTHS_OF_YEAR' => $holiday->getMonth(),
120 ]
121 ];
122
123 $msgPrefix = "SENDER_PRESET_TEMPLATE_RC_HOLIDAY_";
124 foreach (['NAME', 'DESC', 'TITLE', 'TEXT'] as $key)
125 {
126 $item[$key] = Loc::getMessage(
127 $msgPrefix . $key,
128 [
129 '%holiday_name%' => $name,
130 '%holiday_date%' => $formattedDate,
131 ]
132 );
133 $item[$key] = Texts::replace($item[$key] ?? '');
134 }
135
136 $list[] = $item;
137 }
138
139 return $list;
140 }
141
142 private static function getTemplates($templateId = null, $messageCode = null)
143 {
144 $messageCodes = $messageCode ? array($messageCode) : self::getProvidedMessageCodes();
145
146 $result = [
147 [
148 'ID' => 'empty',
149 'TYPE' => Type::getCode(Type::BASE),
150 'CATEGORY' => Category::getCode(Category::CASES),
151 'MESSAGE_CODE' => $messageCodes,
152 'VERSION' => 2,
153 'HOT' => false,
154 'ICON' => BX_ROOT . self::IMAGE_DIR . "empty.png",
155
156 'NAME' => Loc::getMessage('SENDER_PRESET_TEMPLATE_RC_EMPTY'),
157 'DESC' => Loc::getMessage('SENDER_PRESET_TEMPLATE_RC_EMPTY_DESC'),
158 'FIELDS' => [
159 'COMMENT' => [
160 'CODE' => 'COMMENT',
161 'VALUE' => '',
162 ]
163 ],
164 ]
165 ];
166 foreach (self::getListByType() as $item)
167 {
168 $originalCode = mb_strtolower($item['CODE']);
169 $code = 'rc_'.mb_strtolower($item['CODE']);
170 if($templateId && $code !== $templateId)
171 {
172 continue;
173 }
174
175 $segmentTiles = UI\TileView::create();
176 $segments = Segment::getList([
177 'select' => ['ID', 'NAME'],
178 'filter' => ['=CODE' => $item['SEGMENT_CODES']]
179 ]);
180 foreach ($segments as $segment)
181 {
182 $segmentTiles->addTile($segment['ID'], $segment['NAME']);
183 }
184
185 $result[] = array(
186 'ID' => $code,
187 'TYPE' => Type::getCode(Type::BASE),
188 'CATEGORY' => Category::getCode(Category::CASES),
189 'MESSAGE_CODE' => $messageCodes,
190 'VERSION' => 2,
191 'HOT' => $item['HOT'] ?? '',
192 'ICON' => BX_ROOT . self::IMAGE_DIR . "$originalCode.png",
193
194 'NAME' => $item['NAME'] ?? '',
195 'DESC' => $item['DESC'] ?? '',
196 'HINT' => $item['HINT'] ?? '',
197 'FIELDS' => [
198 'TITLE' => [
199 'CODE' => 'TITLE',
200 'VALUE' => $item['TITLE'] ?? '',
201 ],
202 'COMMENT' => [
203 'CODE' => 'COMMENT',
204 'VALUE' => $item['TEXT'] ?? '',
205 ],
206 'ALWAYS_ADD' => [
207 'CODE' => 'ALWAYS_ADD',
208 'VALUE' => 'Y',
209 ],
210 ],
211 'SEGMENTS' => $segmentTiles->getTiles(),
212 'DISPATCH' => $item['DISPATCH'],
213 );
214 }
215
216 return $result;
217 }
218}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList($languageId=LANGUAGE_ID)
Definition holiday.php:51
static onPresetTemplateList($templateType=null, $templateId=null, $messageCode=null)
Definition rc.php:38