Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
plaintemplate.php
1<?php
2
4
8
9Loc::loadMessages(__FILE__);
10
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(
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}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29