Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
texts.php
1
<?php
8
namespace
Bitrix\Sender\Preset\Templates
;
9
10
use
Bitrix\Main\Localization\Loc
;
11
12
use
Bitrix\Sender\Message
;
13
use
Bitrix\Sender\Integration
;
14
15
Loc::loadMessages
(__FILE__);
16
21
class
Texts
22
{
23
const
IMAGE_DIR
=
'/images/sender/preset/template_v2/'
;
24
30
public
static
function
getCodes
()
31
{
32
return
array(
33
'hot_unplanned'
,
34
'unplanned'
,
35
'hot_lead2client'
,
36
'lead2client'
,
37
'hot_inc_profits'
,
38
'inc_profits'
,
39
'hot_brand2brain'
,
40
'brand2brain'
,
41
'hot_repeated'
,
42
'repeated'
,
43
'hot_push2deal'
,
44
'push2deal'
,
45
'hot_wakeup'
,
46
'wakeup'
,
47
'hot_satisfy'
,
48
'satisfy'
,
49
'hot_birthday'
,
50
'birthday'
,
51
'hot_inform_event'
,
52
'inform_event'
,
53
'hot_invite2event'
,
54
'invite2event'
,
55
);
56
}
57
64
public
static
function
getListByType
($type)
65
{
66
$result = array();
67
foreach
(self::getCodes() as $code)
68
{
69
$item =
self::getByCode
($code);
70
if
(empty($item[
'TYPES'
][$type]))
71
{
72
continue
;
73
}
74
75
$fields = $item[
'TYPES'
][$type];
76
unset($item[
'TYPES'
]);
77
foreach
($fields as $key => $value)
78
{
79
$item[$key] = $value;
80
}
81
82
$result[] = $item;
83
}
84
85
return
$result;
86
}
87
94
public
static
function
replace
($text =
''
)
95
{
96
static
$replace =
null
;
97
if
($replace ===
null
)
98
{
99
$card = array();
100
foreach
(Integration\
EventHandler::onSenderCompanyCard
() as $card)
101
{
102
if
(!isset($card[
'DATA'
]) || !is_array($card[
'DATA'
]))
103
{
104
continue
;
105
}
106
$card = $card[
'DATA'
];
107
108
if
(!$card[
'COMPANY_NAME'
])
109
{
110
continue
;
111
}
112
113
break
;
114
}
115
116
if
(!isset($card[
'COMPANY_NAME'
]) || !$card[
'COMPANY_NAME'
])
117
{
118
$card[
'COMPANY_NAME'
] =
Loc::getMessage
(
'SENDER_PRESET_TEMPLATE_DEFAULT_COMPANY'
);
119
}
120
121
if
(!isset($card[
'PHONE'
]) || !$card[
'PHONE'
])
122
{
123
$card[
'PHONE'
] =
Loc::getMessage
(
'SENDER_PRESET_TEMPLATE_DEFAULT_PHONE'
);
124
}
125
126
$replace = array(
127
'%COMPANY%'
=> $card[
'COMPANY_NAME'
],
128
'%PHONE_FORMATTED%'
=> $card[
'PHONE'
],
129
'%PHONE%'
=> preg_replace(
'/[^\d]/'
,
''
, $card[
'PHONE'
]),
130
);
131
}
132
133
if
(count($replace) === 0)
134
{
135
return
$text;
136
}
137
138
return
str_replace(array_keys($replace), array_values($replace), $text);
139
}
140
141
protected
static
function
getMessage
($code)
142
{
143
return
self::replace
(
Loc::getMessage
($code));
144
}
145
152
public
static
function
getByCode
($code)
153
{
154
$dictionary = array(
155
Message
\iBase::CODE_MAIL => array(
156
'SUBJECT'
,
157
'TEXT_HEAD'
,
158
'TEXT_BODY'
159
),
160
Message
\iBase::CODE_SMS => array(
161
'TEXT'
162
),
163
Message
\iBase::CODE_IM => array(
164
'TEXT'
165
),
166
Message
\iBase::CODE_AUDIO_CALL => array(
167
'AUDIO_FILE'
168
),
169
);
170
171
$isHot = mb_strpos($code,
'hot_'
) === 0;
172
$iconPath = $isHot? mb_substr($code, 4) : $code;
173
$iconPath = BX_ROOT . self::IMAGE_DIR . $iconPath .
'.png'
;
174
175
$code = mb_strtoupper($code);
176
$result = array(
177
'CODE'
=> $code,
178
'NAME'
=>
Loc::getMessage
(
'SENDER_PRESET_TEMPLATE_'
. $code .
'_NAME'
),
179
'DESC'
=>
Loc::getMessage
(
'SENDER_PRESET_TEMPLATE_'
. $code .
'_DESC'
),
180
'HOT'
=> $isHot,
181
'ICON'
=> $iconPath,
182
'TYPES'
=> array(),
183
);
184
185
foreach
($dictionary as $type => $keys)
186
{
187
if
(isset($result[
'TYPES'
][$type])
188
&& !is_array($result[
'TYPES'
][$type]))
189
{
190
$result[
'TYPES'
][$type] = array();
191
}
192
193
foreach
($keys as $key)
194
{
195
$msgId =
'SENDER_PRESET_'
. $type .
'_'
. $code .
'_'
. $key;
196
$result[
'TYPES'
][$type][$key] =
self::getMessage
(mb_strtoupper($msgId));
197
}
198
}
199
200
return
(mb_strlen($result[
'NAME'
]) && !empty($result[
'TYPES'
])) ? $result :
null
;
201
}
202
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sender\Entity\Message
Definition
message.php:27
Bitrix\Sender\Integration\EventHandler\onSenderCompanyCard
static onSenderCompanyCard()
Definition
eventhandler.php:57
Bitrix\Sender\Preset\Templates\Texts
Definition
texts.php:22
Bitrix\Sender\Preset\Templates\Texts\getListByType
static getListByType($type)
Definition
texts.php:64
Bitrix\Sender\Preset\Templates\Texts\getCodes
static getCodes()
Definition
texts.php:30
Bitrix\Sender\Preset\Templates\Texts\getMessage
static getMessage($code)
Definition
texts.php:141
Bitrix\Sender\Preset\Templates\Texts\replace
static replace($text='')
Definition
texts.php:94
Bitrix\Sender\Preset\Templates\Texts\IMAGE_DIR
const IMAGE_DIR
Definition
texts.php:23
Bitrix\Sender\Preset\Templates\Texts\getByCode
static getByCode($code)
Definition
texts.php:152
Bitrix\Sender\Integration
Bitrix\Sender\Message
Definition
adapter.php:9
Bitrix\Sender\Preset\Templates
Definition
audiocall.php:9
modules
sender
lib
preset
templates
texts.php
Создано системой
1.10.0