Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
comment.php
1<?php
2
4
9use Bitrix\Rpa\Driver;
10
12{
15
17 {
18 $this->filesUserFieldEntityId = $filesUserFieldEntityId;
19 $this->filesUserFieldName = $filesUserFieldName;
20 }
21
22 public function getVisualEditorResponse(string $name, int $id = 0, string $text = ''): Component
23 {
24 $formId = 'ui-timeline-comment-'.$name;
25
26 $fileFields = $this->getFileUserFields($id);
27 $isUploadFilesAvailable = isset($fileFields[$this->filesUserFieldName]);
28
29 $params = [
30 'SELECTOR_VERSION' => 2,
31 'FORM_ID' => $formId,
32 'SHOW_MORE' => 'N',
33 'PARSER' => [
34 'Bold', 'Italic', 'Underline', 'Strike',
35 'ForeColor', 'FontList', 'FontSizeList', 'RemoveFormat',
36 'Quote', 'Code', 'InsertCut',
37 'CreateLink', 'Image', 'Table', 'Justify',
38 'InsertOrderedList', 'InsertUnorderedList',
39 'SmileList', 'Source', 'UploadImage', 'InputVideo', 'MentionUser'
40 ],
41 'BUTTONS' => [
42 ($isUploadFilesAvailable ? 'UploadImage' : null),
43 'CreateLink',
44 'InputVideo',
45 'Quote',
46 'MentionUser'
47 ],
48 'TEXT' => [
49 'NAME' => 'MESSAGE',
50 'VALUE' => $text,
51 'HEIGHT' => '120px'
52 ],
53 'LHE' => [
54 'id' => $name,
55 'documentCSS' => 'body {color:#434343;background:#F7FBE9}',
56 'jsObjName' => $name,
57 'width' => '100%',
58 'minBodyWidth' => '100%',
59 'normalBodyWidth' => '100%',
60 'height' => 100,
61 'minBodyHeight' => 100,
62 'showTaskbars' => false,
63 'showNodeNavi' => false,
64 'autoResize' => true,
65 'autoResizeOffset' => 50,
66 'bbCode' => true,
67 'saveOnBlur' => false,
68 'bAllowPhp' => false,
69 'lazyLoad' => true,
70 'limitPhpAccess' => false,
71 'setFocusAfterShow' => true,
72 'askBeforeUnloadPage' => false,
73 'useFileDialogs' => false,
74 'controlsMap' => [
75 ['id' => 'Bold', 'compact' => true, 'sort' => 10],
76 ['id' => 'Italic', 'compact' => true, 'sort' => 20],
77 ['id' => 'Underline', 'compact' => true, 'sort' => 30],
78 ['id' => 'Strikeout', 'compact' => true, 'sort' => 40],
79 ['id' => 'RemoveFormat', 'compact' => true, 'sort' => 50],
80 ['id' => 'Color', 'compact' => true, 'sort' => 60],
81 ['id' => 'FontSelector', 'compact' => false, 'sort' => 70],
82 ['id' => 'FontSize', 'compact' => false, 'sort' => 80],
83 ['separator' => true, 'compact' => false, 'sort' => 90],
84 ['id' => 'OrderedList', 'compact' => true, 'sort' => 100],
85 ['id' => 'UnorderedList', 'compact' => true, 'sort' => 110],
86 ['id' => 'AlignList', 'compact' => false, 'sort' => 120],
87 ['separator' => true, 'compact' => false, 'sort' => 130],
88 ['id' => 'InsertLink', 'compact' => true, 'sort' => 140, 'wrap' => 'bx-b-link-'.$formId],
89 ['id' => 'InsertImage', 'compact' => false, 'sort' => 150],
90 ['id' => 'InsertVideo', 'compact' => true, 'sort' => 160, 'wrap' => 'bx-b-video-'.$formId],
91 ['id' => 'InsertTable', 'compact' => false, 'sort' => 170],
92 ['id' => 'Code', 'compact' => true, 'sort' => 180],
93 ['id' => 'Quote', 'compact' => true, 'sort' => 190, 'wrap' => 'bx-b-quote-'.$formId],
94 ['separator' => true, 'compact' => false, 'sort' => 200],
95 ['id' => 'BbCode', 'compact' => true, 'sort' => 220],
96 ['id' => 'More', 'compact' => true, 'sort' => 230],
97 ],
98 ],
99 'USE_CLIENT_DATABASE' => 'Y',
100 'FILES' => [
101 'VALUE' => [],
102 'DEL_LINK' => '',
103 'SHOW' => 'N'
104 ],
105 'UPLOAD_FILE' => $isUploadFilesAvailable,
106 'UPLOAD_FILE_PARAMS' => ['width' => 400, 'height' => 400],
107 'UPLOAD_WEBDAV_ELEMENT' => $fileFields[$this->filesUserFieldName] ?? false,
108 ];
109
110 return new Component('bitrix:main.post.form', '', $params);
111 }
112
113 public function saveFiles(int $id, array $files): bool
114 {
115 $manager = $this->getUserFieldManager();
116 if ($manager instanceof \CUserTypeManager)
117 {
118 $data = [
119 $this->filesUserFieldName => $files,
120 ];
121 if ($manager->CheckFields($this->filesUserFieldEntityId, $id, $data))
122 {
123 return (bool) $manager->Update($this->filesUserFieldEntityId, $id, $data);
124 }
125 }
126
127 return false;
128 }
129
130 public function getFileUserFields(int $id = 0): array
131 {
132 $manager = $this->getUserFieldManager();
133
134 if($manager && ModuleManager::isModuleInstalled('disk'))
135 {
136 $fileFields = $manager->GetUserFields($this->filesUserFieldEntityId, $id);
137 if(isset($fileFields[$this->filesUserFieldName]))
138 {
139 $fileFields[$this->filesUserFieldName]['~EDIT_FORM_LABEL'] = $this->filesUserFieldName;
140 $fileFields[$this->filesUserFieldName]['TAG'] = 'DOCUMENT ID';
141 }
142
143 return $fileFields;
144 }
145
146 return [];
147 }
148
149 public function getFilesContentResponse(int $id): ?Component
150 {
151 $fileFields = $this->getFileUserFields($id);
152 if($fileFields && !empty($fileFields[$this->filesUserFieldName]['VALUE']))
153 {
154 return new Component('bitrix:system.field.view',
155 $fileFields[$this->filesUserFieldName]["USER_TYPE"]["USER_TYPE_ID"],
156 [
157 "PUBLIC_MODE" => false,
158 "ENABLE_AUTO_BINDING_VIEWER" => true,
159 "LAZYLOAD" => 'Y',
160 'arUserField' => $fileFields[$this->filesUserFieldName],
161 ]
162 );
163 }
164
165 return null;
166 }
167
168 public function sendMentions(
169 int $id,
170 int $fromUserId,
171 string $text,
172 string $message,
173 array $previouslyMentionedUserIds = []
174 ): array
175 {
176 $messageIds = [];
177
178 $parser = new CommentParser();
179 $mentionedUserIds = $parser->getMentionedUserIds($text);
180 $mentionedUserIds = array_filter(
181 $mentionedUserIds,
182 static function($userId) use ($fromUserId, $previouslyMentionedUserIds) {
183 $userId = (int)$userId;
184 return (
185 $userId !== $fromUserId
186 && !in_array($userId, $previouslyMentionedUserIds, true)
187 );
188 }
189 );
190
191 if(empty($mentionedUserIds))
192 {
193 return $messageIds;
194 }
195
196 if(!Loader::includeModule('im'))
197 {
198 return $messageIds;
199 }
200
201 foreach ($mentionedUserIds as $userId)
202 {
203 $userId = (int)$userId;
204
205 $messageIds[] = \CIMNotify::Add([
206 'TO_USER_ID' => $userId,
207 'FROM_USER_ID' => $fromUserId,
208 'NOTIFY_TYPE' => IM_NOTIFY_FROM,
209 'NOTIFY_MODULE' => Driver::MODULE_ID,
210 'NOTIFY_TAG' => 'RPA|MESSAGE_TIMELINE_MENTION|' . $id,
211 'NOTIFY_MESSAGE' => $message,
212 ]);
213 }
214
215 return $messageIds;
216 }
217
218 public function getUserGenderSuffix(int $userId): string
219 {
220 $userData = UserTable::getList([
221 'select' => ['PERSONAL_GENDER'],
222 'filter' => [
223 '=ID' => $userId,
224 ],
225 'limit' => 1,
226 ])->fetch();
227 if($userData && !empty($userData['PERSONAL_GENDER']))
228 {
229 return '_'.$userData['PERSONAL_GENDER'];
230 }
231
232 return '';
233 }
234
235 protected function getUserFieldManager(): ?\CUserTypeManager
236 {
237 global $USER_FIELD_MANAGER;
238
239 return $USER_FIELD_MANAGER;
240 }
241}
saveFiles(int $id, array $files)
Definition comment.php:113
getVisualEditorResponse(string $name, int $id=0, string $text='')
Definition comment.php:22
getUserGenderSuffix(int $userId)
Definition comment.php:218
__construct(string $filesUserFieldEntityId, string $filesUserFieldName)
Definition comment.php:16
sendMentions(int $id, int $fromUserId, string $text, string $message, array $previouslyMentionedUserIds=[])
Definition comment.php:168