1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
feed.php
См. документацию.
1<?php
2
3namespace Bitrix\Forum\Comments;
4
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Forum\Internals\Error\Error;
7
8Loc::loadMessages(__FILE__);
9
10class Feed extends BaseObject
11{
12 const ERROR_PARAMS_MESSAGE = 'params0004';
13 const ERROR_PERMISSION = 'params0005';
14
15 private function checkTopic()
16 {
17 if (empty($this->topic))
18 {
19 $this->topic = $this->createTopic();
20 }
21 return ($this->topic !== null);
22 }
23
24 public function moveEventCommentsToNewXmlId(string $newEntityXmlId): bool
25 {
26 if (is_null($this->topic))
27 {
28 return true;
29 }
30
31 $forumId = $this->getForum()['ID'];
32
33 $rows = \Bitrix\Forum\MessageTable::query()
34 ->setSelect(['ID'])
35 ->where('FORUM_ID', $forumId)
36 ->where('TOPIC_ID', $this->topic['ID']);
37
38 $comments = $rows->fetchAll();
39 if (empty($comments))
40 {
41 return true;
42 }
43
44 $newFeed = new \Bitrix\Forum\Comments\Feed($forumId, [
45 'type' => 'EV',
46 'id' => $this->getEntity()->getId(),
47 'xml_id' => $newEntityXmlId,
48 ]);
49
50 if (!$newFeed->checkTopic())
51 {
52 return false;
53 }
54
55 $newTopicId = $newFeed->getTopic()['ID'];
56 $commentsIds = array_map('intval', array_column($comments, 'ID'));
57 \Bitrix\Forum\MessageTable::updateMulti($commentsIds, [
58 'TOPIC_ID' => $newTopicId,
59 ]);
60
61 return true;
62 }
63
68 public function canAdd()
69 {
70 return $this->getEntity()->canAdd($this->getUser()->getId());
71 }
72
77 public function canRead()
78 {
79 return $this->getEntity()->canRead($this->getUser()->getId());
80 }
81
86 public function canEdit()
87 {
88 return $this->getEntity()->canEdit($this->getUser()->getId());
89 }
90
95 public function canEditComment($commentId)
96 {
97 return Comment::createFromId($this, $commentId)->canEdit();
98 }
99
104 public function canDelete()
105 {
106 return $this->getEntity()->canEdit($this->getUser()->getId());
107 }
108
113 public function canDeleteComment($commentId)
114 {
115 return Comment::createFromId($this, $commentId)->canEdit();
116 }
117
121 public function canModerate()
122 {
123 return $this->getEntity()->canModerate($this->getUser()->getId());
124 }
125
128 public function canEditOwn()
129 {
130 return $this->getEntity()->canEditOwn($this->getUser()->getId());
131 }
132
138 public function add(array $params)
139 {
140 if (!$this->canAdd())
141 {
142 $this->errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_RIGHTS1"), self::ERROR_PERMISSION));
143 }
144 else if ($this->checkTopic())
145 {
146 $comment = Comment::create($this);
147 if (empty($params["SERVICE_TYPE"]))
148 {
149 $comment->appendUserFields($params);
150 }
151 $comment->add($params);
152
153 if ($comment->hasErrors())
154 {
155 $this->errorCollection->add($comment->getErrors());
156 }
157 else
158 {
159 return $comment->getComment();
160 }
161 }
162
163 return false;
164 }
165
171 public function addComment(array $params): ?array
172 {
173 if ($this->checkTopic())
174 {
175 $comment = Comment::create($this);
176 $comment->add($params);
177 if ($comment->hasErrors())
178 {
179 $this->errorCollection->add($comment->getErrors());
180 }
181 else
182 {
183 return $comment->getComment();
184 }
185 }
186
187 return null;
188 }
189
190 public function addServiceComment(
191 array $data,
192 int $serviceType = Service\Manager::TYPE_FORUM_DEFAULT,
193 ?array $serviceData = null
194 ): ?array
195 {
196 $data['SERVICE_TYPE'] = $serviceType;
197 if ($serviceData !== null)
198 {
199 $data['SERVICE_DATA'] = json_encode($serviceData);
200 }
201 return $this->addComment($data);
202 }
203
210 public function edit($id, array $params)
211 {
212 $comment = Comment::createFromId($this, $id);
213 if (!$this->canEdit() && !$comment->canEdit())
214 $this->errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_RIGHTS2"), self::ERROR_PERMISSION));
215 else
216 {
217 if (empty($params["SERVICE_TYPE"]))
218 {
219 $comment->appendUserFields($params);
220 }
221 $comment->edit($params);
222 if ($comment->hasErrors())
223 $this->errorCollection->add($comment->getErrors());
224 else
225 return $comment->getComment();
226 }
227 return false;
228 }
229
235 public function delete($id)
236 {
237 $comment = Comment::createFromId($this, $id);
238 if (!$this->canDelete() && !$comment->canDelete())
239 $this->errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_RIGHTS3"), self::ERROR_PERMISSION));
240 else
241 {
242 $comment->delete();
243 if ($comment->hasErrors())
244 $this->errorCollection->add($comment->getErrors());
245 else
246 return $comment->getComment();
247 }
248 return false;
249 }
250
257 public function moderate($id, $show)
258 {
259 $comment = Comment::createFromId($this, $id);
260 if (!$this->canModerate())
261 $this->errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_RIGHTS4"), self::ERROR_PERMISSION));
262 else
263 {
264 $comment->moderate($show);
265 if ($comment->hasErrors())
266 $this->errorCollection->add($comment->getErrors());
267 else
268 return $comment->getComment();
269 }
270 return false;
271 }
272
278 public function send($id, array $params)
279 {
280 ob_start();
281 try{
282 global $APPLICATION;
283 $APPLICATION->IncludeComponent(
284 "bitrix:forum.comments",
285 "bitrix24",
286 [
287 "FORUM_ID" => $this->getForum()["ID"],
288 "ENTITY_TYPE" => $this->getEntity()->getType(),
289 "ENTITY_ID" => $this->getEntity()->getId(),
290 "ENTITY_XML_ID" => $this->getEntity()->getXmlId(),
291 "MID" => $id,
292 "ACTION" => "SEND",
293 "SHOW_POST_FORM" => "N"] + $params + [
294 "SHOW_RATING" => "Y",
295 "URL_TEMPLATES_PROFILE_VIEW" => "",
296 "CHECK_ACTIONS" => "N",
297 "RECIPIENT_ID" => $this->getUser()->getId()],
298 null,
299 array("HIDE_ICONS" => "Y")
300 );
301 $result = true;
302 }
303 catch (\Throwable $e)
304 {
305 $result = false;
306 }
307 ob_get_clean();
308 return $result;
309 }
310
317 public function setPermission($permission)
318 {
319 $this->getEntity()->setPermission($this->getUser()->getId(), $permission);
320 return $this;
321 }
322
327 public function setEditOwn($allow)
328 {
329 $this->getEntity()->setEditOwn($allow);
330 return $this;
331 }
332
337 public function getPermission()
338 {
339 return $this->getEntity()->getPermission($this->getUser()->getId());
340 }
341}
global $APPLICATION
Определения include.php:80
static createFromId(Feed $feed, $id)
Определения comment.php:581
static create(Feed $feed)
Определения comment.php:594
setEditOwn($allow)
Определения feed.php:327
canDelete()
Определения feed.php:104
edit($id, array $params)
Определения feed.php:210
moderate($id, $show)
Определения feed.php:257
canDeleteComment($commentId)
Определения feed.php:113
getPermission()
Определения feed.php:337
moveEventCommentsToNewXmlId(string $newEntityXmlId)
Определения feed.php:24
canEditComment($commentId)
Определения feed.php:95
send($id, array $params)
Определения feed.php:278
canAdd()
Определения feed.php:68
const ERROR_PARAMS_MESSAGE
Определения feed.php:12
canRead()
Определения feed.php:77
setPermission($permission)
Определения feed.php:317
const ERROR_PERMISSION
Определения feed.php:13
add(array $params)
Определения feed.php:138
canModerate()
Определения feed.php:121
canEditOwn()
Определения feed.php:128
canEdit()
Определения feed.php:86
addServiceComment(array $data, int $serviceType=Service\Manager::TYPE_FORUM_DEFAULT, ?array $serviceData=null)
Определения feed.php:190
addComment(array $params)
Определения feed.php:171
Определения error.php:15
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$comment
Определения template.php:15
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$rows
Определения options.php:264