Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
comment.php
1<?php
3
8
10{
11 const COMMENT_COPY_ERROR = "COMMENT_COPY_ERROR";
12
13 protected $ufEntityObject = "FORUM_MESSAGE";
14 protected $ufDiskFileField = "UF_FORUM_MESSAGE_DOC";
15
21 public function add(Container $container, array $fields)
22 {
23 $messageId = \CForumMessage::add($fields);
24
25 if (!$messageId)
26 {
27 $this->result->addError(new Error("Error creating a new comment", self::COMMENT_COPY_ERROR));
28 }
29
30 return $messageId;
31 }
32
33 public function update($commentId, array $fields)
34 {
35 return \CForumMessage::update($commentId, $fields);
36 }
37
45 public function getFields(Container $container, $entityId)
46 {
47 $message = \CForumMessage::getByIDEx($entityId);
48 return ($message ? $message : []);
49 }
50
58 public function prepareFieldsToCopy(Container $container, array $fields)
59 {
60 unset($fields["ID"]);
61
62 if ($container->getParentId())
63 {
64 $fields["TOPIC_ID"] = $container->getParentId();
65 }
66
67 $dictionary = $container->getDictionary();
68
69 if (!empty($dictionary["XML_ID"]))
70 {
71 $fields["XML_ID"] = $dictionary["XML_ID"];
72 }
73
74 return $fields;
75 }
76
85 public function copyChildren(Container $container, $entityId, $copiedEntityId)
86 {
87 $this->copyUfFields($entityId, $copiedEntityId, $this->ufEntityObject);
88
89 return new Result();
90 }
91
99 public function updateAttachedIdsInText(int $id, array $attachedIds, callable $auxiliaryCallback): void
100 {
101 list($field, $text) = $this->getText($id);
102
103 $detailText = call_user_func_array($auxiliaryCallback, [
104 $text,
105 $this->ufEntityObject,
106 $id,
107 $this->ufDiskFileField,
108 $attachedIds
109 ]);
110
111 $this->update($id, [$field => $detailText]);
112 }
113
114 protected function getText($commentId)
115 {
116 $queryObject = \CForumMessage::getlist([], [
117 "ID" => $commentId], false, 0, ["SELECT" => ["POST_MESSAGE"]]);
118
119 if ($fields = $queryObject->fetch())
120 {
121 return ["POST_MESSAGE", $fields["POST_MESSAGE"]];
122 }
123 else
124 {
125 return ["POST_MESSAGE", ""];
126 }
127 }
128}
getFields(Container $container, $entityId)
Definition comment.php:45
updateAttachedIdsInText(int $id, array $attachedIds, callable $auxiliaryCallback)
Definition comment.php:99
add(Container $container, array $fields)
Definition comment.php:21
update($commentId, array $fields)
Definition comment.php:33
copyChildren(Container $container, $entityId, $copiedEntityId)
Definition comment.php:85
prepareFieldsToCopy(Container $container, array $fields)
Definition comment.php:58
copyUfFields(int $entityId, int $copiedEntityId, string $ufObject)