Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
plaintemplate.php
1
<?php
2
3
namespace
Bitrix\Im\Integration\Bizproc\Message
;
4
5
use
Bitrix\Bizproc\FieldType
;
6
use
Bitrix\Main\Error
;
7
use
Bitrix\Main\Localization\Loc
;
8
9
Loc::loadMessages
(__FILE__);
10
11
class
PlainTemplate
extends
Template
12
{
13
protected
string
$messageText
=
''
;
14
15
public
function
buildMessage
(array $messageFields): array
16
{
17
$messageFields[
'MESSAGE'
] = $this->
buildMessageText
();
18
19
return
$messageFields;
20
}
21
22
protected
function
buildMessageText
(): string
23
{
24
$text =
$this->messageText
;
25
26
if
($this->asRobotMessage)
27
{
28
$text .= PHP_EOL . $this->
buildRobotText
();
29
}
30
31
return
$text;
32
}
33
34
protected
function
buildDescriptionText
(): string
35
{
36
$text = mb_substr(\CBPHelper::convertBBtoText($this->messageText), 0, 200);
37
if
(mb_strlen($text) === 200)
38
{
39
$text .=
'...'
;
40
}
41
42
return
$text;
43
}
44
49
protected
function
buildRobotText
()
50
{
51
return
'[i]'
.
Loc::getMessage
(
'IM_BIZPROC_MESSAGE_PLAIN_TEMPLATE_SENT_BY_ROBOT'
) .
'[/i]'
;
52
}
53
54
protected
function
validate
(): void
55
{
56
if
($this->messageText ===
''
)
57
{
58
$fieldsMap = static::getFieldsMap();
59
60
$this->errors->setError(
61
new
Error
(
62
Loc::getMessage
(
63
'IM_BIZPROC_MESSAGE_PLAIN_TEMPLATE_ERROR_EMPTY_FIELD'
,
64
[
'#FIELD_NAME#'
=> $fieldsMap[
'MessageText'
][
'Name'
]]
65
),
66
)
67
);
68
}
69
}
70
71
public
function
setFields
(array $fields): self
72
{
73
if
(!empty($fields[
'MessageText'
]))
74
{
75
$this->messageText = trim(\CBPHelper::stringify($fields[
'MessageText'
]));
76
}
77
78
return
$this;
79
}
80
81
public
static
function
getFieldsMap
(): array
82
{
83
return
[
84
'MessageText'
=> [
85
'Name'
=>
Loc::getMessage
(
'IM_BIZPROC_MESSAGE_PLAIN_TEMPLATE_FIELD_NAME_MESSAGE_TEXT'
),
86
'FieldName'
=>
'template_message_text'
,
87
'Type'
=> FieldType::TEXT,
88
'Required'
=>
true
,
89
'Multiple'
=>
false
,
90
],
91
];
92
}
93
}
Bitrix\Bizproc\FieldType
Definition
fieldtype.php:12
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate
Definition
plaintemplate.php:12
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\validate
validate()
Definition
plaintemplate.php:54
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\buildMessageText
buildMessageText()
Definition
plaintemplate.php:22
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\buildRobotText
buildRobotText()
Definition
plaintemplate.php:49
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\getFieldsMap
static getFieldsMap()
Definition
plaintemplate.php:81
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\buildMessage
buildMessage(array $messageFields)
Definition
plaintemplate.php:15
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\$messageText
string $messageText
Definition
plaintemplate.php:13
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\buildDescriptionText
buildDescriptionText()
Definition
plaintemplate.php:34
Bitrix\Im\Integration\Bizproc\Message\PlainTemplate\setFields
setFields(array $fields)
Definition
plaintemplate.php:71
Bitrix\Im\Integration\Bizproc\Message\Template
Definition
template.php:9
Bitrix\Main\Error
Definition
error.php:14
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\Im\Integration\Bizproc\Message
Definition
alerttemplate.php:3
modules
im
lib
integration
bizproc
message
plaintemplate.php
Создано системой
1.10.0