Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logcomment.php
1<?php
2
4
7
8final class LogComment extends Provider
9{
10 public const PROVIDER_ID = 'SONET_COMMENT';
11 public const CONTENT_TYPE_ID = 'LOG_COMMENT';
12
13 protected $logEventId = null;
14 protected $logEntityType = null;
15 protected $logEntityId = null;
16
17 public static function getId(): string
18 {
19 return static::PROVIDER_ID;
20 }
21
22 public function getEventId(): array
23 {
24 return [ 'data_comment', 'photoalbum_comment', 'intranet_new_user_comment', 'bitrix24_new_user_comment' ];
25 }
26
27 public function getType(): string
28 {
30 }
31
32 public function initSourceFields()
33 {
34 $commentId = $this->entityId;
35
36 if ($commentId > 0)
37 {
38 $logId = false;
39
41 'filter' => [
42 '=ID' => $commentId,
43 '@EVENT_ID' => $this->getEventId(),
44 ],
45 'select' => [ 'ID', 'LOG_ID', 'MESSAGE', 'SHARE_DEST', 'EVENT_ID' ]
46 ]);
47 if ($logComentFields = $res->fetch())
48 {
49 $logId = (int)$logComentFields['LOG_ID'];
50 }
51
52 if ($logId)
53 {
54 $res = \CSocNetLog::getList(
55 array(),
56 array(
57 '=ID' => $logId
58 ),
59 false,
60 false,
61 array('ID', 'EVENT_ID'),
62 array(
63 "CHECK_RIGHTS" => "Y",
64 "USE_FOLLOW" => "N",
65 "USE_SUBSCRIBE" => "N"
66 )
67 );
68 if ($logFields = $res->fetch())
69 {
70 $this->setLogId($logFields['ID']);
71 $this->setSourceFields(array_merge($logComentFields, array('LOG_EVENT_ID' => $logFields['EVENT_ID'])));
72 $this->setSourceDescription($logComentFields['MESSAGE']);
73
74 $title = htmlspecialcharsback($logComentFields['MESSAGE']);
75 $title = \Bitrix\Socialnetwork\Helper\Mention::clear($title);
76
77 $CBXSanitizer = new \CBXSanitizer;
78 $CBXSanitizer->delAllTags();
79 $title = preg_replace(array("/\n+/is".BX_UTF_PCRE_MODIFIER, "/\s+/is".BX_UTF_PCRE_MODIFIER), " ", $CBXSanitizer->sanitizeHtml($title));
80 $this->setSourceTitle(truncateText($title, 100));
81 $this->setSourceAttachedDiskObjects($this->getAttachedDiskObjects($this->cloneDiskObjects));
82 $this->setSourceDiskObjects($this->getDiskObjects($commentId, $this->cloneDiskObjects));
83 $this->setSourceOriginalText($logComentFields['MESSAGE']);
84 $this->setSourceAuxData($logComentFields);
85 }
86 }
87 }
88 }
89
90 protected function getAttachedDiskObjects($clone = false)
91 {
92 return $this->getEntityAttachedDiskObjects([
93 'userFieldEntity' => 'SONET_COMMENT',
94 'userFieldCode' => 'UF_SONET_COM_DOC',
95 'clone' => $clone,
96 ]);
97 }
98
99 public function getLiveFeedUrl(): string
100 {
101 $pathToLogEntry = '';
102
103 $logId = $this->getLogId();
104 if ($logId)
105 {
106 $pathToLogEntry = Option::get('socialnetwork', 'log_entry_page', '', $this->getSiteId());
107 if (!empty($pathToLogEntry))
108 {
109 $pathToLogEntry = \CComponentEngine::makePathFromTemplate($pathToLogEntry, array("log_id" => $logId));
110 $pathToLogEntry .= (mb_strpos($pathToLogEntry, '?') === false ? '?' : '&').'commentId='.$this->getEntityId().'#com'.$this->getEntityId();
111 }
112 }
113 return $pathToLogEntry;
114 }
115
116 public static function canRead($params): bool
117 {
118 return true;
119 }
120
121 protected function getPermissions(array $post): string
122 {
124 }
125
126 public function getSuffix(): string
127 {
128 $logEventId = $this->getLogEventId();
129
130 if (!empty($logEventId))
131 {
132 $providerIntranetNewUser = new IntranetNewUser();
133 if (in_array($logEventId, $providerIntranetNewUser->getEventId(), true))
134 {
135 return 'INTRANET_NEW_USER';
136 }
137
138 $providerBitrix24NewUser = new Bitrix24NewUser();
139 if (in_array($logEventId, $providerBitrix24NewUser->getEventId(), true))
140 {
141 return 'BITRIX24_NEW_USER';
142 }
143 }
144
145 return '2';
146 }
147
148 public function add($params = array())
149 {
150 global $USER;
151
152 static $parser = null;
153
154 $authorId = (
155 isset($params['AUTHOR_ID'])
156 && (int)$params['AUTHOR_ID'] > 0
157 ? (int)$params['AUTHOR_ID']
158 : $USER->getId()
159 );
160
161 $message = (string)(
162 isset($params['MESSAGE'])
163 && (string)$params['MESSAGE'] !== ''
164 ? $params['MESSAGE']
165 : ''
166 );
167
168 if ($message === '')
169 {
170 return false;
171 }
172
173 $module = ($params['MODULE'] ?? 'tasks');
174 $logId = $this->getLogId();
175
176 if (!$logId)
177 {
178 return false;
179 }
180
181 $this->setLogId($logId);
182
183 if ($parser === null)
184 {
185 $parser = new \CTextParser();
186 }
187
188 $commentEventId = false;
189
190 $providerIntranetNewUser = new IntranetNewUser();
191 if (in_array($this->getLogEventId(), $providerIntranetNewUser->getEventId(), true))
192 {
193 $commentEventId = 'intranet_new_user_comment';
194 }
195
196 if (!$commentEventId)
197 {
198 $providerBitrix24NewUser = new Bitrix24NewUser();
199 if (in_array($this->getLogEventId(), $providerBitrix24NewUser->getEventId(), true))
200 {
201 $commentEventId = 'bitrix24_new_user_comment';
202 }
203 }
204
205 if (!$commentEventId)
206 {
207 $providerPhotogalleryAlbum = new PhotogalleryAlbum();
208 if (in_array($this->getLogEventId(), $providerPhotogalleryAlbum->getEventId(), true))
209 {
210 $commentEventId = 'photoalbum_comment';
211 }
212 }
213
214 if (!$commentEventId)
215 {
216 $commentEventId = 'data_comment';
217 }
218
219 $sonetCommentFields = array(
220 "ENTITY_TYPE" => $this->getLogEntityType(),
221 "ENTITY_ID" => $this->getLogEntityId(),
222 "EVENT_ID" => $commentEventId,
223 "MESSAGE" => $message,
224 "TEXT_MESSAGE" => $parser->convert4mail($message),
225 "MODULE_ID" => $module,
226 "LOG_ID" => $logId,
227 "RATING_TYPE_ID" => "LOG_COMMENT",
228 "USER_ID" => $authorId,
229 "=LOG_DATE" => \CDatabase::currentTimeFunction(),
230 );
231
232 if (!empty($params['SHARE_DEST']))
233 {
234 $sonetCommentFields['SHARE_DEST'] = $params['SHARE_DEST'];
235 }
236
237 if ($sonetCommentId = \CSocNetLogComments::add($sonetCommentFields, false, false))
238 {
239 \CSocNetLogComments::update($sonetCommentId, array(
240 "RATING_ENTITY_ID" => $sonetCommentId
241 ));
242 }
243
244 return [
245 'sonetCommentId' => $sonetCommentId,
246 'sourceCommentId' => $sonetCommentId
247 ];
248 }
249
250}
static getList(array $parameters=array())
setSourceAttachedDiskObjects(array $diskAttachedObjects)
Definition provider.php:739
getEntityAttachedDiskObjects(array $params=[])
getDiskObjects($entityId, $clone=false)
Definition provider.php:822