22 private static $topics = array();
23 private static $users = array();
41 $userId = ($USER instanceof \CUser ? $USER->getId() : 0);
45 $userId = intval($userId);
56 if (($id = array_change_key_case($id, CASE_LOWER)) && $id[
"id"] > 0)
68 if ($this->entity instanceof
Entity)
71 if (!is_array($this->entity))
76 if (is_null($protoEntity))
79 if (!array_key_exists(
'xml_id', $id) || empty($id[
"xml_id"]))
80 $id[
'xml_id'] = mb_strtoupper($id[
"type"].
"_".$id[
'id']);
82 elseif (!array_key_exists(
'xml_id', $id) || empty($id[
"xml_id"]))
83 $id[
'xml_id'] = $protoEntity[
"xmlIdPrefix"].
"_".$id[
'id'];
84 if (!Loader::includeModule($protoEntity[
"moduleId"]))
85 throw new SystemException(
"Module {$protoEntity["moduleId
"]} is not included.");
87 $this->entity =
new $protoEntity[
"className"]($id, $this->
getForum());
88 if (! $this->entity instanceof
Entity)
89 throw new SystemException(
"Entity Class does not descended from \\Bitrix\\Forum\\Comments\\Entity.");
96 if (!array_key_exists($this->
getEntity()->getXmlId(), self::$topics))
98 $dbRes = \CForumTopic::getList(
null, array(
99 "FORUM_ID" => $this->forum[
"ID"],
100 "XML_ID" => $this->
getEntity()->getXmlId()
102 self::$topics[$this->
getEntity()->getXmlId()] = (($res = $dbRes->fetch()) && $res ? $res :
null);
104 $this->topic = self::$topics[$this->
getEntity()->getXmlId()];
108 protected function createTopic()
111 'TITLE' => $this->
getEntity()->getXmlId(),
113 'MESSAGE' => $this->
getEntity()->getXmlId(),
117 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
118 $post = array_merge($request->getQueryList()->toArray(), $request->getPostList()->toArray());
123 if (!isset(
$topic[
"AUTHOR_NAME"]) || strlen(
$topic[
"AUTHOR_NAME"]) <= 0)
127 "FORUM_ID" => $this->forum[
"ID"],
128 'TITLE' =>
$topic[
"TITLE"],
130 'MESSAGE' =>
$topic[
"MESSAGE"],
131 "USER_START_ID" =>
$topic[
"AUTHOR_ID"],
132 "USER_START_NAME" =>
$topic[
"AUTHOR_NAME"],
133 "LAST_POSTER_NAME" =>
$topic[
"AUTHOR_NAME"],
134 "XML_ID" => $this->
getEntity()->getXmlId(),
137 if (($tid = \CForumTopic::add(
$topic)) > 0)
139 if ($this->forum[
"ALLOW_HTML"] !=
"Y")
143 "POST_MESSAGE" =>
$topic[
'MESSAGE'],
144 "AUTHOR_ID" =>
$topic[
"AUTHOR_ID"],
145 "AUTHOR_NAME" =>
$topic[
"AUTHOR_NAME"],
146 "FORUM_ID" =>
$topic[
"FORUM_ID"],
148 "APPROVED" =>
$topic[
"APPROVED"],
150 "XML_ID" => $this->
getEntity()->getXmlId(),
151 "PARAM1" => $this->
getEntity()->getType(),
154 if ((\CForumMessage::add($fields)) > 0)
156 $event =
new Event(
"forum",
"OnAfterCommentTopicAdd", array($this->
getEntity()->getType(), $this->
getEntity()->getId(), $tid));
159 self::$topics[$this->
getEntity()->getXmlId()] =
$topic + array(
"ID" => $tid);
160 return self::$topics[$this->
getEntity()->getXmlId()];
162 \CForumTopic::delete($tid);
164 $this->errorCollection->add(array(
new Error(
Loc::getMessage(
"FORUM_CM_TOPIC_IS_NOT_CREATED"), self::ERROR_PARAMS_TOPIC_ID)));
182 return $this->errorCollection->hasErrors();
190 return $this->errorCollection->toArray();
195 $res = (is_integer($forumId) || is_string($forumId) ? intval($forumId) : 0);
210 $this->forum = Forum\ForumTable::getMainData($id, SITE_ID);
235 foreach ($params as $key => $val)
237 if (array_key_exists($key, $this->forum))
238 $this->forum[$key] = $val;
249 $this->user = new \Bitrix\Forum\Comments\User($userId);
262 return $this->user->getUnreadMessageId($this->
getTopic() ? $this->
getTopic()[
"ID"] : 0);
272 $this->user->setLocation($this->forum[
"ID"], $this->
getTopic() ? $this->
getTopic()[
"ID"] : 0);
284 private static function getUserFromForum($userId)
286 if ($userId > 0 && !array_key_exists($userId, self::$users))
288 self::$users[$userId] = \CForumUser::getListEx(array(), array(
"USER_ID" => $userId))->fetch();
289 if(!self::$users[$userId])
291 self::$users[$userId] = \CUser::getById($userId)->fetch();
292 self::$users[$userId][
"SHOW_NAME"] = \COption::getOptionString(
"forum",
"USER_SHOW_NAME",
"Y");
295 return self::$users[$userId];
300 $user = self::getUserFromForum($userId);
304 $name = (
$user[
"SHOW_NAME"] ==
"Y" ? trim(
$user[
"NAME"].
" ".
$user[
"LAST_NAME"]) :
"");
305 $name = (empty($name) ?
$user[
"LOGIN"] : $name);
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)