Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
taskinfo.php
1<?php
2
4
8use Bitrix\Tasks\Comments\Task\CommentPoster;
9
10final class TaskInfo extends Base
11{
12 public const TYPE = 'TASKINFO';
13 public const POST_TEXT = 'commentAuxTaskInfo';
14
15 protected static $forumMessageTableClass = MessageTable::class;
16
17 public function getParamsFromFields($fields = []): array
18 {
19 static $cacheData = [];
20
21 $params = [];
22
23 if (!empty($fields['SHARE_DEST'])) // old
24 {
25 $paramsList = unserialize(htmlspecialcharsback($fields['SHARE_DEST']), [ 'allowed_classes' => false ]);
26 if (!empty($paramsList))
27 {
28 $params = $paramsList;
29 }
30 else
31 {
32 $paramsList = explode('|', $fields['SHARE_DEST']);
33 if (!empty($paramsList))
34 {
35 foreach ($paramsList as $pair)
36 {
37 [ $key, $value ] = explode('=', $pair);
38 if (isset($key, $value))
39 {
40 $params[$key] = $value;
41 }
42 }
43 }
44 }
45 }
46 elseif (
47 !empty($fields['EVENT_ID'])
48 && in_array($fields['EVENT_ID'], [ 'tasks_comment', 'crm_activity_add_comment' ])
49 && !empty($fields['SOURCE_ID'])
50 && (int)$fields['SOURCE_ID'] > 0
51 && Loader::includeModule('forum')
52 ) // new
53 {
54 $messageId = (int)$fields['SOURCE_ID'];
55
56 if (isset($cacheData[$messageId]))
57 {
58 $params = $cacheData[$messageId];
59 }
60 else
61 {
62 $forumPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\ForumPost();
63 $commentData = $forumPostLivefeedProvider->getAuxCommentCachedData($messageId);
64
65 if (
66 !empty($commentData)
67 && isset($commentData['SERVICE_TYPE'])
68 && $commentData['SERVICE_TYPE'] === \Bitrix\Forum\Comments\Service\Manager::TYPE_TASK_INFO
69 && (
70 !empty($commentData['SERVICE_DATA'])
71 || !empty($commentData['POST_MESSAGE'])
72 )
73 )
74 {
75 try
76 {
77 $messageParams = Json::decode(!empty($commentData['SERVICE_DATA']) ? $commentData['SERVICE_DATA'] : $commentData['POST_MESSAGE']);
78 if (!is_array($messageParams))
79 {
80 $messageParams = [];
81 }
82 }
83 catch(\Bitrix\Main\ArgumentException $e)
84 {
85 $messageParams = [];
86 }
87
88 $cacheData[$messageId] = $params = $messageParams;
89 }
90 else
91 {
92 $res = self::$forumMessageTableClass::getList([
93 'filter' => [
94 '=ID' => $messageId
95 ],
96 'select' => ['TOPIC_ID']
97 ]);
98 if (
99 ($forumMessageFields = $res->fetch())
100 && !empty($forumMessageFields['TOPIC_ID'])
101 )
102 {
103 $res = self::$forumMessageTableClass::getList([
104 'filter' => [
105 '=TOPIC_ID' => (int)$forumMessageFields['TOPIC_ID']
106 ],
107 'select' => [ 'ID', 'SERVICE_DATA', 'POST_MESSAGE' ]
108 ]);
109 while (
110 ($forumMessageFields = $res->fetch())
111 && (
112 !empty($forumMessageFields['SERVICE_DATA'])
113 || !empty($forumMessageFields['POST_MESSAGE'])
114 )
115 )
116 {
117 try
118 {
119 $messageParams = Json::decode(!empty($forumMessageFields['SERVICE_DATA']) ? $forumMessageFields['SERVICE_DATA'] : $forumMessageFields['POST_MESSAGE']);
120 if (!is_array($messageParams))
121 {
122 $messageParams = [];
123 }
124 }
125 catch(\Bitrix\Main\ArgumentException $e)
126 {
127 $messageParams = [];
128 }
129
130 $cacheData[$forumMessageFields['ID']] = $messageParams;
131 }
132
133 $params = ($cacheData[$messageId] ?? []);
134 }
135 }
136 }
137 }
138
139 return $params;
140 }
141
142 public function getText(): string
143 {
144 $result = '';
146
147 if (
148 isset($params['auxData'], $params['text'])
149 && $params['text'] <> ''
150 )
151 {
152 $result = $params['text'];
153 }
154 elseif(
155 is_array($params)
156 && !empty($params)
157 && Loader::includeModule('tasks')
158 )
159 {
160 $result = htmlspecialcharsEx(CommentPoster::getCommentText($params, $this->getOptions()));
161 $parser = new \CTextParser();
162
163 $parser->allow = [
164 'HTML' => 'N',
165 'ANCHOR' => 'Y',
166 'USER' => 'Y',
167 ];
168
169 $result = $parser->convertText($result);
170 }
171
172 return $result;
173 }
174
175 public function canDelete(): bool
176 {
177 return false;
178 }
179
180 public function checkRecalcNeeded($fields, $params): bool
181 {
182 return true;
183 }
184
185 protected function getRatingNotificationEntityMessage(): string
186 {
187 $CBXSanitizer = new \CBXSanitizer;
188 $CBXSanitizer->delAllTags();
189 return strip_tags(str_replace('<br>', ' ', $CBXSanitizer->sanitizeHtml($this->getText())));
190 }
191
192 protected function getRatingNotificationNotigyTag(array $ratingVoteParams = [], array $fields = []): string
193 {
194 return 'RATING|' . ($ratingVoteParams['VALUE'] >= 0 ? '' : 'DL|') . 'FORUM_POST|' . $fields['SOURCE_ID'];
195 }
196}
getRatingNotificationNotigyTag(array $ratingVoteParams=[], array $fields=[])
Definition taskinfo.php:192