Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
feed.php
1
<?php
2
3
namespace
Bitrix\Forum\Comments
;
4
5
use \Bitrix\Main\Localization\Loc;
6
use \Bitrix\Forum\Internals\Error\Error;
7
8
Loc::loadMessages
(__FILE__);
9
10
class
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
}
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
$this->errorCollection->addOne(
new
Error
(
Loc::getMessage
(
"FORUM_CM_RIGHTS1"
), self::ERROR_PERMISSION));
142
else
if
($this->checkTopic())
143
{
144
$comment =
Comment::create
($this);
145
$comment->add($params);
146
if
($comment->hasErrors())
147
$this->errorCollection->add($comment->getErrors());
148
else
149
return
$comment->getComment();
150
}
151
return
false
;
152
}
153
160
public
function
edit
($id, array $params)
161
{
162
$comment =
Comment::createFromId
($this, $id);
163
if
(!$this->
canEdit
() && !$comment->canEdit())
164
$this->errorCollection->addOne(
new
Error
(
Loc::getMessage
(
"FORUM_CM_RIGHTS2"
), self::ERROR_PERMISSION));
165
else
166
{
167
$comment->edit($params);
168
if
($comment->hasErrors())
169
$this->errorCollection->add($comment->getErrors());
170
else
171
return
$comment->getComment();
172
}
173
return
false
;
174
}
175
181
public
function
delete
($id)
182
{
183
$comment =
Comment::createFromId
($this, $id);
184
if
(!$this->
canDelete
() && !$comment->canDelete())
185
$this->errorCollection->addOne(
new
Error
(
Loc::getMessage
(
"FORUM_CM_RIGHTS3"
), self::ERROR_PERMISSION));
186
else
187
{
188
$comment->delete();
189
if
($comment->hasErrors())
190
$this->errorCollection->add($comment->getErrors());
191
else
192
return
$comment->getComment();
193
}
194
return
false
;
195
}
196
203
public
function
moderate
($id, $show)
204
{
205
$comment =
Comment::createFromId
($this, $id);
206
if
(!$this->
canModerate
())
207
$this->errorCollection->addOne(
new
Error
(
Loc::getMessage
(
"FORUM_CM_RIGHTS4"
), self::ERROR_PERMISSION));
208
else
209
{
210
$comment->moderate($show);
211
if
($comment->hasErrors())
212
$this->errorCollection->add($comment->getErrors());
213
else
214
return
$comment->getComment();
215
}
216
return
false
;
217
}
224
public
function
send
($id, array $params)
225
{
226
ob_start();
227
try
{
228
global $APPLICATION;
229
$APPLICATION->IncludeComponent(
230
"bitrix:forum.comments"
,
231
"bitrix24"
,
232
[
233
"FORUM_ID"
=> $this->
getForum
()[
"ID"
],
234
"ENTITY_TYPE"
=> $this->
getEntity
()->getType(),
235
"ENTITY_ID"
=> $this->
getEntity
()->getId(),
236
"ENTITY_XML_ID"
=> $this->
getEntity
()->getXmlId(),
237
"MID"
=> $id,
238
"ACTION"
=>
"SEND"
,
239
"SHOW_POST_FORM"
=>
"N"
] + $params + [
240
"SHOW_RATING"
=>
"Y"
,
241
"URL_TEMPLATES_PROFILE_VIEW"
=>
""
,
242
"CHECK_ACTIONS"
=>
"N"
,
243
"RECIPIENT_ID"
=> $this->
getUser
()->getId()],
244
null
,
245
array(
"HIDE_ICONS"
=>
"Y"
)
246
);
247
$result =
true
;
248
}
249
catch
(\Throwable $e)
250
{
251
$result =
false
;
252
}
253
ob_get_clean();
254
return
$result;
255
}
263
public
function
setPermission
($permission)
264
{
265
$this->
getEntity
()->setPermission($this->
getUser
()->getId(), $permission);
266
return
$this;
267
}
268
273
public
function
setEditOwn
($allow)
274
{
275
$this->
getEntity
()->setEditOwn($allow);
276
return
$this;
277
}
278
283
public
function
getPermission
()
284
{
285
return
$this->
getEntity
()->getPermission($this->
getUser
()->getId());
286
}
287
}
Bitrix\Forum\Comments\BaseObject
Definition
baseobject.php:18
Bitrix\Forum\Comments\BaseObject\getForum
getForum()
Definition
baseobject.php:222
Bitrix\Forum\Comments\BaseObject\getEntity
getEntity()
Definition
baseobject.php:66
Bitrix\Forum\Comments\BaseObject\getUser
getUser()
Definition
baseobject.php:255
Bitrix\Forum\Comments\Comment\createFromId
static createFromId(Feed $feed, $id)
Definition
comment.php:577
Bitrix\Forum\Comments\Comment\create
static create(Feed $feed)
Definition
comment.php:590
Bitrix\Forum\Comments\Feed
Definition
feed.php:11
Bitrix\Forum\Comments\Feed\setEditOwn
setEditOwn($allow)
Definition
feed.php:273
Bitrix\Forum\Comments\Feed\canDelete
canDelete()
Definition
feed.php:104
Bitrix\Forum\Comments\Feed\edit
edit($id, array $params)
Definition
feed.php:160
Bitrix\Forum\Comments\Feed\moderate
moderate($id, $show)
Definition
feed.php:203
Bitrix\Forum\Comments\Feed\canDeleteComment
canDeleteComment($commentId)
Definition
feed.php:113
Bitrix\Forum\Comments\Feed\getPermission
getPermission()
Definition
feed.php:283
Bitrix\Forum\Comments\Feed\moveEventCommentsToNewXmlId
moveEventCommentsToNewXmlId(string $newEntityXmlId)
Definition
feed.php:24
Bitrix\Forum\Comments\Feed\canEditComment
canEditComment($commentId)
Definition
feed.php:95
Bitrix\Forum\Comments\Feed\send
send($id, array $params)
Definition
feed.php:224
Bitrix\Forum\Comments\Feed\canAdd
canAdd()
Definition
feed.php:68
Bitrix\Forum\Comments\Feed\ERROR_PARAMS_MESSAGE
const ERROR_PARAMS_MESSAGE
Definition
feed.php:12
Bitrix\Forum\Comments\Feed\canRead
canRead()
Definition
feed.php:77
Bitrix\Forum\Comments\Feed\setPermission
setPermission($permission)
Definition
feed.php:263
Bitrix\Forum\Comments\Feed\ERROR_PERMISSION
const ERROR_PERMISSION
Definition
feed.php:13
Bitrix\Forum\Comments\Feed\add
add(array $params)
Definition
feed.php:138
Bitrix\Forum\Comments\Feed\canModerate
canModerate()
Definition
feed.php:121
Bitrix\Forum\Comments\Feed\canEditOwn
canEditOwn()
Definition
feed.php:128
Bitrix\Forum\Comments\Feed\canEdit
canEdit()
Definition
feed.php:86
Bitrix\Forum\Internals\Error\Error
Definition
error.php:6
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Forum\Comments
Definition
baseobject.php:3
modules
forum
lib
comments
feed.php
Создано системой
1.10.0