22 private static $topics =
array();
23 private static $users =
array();
56 if (($id = array_change_key_case($id, CASE_LOWER)) && $id[
"id"] > 0)
59 throw new ArgumentException(Loc::getMessage(
"FORUM_CM_WRONG_ENTITY"), self::ERROR_PARAMS_ENTITY_ID);
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'];
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))
99 "FORUM_ID" => $this->forum[
"ID"],
100 "XML_ID" => $this->
getEntity()->getXmlId()
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();
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)
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);
208 throw new ArgumentTypeException(Loc::getMessage(
"FORUM_CM_FORUM_IS_WRONG"), self::ERROR_PARAMS_FORUM_ID);
213 throw new ArgumentException(Loc::getMessage(
"FORUM_CM_FORUM_IS_LOST"), self::ERROR_PARAMS_FORUM_ID);
237 if (array_key_exists(
$key, $this->forum))
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)
292 self::$users[
$userId][
"SHOW_NAME"] = \COption::getOptionString(
"forum",
"USER_SHOW_NAME",
"Y");
static includeModule($moduleName)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)