6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\ORM\Event;
8use Bitrix\Main\ORM\Fields\BooleanField;
9use Bitrix\Main\ORM\Fields\DatetimeField;
10use Bitrix\Main\ORM\Fields\EnumField;
11use Bitrix\Main\ORM\Fields\IntegerField;
12use Bitrix\Main\ORM\Fields\Relations\Reference;
13use Bitrix\Main\ORM\Fields\StringField;
14use Bitrix\Main\ORM\Fields\TextField;
15use Bitrix\Main\ORM\Query\Join;
16use Bitrix\Main\Type\DateTime;
79 return 'b_forum_topic';
90 (
new IntegerField(
"ID", [
"primary" =>
true,
"autocomplete" =>
true])),
93 (
new StringField(
"TITLE", [
"required" =>
true,
"size" => 255])),
103 (
new StringField(
"USER_START_NAME", [
"required" =>
true,
"size" => 255])),
104 (
new DatetimeField(
"START_DATE", [
"required" =>
true,
"default_value" =>
function(){
return new DateTime();}])),
108 (
new StringField(
"LAST_POSTER_NAME", [
"required" =>
true,
"size" => 255])),
109 (
new DatetimeField(
"LAST_POST_DATE", [
"required" =>
true,
"default_value" =>
function(){
return new DateTime();}])),
111 (
new IntegerField(
"POSTS_UNAPPROVED", [
"default_value" => 0])),
113 (
new StringField(
"ABS_LAST_POSTER_NAME", [
"size" => 255])),
114 (
new DatetimeField(
"ABS_LAST_POST_DATE", [
"required" =>
true,
"default_value" =>
function(){
return new DateTime();}])),
120 (
new Reference(
"FORUM", ForumTable::class, Join::on(
"this.FORUM_ID",
"ref.ID")))
132 "ABS_LAST_POSTER_NAME"
141 if (
Main\
Config\Option::get(
"forum",
"FILTER",
"Y") ==
"Y")
144 foreach ($filteredFields as
$key)
159 $data[
"TITLE_SEO"] = array_key_exists(
"TITLE_SEO",
$data) ? trim(
$data[
"TITLE_SEO"],
" -") :
"";
160 if (empty(
$data[
"TITLE_SEO"]))
162 $data[
"TITLE_SEO"] = \CUtil::translit(
$data[
"TITLE"], LANGUAGE_ID,
array(
"max_len"=>255,
"safe_chars"=>
".",
"replace_space" =>
'-'));
178 public static function onBeforeUpdate(Main\ORM\Event
$event)
180 $result =
new Main\ORM\EventResult();
183 $id =
$event->getParameter(
"id");
187 if (Main\Config\Option::get(
"forum",
"FILTER",
"Y") ==
"Y")
190 if (!empty(array_intersect($filteredFields, array_keys(
$data))))
192 $topic = TopicTable::getById($id)->fetch();
194 foreach ($filteredFields as
$key)
209 if (array_key_exists(
"TITLE_SEO",
$data) || array_key_exists(
"TITLE",
$data))
211 $data[
"TITLE_SEO"] = trim(
$data[
"TITLE_SEO"],
" -");
212 if (
$data[
"TITLE_SEO"] ==
'')
214 if (array_key_exists(
"TITLE",
$data))
222 $res = \Bitrix\Forum\TopicTable::query()->setSelect([
'TITLE'])
232 $data[
"TITLE_SEO"] = \CUtil::translit(
$title, LANGUAGE_ID,
array(
"max_len"=>255,
"safe_chars"=>
".",
"replace_space" =>
'-'));
248 $id =
$event->getParameter(
"id");
251 if (array_key_exists(
"FORUM_ID",
$fields))
271 $key = array_key_exists(
"VIEWS",
$data) ?
"VIEWS" : (array_key_exists(
"=VIEWS",
$data) ?
"=VIEWS" :
null);
272 if (
$key !==
null && str_replace(
" ",
"",
$data[
$key]) ===
"VIEWS+1")
288 use \Bitrix\Forum\Internals\EntityFabric;
302 parent::__construct($id);
307 if (!($this->data = TopicTable::getById($this->
id)->fetch()))
311 $this->authorId = intval($this->data[
"USER_START_ID"]);
312 $this->data[
"~TITLE_SEO"] = $this->data[
"TITLE_SEO"];
313 $this->data[
"TITLE_SEO"] = implode(
"-", [$this->data[
"ID"], $this->data[
"TITLE_SEO"]]);
319 if ($forumId == $this->forum->getId())
323 $newForum = \Bitrix\Forum\Forum::getById($forumId);
324 TopicTable::update($this->
getId(), [
"FORUM_ID" => $newForum->getId()]);
325 $this->forum->calculateStatistic();
326 $newForum->calculateStatistic();
335 if ($this->data[
"STATE"] === self::STATE_CLOSED)
337 if (
Forum\TopicTable::update($this->
getId(), [
"STATE" => self::STATE_OPENED])->isSuccess())
339 $this->data[
"STATE"] = self::STATE_OPENED;
341 $result->setData([
"STATE" => self::STATE_OPENED]);
342 (
new Main\Event(
"forum",
"onTopicOpen", [$this->
getId(), $this->data]))->send();
355 if ($this->data[
"STATE"] === self::STATE_OPENED)
357 if (
Forum\TopicTable::update($this->
getId(), [
"STATE" => self::STATE_CLOSED])->isSuccess())
359 $this->data[
"STATE"] = self::STATE_CLOSED;
361 $result->setData([
"STATE" => self::STATE_CLOSED]);
362 (
new Main\Event(
"forum",
"onTopicClose", [$this->
getId(), $this->data]))->send();
375 if ($this->data[
"APPROVED"] === self::APPROVED_APPROVED)
377 $this->data[
"APPROVED"] = self::APPROVED_DISAPPROVED;
378 TopicTable::update($this->
getId(), [
"APPROVED" => self::APPROVED_DISAPPROVED]);
383 $res = $this->forum->getPermissions();
385 foreach (
$res as $group => $permission)
398 $this->forum->calculateStatistic();
405 $result->setData([
"APPROVED" => self::APPROVED_DISAPPROVED]);
413 if ($this->data[
"APPROVED"] !== self::APPROVED_APPROVED)
415 $this->data[
"APPROVED"] = self::APPROVED_APPROVED;
416 TopicTable::update($this->
getId(), [
"APPROVED" => self::APPROVED_APPROVED]);
421 $res = $this->forum->getPermissions();
423 foreach (
$res as $group => $permission)
436 $this->forum->calculateStatistic();
443 $result->setData([
"APPROVED" => self::APPROVED_APPROVED]);
448 public function remove()
451 if (self::deleteTopic($this->
getId(), $this->data)->isSuccess())
454 Forum\Forum::getById($this->
getForumId())->calculateStatistic();
466 $forum = Forum\Forum::getInstance($parentObject);
475 "TITLE_SEO" =>
$fields[
"TITLE_SEO"] ??
'',
476 "TAGS" =>
$fields[
"TAGS"] ??
'',
477 "DESCRIPTION" =>
$fields[
"DESCRIPTION"] ??
'',
478 "ICON" =>
$fields[
"ICON"] ??
'',
480 "APPROVED" =>
$fields[
"APPROVED"] ??
'Y',
483 "POSTS_SERVICE" => 0,
484 "POSTS_UNAPPROVED" => 0,
486 "USER_START_ID" => $author[
"ID"],
487 "USER_START_NAME" => $author[
"NAME"],
488 "START_DATE" => $date,
490 "LAST_POSTER_ID" => $author[
"ID"],
491 "LAST_POSTER_NAME" => $author[
"NAME"],
492 "LAST_POST_DATE" => $date,
493 "LAST_MESSAGE_ID" => 0,
495 "ABS_LAST_POSTER_ID" => $author[
"ID"],
496 "ABS_LAST_POSTER_NAME" => $author[
"NAME"],
497 "ABS_LAST_POST_DATE" => $date,
498 "ABS_LAST_MESSAGE_ID" => 0,
500 "XML_ID" =>
$fields[
"TOPIC_XML_ID"] ??
'',
502 "OWNER_ID" =>
$fields[
"OWNER_ID"] ??
null,
503 "SOCNET_GROUP_ID" =>
$fields[
"SOCNET_GROUP_ID"] ?? null
508 $messageData =
array(
510 "APPROVED" => $topicData[
"APPROVED"],
512 "USE_SMILES" =>
$fields[
"USE_SMILES"] ??
'Y',
513 "POST_DATE" => $date,
514 "POST_MESSAGE" =>
$fields[
"POST_MESSAGE"],
516 "ATTACH_IMG" =>
$fields[
"ATTACH_IMG"] ??
null,
517 "FILES" =>
$fields[
"FILES"] ??
null,
519 "PARAM1" =>
$fields[
"PARAM1"] ??
null,
520 "PARAM2" =>
$fields[
"PARAM2"] ??
null,
522 "AUTHOR_ID" => $author[
"ID"],
523 "AUTHOR_NAME" => $author[
"NAME"],
524 "AUTHOR_EMAIL" =>
$fields[
"AUTHOR_EMAIL"] ??
'',
526 "AUTHOR_IP" =>
$fields[
"AUTHOR_IP"] ??
null,
527 "AUTHOR_REAL_IP" =>
$fields[
"AUTHOR_REAL_IP"] ??
null,
528 "GUEST_ID" =>
$fields[
"GUEST_ID"] ??
null,
533 $topic = Topic::getById(
$result->getId());
538 $result->setData([
"MESSAGE_ID" =>
$result->getId(),
"TOPIC_ID" => $topic->getId()]);
541 TopicTable::update($topic->getId(), [
"LAST_MESSAGE_ID" =>
$message[
"ID"],
"ABS_LAST_MESSAGE_ID" =>
$message[
"ID"]]);
549 TopicTable::delete($topic->getId());
561 if (($events =
GetModuleEvents(
"forum",
"onBeforeTopicAdd",
true)) && !empty($events))
564 foreach ($events as $ev)
570 $errorMessage = Loc::getMessage(
"FORUM_EVENT_BEFORE_TOPIC_ADD");
608 if (!($m = MessageTable::getList([
610 "filter" => [
"TOPIC_ID" => $this->
getId(),
"NEW_TOPIC" =>
"Y"],
619 $topicData = array_intersect_key(
630 if (array_key_exists(
"AUTHOR_NAME",
$fields))
632 $topicData[
"USER_START_NAME"] =
$fields[
"AUTHOR_NAME"];
635 if (!empty($topicData))
640 $this->data = TopicTable::getById($this->
getId())->fetch();
645 if (!$result->isSuccess())
653 $result->setPrimary([
"ID" => $m[
"ID"]]);
654 $result->setData([
"MESSAGE_ID" => $m[
"ID"],
"TOPIC_ID" => $this->
getId()]);
658 if (
$forum[
"INDEXATION"] ===
"Y" && $fieldsBefore !== $fieldsAfter)
660 $searchKeys = [
"TITLE",
"TITLE_SEO",
"TAGS",
"DESCRIPTION"];
661 $diffData = array_intersect_key(
662 array_diff_assoc($fieldsAfter, $fieldsBefore),
663 array_flip($searchKeys)
665 if (array_key_exists(
'TITLE', $diffData)
666 || array_key_exists(
'TITLE_SEO', $diffData))
675 Forum\MessageTable::getById($m[
"ID"])->fetch()
681 $log = array_diff_assoc(
682 array_intersect_key($fieldsBefore + $m,
$fields),
686 function (&$item,
$key, $fieldsAfter)
690 'after' => $fieldsAfter[
$key]
694 unset($log[
"EDIT_DATE"]);
702 unset(
$data[
"FORUM_ID"]);
705 $result->setPrimary([
"ID" => $id]);
707 if (($events =
GetModuleEvents(
"forum",
"onBeforeTopicUpdate",
true)) && !empty($events))
709 $topic = Forum\TopicTable::getById($id)->fetch();
711 foreach ($events as $ev)
717 $errorMessage = Loc::getMessage(
"FORUM_EVENT_BEFORE_TOPIC_UPDATE_ERROR");
746 $result =
new Main\Orm\Data\DeleteResult();
747 if (!($topicData =
Forum\TopicTable::getById($id)->fetch()))
752 return self::deleteTopic($id, $topicData);
757 $result =
new Main\Orm\Data\DeleteResult();
760 foreach (
GetModuleEvents(
"forum",
"onBeforeTopicDelete",
true) as $arEvent)
776 Forum\Internals\MessageCleaner::runForTopic($id);
777 Main\Application::getConnection()->queryExecute(
"DELETE FROM b_forum_subscribe WHERE TOPIC_ID = ".$id);
778 Main\Application::getConnection()->queryExecute(
"DELETE FROM b_forum_message WHERE TOPIC_ID = ".$id);
779 Main\Application::getConnection()->queryExecute(
"DELETE FROM b_forum_user_topic WHERE TOPIC_ID = ".$id);
780 Main\Application::getConnection()->queryExecute(
"DELETE FROM b_forum_topic WHERE ID = ".$id);
781 Main\Application::getConnection()->queryExecute(
"DELETE FROM b_forum_topic WHERE TOPIC_ID = ".$id);
782 Main\Application::getConnection()->queryExecute(
"DELETE FROM b_forum_stat WHERE TOPIC_ID = ".$id);
785 foreach(
GetModuleEvents(
"forum",
"onAfterTopicDelete",
true) as $arEvent)
796 "ABS_LAST_POSTER_ID" =>
$message[
"AUTHOR_ID"],
797 "ABS_LAST_POSTER_NAME" =>
$message[
"AUTHOR_NAME"],
798 "ABS_LAST_POST_DATE" =>
$message[
"POST_DATE"],
799 "ABS_LAST_MESSAGE_ID" =>
$message[
"ID"]
801 $this->data = array_merge($this->data,
$fields);
806 "LAST_POSTER_ID" =>
$message[
"AUTHOR_ID"],
807 "LAST_POSTER_NAME" =>
$message[
"AUTHOR_NAME"],
808 "LAST_POST_DATE" =>
$message[
"POST_DATE"],
811 $this->data = array_merge($this->data,
$fields);
815 $this->data[
"POSTS"]++;
817 if (!empty(
$message[
"SERVICE_TYPE"]))
820 $this->data[
"POSTS_SERVICE"]++;
826 $this->data[
"POSTS_UNAPPROVED"]++;
837 $this->data[
'POSTS']--;
838 if (!empty(
$message[
"SERVICE_TYPE"]))
841 $this->data[
"POSTS_SERVICE"]--;
847 $this->data[
'POSTS_UNAPPROVED']--;
850 if (
$message[
'NEW_TOPIC'] ===
'Y' && ($firstMessage = MessageTable::getList([
852 'filter' => [
'TOPIC_ID' => $this->
getId()],
853 'order' => [
'ID' =>
'ASC'],
857 $fields[
'USER_START_ID'] = $firstMessage[
'AUTHOR_ID'];
858 $fields[
'USER_START_NAME'] = $firstMessage[
'AUTHOR_NAME'];
859 $fields[
'START_DATE'] = $firstMessage[
'POST_DATE'];
860 if ($this->data[
'APPROVED'] ===
'Y' && $firstMessage[
'APPROVED'] !==
'Y' && $this->data[
'POSTS'] < 0)
865 else if (
$message[
'ID'] >= $this->data[
'LAST_MESSAGE_ID'])
867 if (
$message[
'ID'] === $this->data[
'LAST_MESSAGE_ID']
869 ($lastMessage =
Forum\MessageTable::getList([
870 'select' => [
'ID',
'AUTHOR_ID',
'AUTHOR_NAME',
'POST_DATE'],
872 'TOPIC_ID' => $this->
getId(),
875 'order' => [
'ID' =>
'DESC'],
881 'LAST_POSTER_ID' => $lastMessage[
'AUTHOR_ID'],
882 'LAST_POSTER_NAME' => $lastMessage[
'AUTHOR_NAME'],
883 'LAST_POST_DATE' => $lastMessage[
'POST_DATE'],
884 'LAST_MESSAGE_ID' => $lastMessage[
'ID']
888 if (
$message[
'ID'] === $this->data[
'ABS_LAST_MESSAGE_ID']
890 ($lastMessage =
Forum\MessageTable::getList([
891 'select' => [
'ID',
'AUTHOR_ID',
'AUTHOR_NAME',
'POST_DATE'],
892 'filter' => [
'TOPIC_ID' => $this->
getId()],
893 'order' => [
'ID' =>
'DESC'],
899 'ABS_LAST_POSTER_ID' => $lastMessage[
'AUTHOR_ID'],
900 'ABS_LAST_POSTER_NAME' => $lastMessage[
'AUTHOR_NAME'],
901 'ABS_LAST_POST_DATE' => $lastMessage[
'POST_DATE'],
902 'ABS_LAST_MESSAGE_ID' => $lastMessage[
'ID']
908 $this->data = array_merge($this->data, array_filter(
$fields,
function($item) {
917 if (isset($firstMessage) && $firstMessage)
919 $result->setData($firstMessage);
static index(Forum\Forum $forum, Forum\Topic $topic, array $message)
static reindex(int $topicId, bool $reindexOnlyFirstMessage=false)
static deleteIndex(Forum\Topic $topic)
const APPROVED_DISAPPROVED
static add(Forum\Topic $topic, array $fields)
static update($id, array &$fields)
static getDataById($id, $ttl=84600)
static runForTopic(int $topicId)
const APPROVED_DISAPPROVED
incrementStatistic(array $message)
decrementStatistic(array $message)
moveToForum(int $forumId)
static update(int $id, array &$data)
static create($parentObject, array $fields)
static add(Forum\Forum $forum, array &$data)
static getFilteredFields()
static onAfterUpdate(Main\ORM\Event $event)
static includeModule($moduleName)
static ChangePermission($MODULE_ID, $arGroups, $ITEM_ID=false, $PARAM1=false, $PARAM2=false, $SITE_ID=false, $PARAMS=false)
static Log($object, $action, $id, $description="", $title="")
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
global $USER_FIELD_MANAGER
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
ExecuteModuleEventEx($arEvent, $arParams=[])
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
if(empty($signedUserToken)) $key