Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
forummessageattachmenthandler.php
1<?php
3
5
6if (Loader::includeModule('replica'))
7{
8 class ForumMessageAttachmentHandler extends \Bitrix\Replica\Client\AttachmentHandler
9 {
10 protected $moduleId = "forum";
11 protected $relation = "b_forum_message.ATTACH_ID";
12
13 protected $executeEventEntity = "ForumMessage";
14 protected $parentRelation = "b_forum_message.ID";
15 protected $diskConnectorString = "forum_message";
16
17 protected $dataFields = array("POST_MESSAGE", "POST_MESSAGE_HTML");
18
27 public static function updateUserField($messageId, $diskAttachId)
28 {
29 global $USER_FIELD_MANAGER;
30 $ufValue = $USER_FIELD_MANAGER->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageId);
31 if (!$ufValue)
32 {
33 $ufValue = array($diskAttachId);
34 }
35 elseif (is_array($ufValue))
36 {
37 $ufValue[] = $diskAttachId;
38 }
39 else
40 {
41 $ufValue = $diskAttachId;
42 }
43 $USER_FIELD_MANAGER->Update("FORUM_MESSAGE", $messageId, array("UF_FORUM_MESSAGE_DOC" => $ufValue));
44 }
45
53 public static function getUserField($messageId)
54 {
55 $result = array();
56
57 $messageList = \CForumMessage::getList(
58 array(),
59 array(
60 "ID" => $messageId,
61 ),
62 false, 0,
63 array("SELECT" => array("UF_FORUM_MESSAGE_DOC"))
64 );
65 $messageInfo = $messageList->fetch();
66
67 if (
68 $messageInfo
69 && $messageInfo["UF_FORUM_MESSAGE_DOC"]
70 && $messageInfo["UF_FORUM_MESSAGE_DOC"]["VALUE"]
71 && \Bitrix\Main\Loader::includeModule('disk')
72 )
73 {
74 foreach ($messageInfo["UF_FORUM_MESSAGE_DOC"]["VALUE"] as $attachId)
75 {
76 $attachedObject = \Bitrix\Disk\AttachedObject::getById($attachId, array('OBJECT'));
77 if ($attachedObject && $attachedObject->getFile())
78 {
79 $result[$attachId] = $attachedObject;
80 }
81 }
82 }
83
84 return $result;
85 }
86
96 public function onExecuteDescriptionFix(\Bitrix\Main\Event $event)
97 {
98 $parameters = $event->getParameters();
99 $messId = $parameters[0];
100 $fields = $parameters[1];
101 $connection = \Bitrix\Main\Application::getConnection();
102 $sqlHelper = $connection->getSqlHelper();
103
104 if ($this->replaceGuidsWithFiles($fields))
105 {
106 $update = $sqlHelper->prepareUpdate("b_forum_message", $fields);
107 if ($update[0] <> '')
108 {
109 $sql = "UPDATE ".$sqlHelper->quote("b_forum_message")." SET ".$update[0]." WHERE ID = ".$messId;
110 $connection->query($sql);
111
112 if (\Bitrix\Main\Loader::includeModule('socialnetwork'))
113 {
114 $dbLogComment = \CSocNetLogComments::GetList(
115 array("ID" => "DESC"),
116 array(
117 "EVENT_ID" => 'tasks_comment',
118 "SOURCE_ID" => $messId,
119 ),
120 false,
121 false,
122 array("ID", "LOG_ID")
123 );
124 $arLogComment = $dbLogComment->fetch();
125 if ($arLogComment)
126 {
127 $parser = new \CTextParser();
128 $parser->allow = array(
129 "HTML" => 'Y',
130 "ANCHOR" => 'Y',
131 "BIU" => 'Y',
132 "IMG" => "Y",
133 "VIDEO" => "Y",
134 "LIST" => 'N',
135 "QUOTE" => 'Y',
136 "CODE" => 'Y',
137 "FONT" => 'Y',
138 "SMILES" => "N",
139 "UPLOAD" => 'N',
140 "NL2BR" => 'N',
141 "TABLE" => "Y",
142 );
143 $arFieldsForSocnet = array(
144 "LOG_ID" => intval($arLogComment["LOG_ID"]),
145 "MESSAGE" => $fields["POST_MESSAGE"],
146 "TEXT_MESSAGE" => $parser->convert4mail($fields["POST_MESSAGE"]),
147 );
148
149 $ufFileID = array();
150 $dbAddedMessageFiles = \CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messId));
151 while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch())
152 {
153 $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
154 }
155
156 if (count($ufFileID) > 0)
157 {
158 $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID;
159 }
160
161 $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", intval($messId), LANGUAGE_ID);
162 if ($ufDocID)
163 {
164 $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
165 }
166
167 \CSocNetLogComments::Update($arLogComment["ID"], $arFieldsForSocnet);
168 }
169 }
170 }
171 }
172 }
173 }
174}
$GLOBALS['____1979065141']
Definition mutator.php:1