• Модуль: forum
  • Путь к файлу: ~/bitrix/modules/forum/lib/comments/baseobject.php
  • Класс: BitrixForumCommentsBaseObject
  • Вызов: BaseObject::createTopic
protected function createTopic()
{
	$topic = array(
		'TITLE' => $this->getEntity()->getXmlId(),
		'TAGS' => '',
		'MESSAGE' => $this->getEntity()->getXmlId(),
		'AUTHOR_ID' => 0
	);
	/** @var $request BitrixMainHttpRequest */
	$request = BitrixMainContext::getCurrent()->getRequest();
	$post = array_merge($request->getQueryList()->toArray(), $request->getPostList()->toArray());

	$event = new Event("forum", "OnCommentTopicAdd", array($this->getEntity()->getType(), $this->getEntity()->getId(), $post, &$topic));
	$event->send();

	if (!isset($topic["AUTHOR_NAME"]) || strlen($topic["AUTHOR_NAME"]) <= 0)
		$topic["AUTHOR_NAME"] = ($topic["AUTHOR_ID"] <= 0 ? Loc::getMessage("FORUM_USER_SYSTEM") : self::getUserName($topic["AUTHOR_ID"]));

	$topic = array_merge($topic, array(
		"FORUM_ID" => $this->forum["ID"],
		'TITLE' => $topic["TITLE"],
		'TAGS' => $topic["TAGS"],
		'MESSAGE' => $topic["MESSAGE"],
		"USER_START_ID" => $topic["AUTHOR_ID"],
		"USER_START_NAME" => $topic["AUTHOR_NAME"],
		"LAST_POSTER_NAME" => $topic["AUTHOR_NAME"],
		"XML_ID" => $this->getEntity()->getXmlId(),
		"APPROVED" => "Y"
	));
	if (($tid = CForumTopic::add($topic)) > 0)
	{
		if ($this->forum["ALLOW_HTML"] != "Y")
			$topic['MESSAGE'] = strip_tags($topic['MESSAGE']);

		$fields = Array(
			"POST_MESSAGE" => $topic['MESSAGE'],
			"AUTHOR_ID" => $topic["AUTHOR_ID"],
			"AUTHOR_NAME" => $topic["AUTHOR_NAME"],
			"FORUM_ID" => $topic["FORUM_ID"],
			"TOPIC_ID" => $tid,
			"APPROVED" => $topic["APPROVED"],
			"NEW_TOPIC" => "Y",
			"XML_ID" => $this->getEntity()->getXmlId(),
			"PARAM1" => $this->getEntity()->getType(),
			"PARAM2" => $this->getEntity()->getId()
		);
		if ((CForumMessage::add($fields)) > 0)
		{
			$event = new Event("forum", "OnAfterCommentTopicAdd", array($this->getEntity()->getType(), $this->getEntity()->getId(), $tid));
			$event->send();

			self::$topics[$this->getEntity()->getXmlId()] = $topic + array("ID" => $tid);
			return self::$topics[$this->getEntity()->getXmlId()];
		}
		CForumTopic::delete($tid);
	}
	$this->errorCollection->add(array(new Error(Loc::getMessage("FORUM_CM_TOPIC_IS_NOT_CREATED"), self::ERROR_PARAMS_TOPIC_ID)));
	return null;
}