Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
forumtopic.php
1<?php
2
4
10
11final class ForumTopic extends Provider
12{
13 public const PROVIDER_ID = 'FORUM_TOPIC';
14 public const CONTENT_TYPE_ID = 'FORUM_TOPIC';
15
16 public static function getId(): string
17 {
18 return static::PROVIDER_ID;
19 }
20
21 public function getEventId(): array
22 {
23 return [ 'forum' ];
24 }
25
26 public function getType(): string
27 {
29 }
30
31 final public function setEntityId($topicId): void // patch TOPIC->POST
32 {
33 $topicId = (int)$topicId;
34 $messageId = 0;
35
36 if (
37 $topicId > 0
38 && Loader::includeModule('forum')
39 )
40 {
41 $res = MessageTable::getList(array(
42 'order' => array('ID' => 'ASC'),
43 'filter' => array(
44 'TOPIC_ID' => $topicId,
45 ),
46 'select' => array('ID')
47 ));
48 if ($message = $res->fetch())
49 {
50 $messageId = $message['ID'];
51 }
52 }
53
54 $this->entityId = $messageId;
55 }
56
57 public function getCommentProvider(): Provider
58 {
59 return new ForumPost();
60 }
61
62 public function initSourceFields()
63 {
64 $messageId = $this->entityId;
65
66 if (
67 $messageId > 0
68 && Loader::includeModule('forum')
69 )
70 {
71 $res = MessageTable::getList(array(
72 'filter' => array(
73 '=ID' => $messageId
74 ),
75 'select' => array('ID', 'TOPIC_ID', 'POST_MESSAGE')
76 ));
77 if ($message = $res->fetch())
78 {
79 $logId = false;
80
81 $res = LogTable::getList(array(
82 'filter' => array(
83 'SOURCE_ID' => $messageId,
84 '@EVENT_ID' => $this->getEventId(),
85 ),
86 'select' => array('ID')
87 ));
88 if ($logEntryFields = $res->fetch())
89 {
90 $logId = (int)$logEntryFields['ID'];
91 }
92
93 if ($logId)
94 {
95 $res = \CSocNetLog::getList(
96 array(),
97 array(
98 '=ID' => $logId
99 ),
100 false,
101 false,
102 array('ID', 'EVENT_ID', 'URL'),
103 array(
104 "CHECK_RIGHTS" => "Y",
105 "USE_FOLLOW" => "N",
106 "USE_SUBSCRIBE" => "N"
107 )
108 );
109 if ($logFields = $res->fetch())
110 {
111 $this->setLogId($logFields['ID']);
112 $this->setSourceFields(array_merge($message, array(
113 'LOG_EVENT_ID' => $logFields['EVENT_ID'],
114 'URL' => $logFields['URL']
115 )));
116 $this->setSourceDescription($message['POST_MESSAGE']);
117
118 $title = '';
119 $res = TopicTable::getList(array(
120 'filter' => array(
121 '=ID' => $message['TOPIC_ID']
122 ),
123 'select' => array('TITLE')
124 ));
125 if ($topic = $res->fetch())
126 {
127 $title = htmlspecialcharsback($topic['TITLE']);
128 $title = \Bitrix\Socialnetwork\Helper\Mention::clear($title);
129
130 $CBXSanitizer = new \CBXSanitizer;
131 $CBXSanitizer->delAllTags();
132 $title = preg_replace(array("/\n+/is".BX_UTF_PCRE_MODIFIER, "/\s+/is".BX_UTF_PCRE_MODIFIER), " ", $CBXSanitizer->sanitizeHtml($title));
133
134 }
135 $this->setSourceTitle(truncateText($title, 100));
136 $this->setSourceAttachedDiskObjects($this->getAttachedDiskObjects($this->cloneDiskObjects));
137 $this->setSourceDiskObjects($this->getDiskObjects($messageId, $this->cloneDiskObjects));
138 }
139 }
140 }
141 }
142 }
143
144 protected function getAttachedDiskObjects($clone = false)
145 {
146 return $this->getEntityAttachedDiskObjects([
147 'userFieldEntity' => 'FORUM_MESSAGE',
148 'userFieldCode' => 'UF_FORUM_MESSAGE_DOC',
149 'clone' => $clone,
150 ]);
151 }
152
153 public static function canRead($params): bool
154 {
155 return true;
156 }
157
158 protected function getPermissions(array $post): string
159 {
161 }
162
163 public function getLiveFeedUrl()
164 {
165 $pathToMessage = '';
166
167 if (
168 ($message = $this->getSourceFields())
169 && !empty($message)
170 )
171 {
172 $pathToMessage = str_replace(
173 "#GROUPS_PATH#",
174 Option::get('socialnetwork', 'workgroups_page', '/workgroups/', $this->getSiteId()),
175 $message['URL']
176 );
177 }
178
179 return $pathToMessage;
180 }
181
182 public function getAdditionalData($params = []): array
183 {
184 $result = array();
185
186 if (
187 !$this->checkAdditionalDataParams($params)
188 || !Loader::includeModule('forum')
189 )
190 {
191 return $result;
192 }
193
194 $res = MessageTable::getList(array(
195 'filter' => array(
196 '@ID' => $params['id']
197 ),
198 'select' => array('ID', 'USE_SMILES')
199 ));
200
201 while ($message = $res->fetch())
202 {
203 $data = $message;
204 unset($data['ID']);
205 $result[$message['ID']] = $data;
206 }
207
208 return $result;
209 }
210}
static getList(array $parameters=array())
Definition forumpost.php:22
setSourceAttachedDiskObjects(array $diskAttachedObjects)
Definition provider.php:739
getEntityAttachedDiskObjects(array $params=[])
getDiskObjects($entityId, $clone=false)
Definition provider.php:822