7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\ORM\EntityError;
9use Bitrix\Main\ORM\Event;
10use Bitrix\Main\ORM\Fields\FieldError;
11use Bitrix\Main\Result;
12use Bitrix\Main\Type\DateTime;
15Loc::loadMessages(__FILE__);
69 return 'b_forum_user';
81 'data_type' =>
'integer',
83 'autocomplete' =>
true,
86 'data_type' =>
'integer',
90 'data_type' =>
'Bitrix\Main\UserTable',
92 '=this.USER_ID' =>
'ref.ID'
95 'DESCRIPTION' =>
array(
96 'data_type' =>
'string',
99 'data_type' =>
'integer'
102 'data_type' =>
'integer'
105 'data_type' =>
'integer'
107 'NUM_POSTS' =>
array(
108 'data_type' =>
'integer'
110 'INTERESTS' =>
array(
111 'data_type' =>
'text'
113 'LAST_POST' =>
array(
114 'data_type' =>
'integer'
116 'SIGNATURE' =>
array(
117 'data_type' =>
'string'
119 'IP_ADDRESS' =>
array(
120 'data_type' =>
'string',
123 'REAL_IP_ADDRESS' =>
array(
124 'data_type' =>
'string',
128 'data_type' =>
'datetime',
130 'default_value' =>
function(){
return new DateTime();}
132 'LAST_VISIT' =>
array(
133 'data_type' =>
'datetime',
135 'default_value' =>
function(){
return new DateTime();}
137 'ALLOW_POST' =>
array(
138 'data_type' =>
"boolean",
139 'values' =>
array(
"N",
"Y"),
140 'default_value' =>
"Y"
142 'SHOW_NAME' =>
array(
143 'data_type' =>
"boolean",
144 'values' =>
array(
"N",
"Y"),
145 'default_value' =>
"Y"
147 'HIDE_FROM_ONLINE' =>
array(
148 'data_type' =>
"boolean",
149 'values' =>
array(
"N",
"Y"),
150 'default_value' =>
"N"
152 'SUBSC_GROUP_MESSAGE' =>
array(
153 'data_type' =>
"boolean",
154 'values' =>
array(
"N",
"Y"),
155 'default_value' =>
"N"
157 'SUBSC_GET_MY_MESSAGE' =>
array(
158 'data_type' =>
"boolean",
159 'values' =>
array(
"N",
"Y"),
160 'default_value' =>
"Y"
171 "filter" => [
"USER_ID" =>
$data[
"USER_ID"]]
194 if (array_key_exists(
"AVATAR",
$data))
197 "width" =>
Main\
Config\Option::get(
"forum",
"avatar_max_width", 100),
198 "height" =>
Main\
Config\Option::get(
"forum",
"avatar_max_height", 100)));
200 if (
$str = \CFile::CheckImageFile(
$data[
"AVATAR"], $maxSize))
207 $fields[
"AVATAR"][
"MODULE_ID"] =
"forum";
208 if ($id =
$event->getParameter(
"id"))
210 $id = is_integer($id) ? $id : $id[
"ID"];
216 if (!\CFile::SaveForDB(
$fields,
"AVATAR",
"forum/avatar"))
233 $id =
$event->getParameter(
"id");
235 if (($events =
GetModuleEvents(
"forum",
"onBeforeUserDelete",
true)) && !empty($events))
237 foreach ($events as $ev)
248 \CFile::Delete(
$user[
"AVATAR"]);
255 $id =
$event->getParameter(
"id");
257 foreach(
GetModuleEvents(
"forum",
"onAfterUserDelete",
true) as $arEvent)
264class User implements \ArrayAccess {
266 use Internals\EntityBaseMethods;
281 private $editOwn =
false;
286 'VISIBLE_NAME' =>
'Guest',
292 $user = UserTable::getList([
294 'ID',
'USER_ID',
'POINTS',
'NUM_POSTS',
'LAST_POST',
'ALLOW_POST',
'SHOW_NAME',
295 'ACTIVE' =>
'USER.ACTIVE',
296 'NAME' =>
'USER.NAME',
297 'SECOND_NAME' =>
'USER.SECOND_NAME',
298 'LAST_NAME' =>
'USER.LAST_NAME',
299 'LOGIN' =>
'USER.LOGIN'
301 'filter' => [
'USER_ID' => (
int)
$id],
306 $this->forumUserId =
$user[
'ID'];
307 $this->
id =
$user[
'USER_ID'];
308 $this->locked = (
$user[
'ACTIVE'] !==
'Y' ||
$user[
'ALLOW_POST'] !==
'Y');
311 'select' => [
'ID',
'ACTIVE',
'NAME',
'SECOND_NAME',
'LAST_NAME',
'LOGIN'],
312 'filter' => [
'ID' => (
int)
$id],
316 $this->
id =
$user[
'ID'];
317 $this->locked = (
$user[
'ACTIVE'] !==
'Y');
319 $user[
'ALLOW_POST'] =
'Y';
320 $user[
'SHOW_NAME'] = (\COption::GetOptionString(
'forum',
'USER_SHOW_NAME',
'Y') ==
'Y' ?
'Y' :
'N');
327 $this->data[
'ALLOW_POST'] = (($this->data[
'ALLOW_POST'] ??
'Y') ===
'N' ?
'N' :
'Y');
328 if (empty($this->data[
'SHOW_NAME']))
329 $this->data[
'SHOW_NAME'] = \COption::GetOptionString(
'forum',
'USER_SHOW_NAME',
'Y');
330 $this->data[
'SHOW_NAME'] = $this->data[
'SHOW_NAME'] ==
'N' ?
'N' :
'Y';
331 $this->data[
'VISIBLE_NAME'] = ($this->data[
'SHOW_NAME'] ===
'Y' ? \CUser::FormatName(\CSite::getNameFormat(
false),
$user,
true,
false) : $this->data[
'LOGIN']);
332 $this->editOwn = (\COption::GetOptionString(
'forum',
'USER_EDIT_OWN_POST',
'Y') ==
'Y');
340 return $this->data[
"VISIBLE_NAME"];
345 if ($this->getId() <= 0)
353 $update = $helper->prepareUpdate($tableName, [
'LAST_VISIT' =>
new Main\
DB\
SqlExpression($helper->getCurrentDateTimeFunction())]);
354 $where = $helper->prepareAssignment($tableName,
'USER_ID', $this->getId());
355 $sql =
'UPDATE '.$helper->quote($tableName).
' SET '.$update[0].
' WHERE '.$where;
359 $merge = $helper->prepareMerge(
363 'SHOW_NAME' => ($this->data[
'SHOW_NAME'] ===
'N' ?
'N' :
'Y'),
364 'ALLOW_POST' => ($this->data[
'ALLOW_POST'] ===
'N' ?
'N' :
'Y'),
365 'USER_ID' => $this->getId(),
379 unset(
$GLOBALS[
'FORUM_CACHE'][
'USER']);
380 unset(
$GLOBALS[
'FORUM_CACHE'][
'USER_ID']);
397 'USER_ID' => $this->getId(),
398 'PHPSESSID' => $this->getSessId()
401 'SHOW_NAME' => $this->
getName(),
405 'FORUM_ID' => $forumId,
406 'TOPIC_ID' => $topicId,
409 if ($this->getId() > 0)
411 $fields[
'PHPSESSID'] = $primaryFields[
'PHPSESSID'];
414 $merge = $helper->prepareMerge(
416 array_keys($primaryFields),
440 return ($this->getId() <= 0);
445 return ($this->getId() > 0);
457 foreach (
GetModuleEvents(
"forum",
"onBeforeUserEdit",
true) as $arEvent)
493 if (
$res = MessageTable::getList([
494 "select" => [
"CNT",
"LAST_MESSAGE_ID"],
495 "filter" => [
"AUTHOR_ID" => $this->getId(),
"=APPROVED" =>
"Y"],
503 "LAST_POST" =>
$res[
"LAST_MESSAGE_ID"],
504 "NUM_POSTS" =>
$res[
"CNT"],
513 if (!$this->
isAuthorized() || $message[
"APPROVED"] !=
"Y")
518 $this->data[
"NUM_POSTS"]++;
520 $this->data[
"LAST_POST"] =
$message[
"ID"];
523 "POINTS" => $this->data[
"POINTS"],
535 $this->data[
'NUM_POSTS']--;
539 'POINTS' => $this->data[
'POINTS'],
542 $message[
'ID'] === $this->data[
'LAST_POST']
547 'filter' => [
'AUTHOR_ID' => $this->getId(),
'APPROVED' =>
'Y'],
549 'order' => [
'ID' =>
'DESC']
551 $this->data[
'LAST_POST'] =
$message[
'ID'];
569 $topic = Topic::getById($topicId);
576 $query = MessageTable::query()
578 ->where(
'TOPIC_ID', $topic->getId())
580 ->setOrder([
'FORCED_INT_ID' =>
'ASC'])
585 ->registerRuntimeField(
591 '=this.TOPIC_ID' =>
'ref.TOPIC_ID',
592 '=ref.USER_ID' => [
'?i', $this->getId()],
594 [
'join_type' =>
'LEFT']
597 ->registerRuntimeField(
601 UserForumTable::getEntity(),
603 '=this.FORUM_ID' =>
'ref.FORUM_ID',
604 '=ref.USER_ID' => [
'?i', $this->getId()]
606 [
'join_type' =>
'LEFT']
609 ->registerRuntimeField(
613 UserForumTable::getEntity(),
615 '=this.FORUM_ID' => [
'?i', 0],
616 '=ref.USER_ID' => [
'?i', $this->getId()]
618 [
'join_type' =>
'LEFT']
626 ->whereNotNull(
'USER_TOPIC.LAST_VISIT')
627 ->whereColumn(
'POST_DATE',
'>',
'USER_TOPIC.LAST_VISIT')
631 ->whereNull(
'USER_TOPIC.LAST_VISIT')
632 ->whereColumn(
'POST_DATE',
'>',
'USER_FORUM.LAST_VISIT')
636 ->whereNull(
'USER_TOPIC.LAST_VISIT')
637 ->whereNull(
'USER_FORUM.LAST_VISIT')
638 ->whereColumn(
'POST_DATE',
'>',
'USER_FORUM_0.LAST_VISIT')
642 ->whereNull(
'USER_TOPIC.LAST_VISIT')
643 ->whereNull(
'USER_FORUM.LAST_VISIT')
644 ->whereNull(
'USER_FORUM_0.LAST_VISIT')
651 $timestamps = $this->getFromSession(
'GUEST_TID');
653 $this->getFromSession(
'LAST_VISIT_FORUM_0'),
654 $this->getFromSession(
'LAST_VISIT_FORUM_'.$topic->getForumId()),
655 is_array($timestamps) && array_key_exists($topic->getId(), $timestamps) ? $timestamps[$topic->getId()] : 0
659 $query->where(
'POST_DATE',
'>', DateTime::createFromTimestamp($lastVisit));
680 || !($topic = Topic::getById($topicId))
681 || !($topic instanceof
Topic)
687 $topic->incrementViews();
695 'USER_ID' => $this->getId(),
696 'TOPIC_ID' => $topic->getId()
700 'FORUM_ID' => $topic->getForumId(),
705 if (
$result->getAffectedRowsCount() <= 0)
707 $merge = $helper->prepareMerge(
708 'b_forum_user_topic',
709 array_keys($primaryFields),
722 $this->saveInSession(
'GUEST_TID',
null);
724 if (
Main\
Config\Option::set(
'forum',
'USE_COOKIE',
'N') ==
'Y')
726 $GLOBALS[
'APPLICATION']->set_cookie(
'FORUM_GUEST_TID',
'',
false,
'/',
false,
false,
'Y',
false);
739 'USER_ID' => $this->getId(),
740 'FORUM_ID' => $forumId
748 if (
$result->getAffectedRowsCount() <= 0)
750 $merge = $helper->prepareMerge(
752 array_keys($primaryFields),
775 $topics = $this->saveInSession(
'GUEST_TID', [$topic->getId() => $timestamp->getTimestamp()]);
777 if (
Main\
Config\Option::set(
'forum',
'USE_COOKIE',
'N') ==
'Y')
779 foreach ($topics as $topicId => $timestamp)
781 $topics[$topicId] = implode(
'-', [$topicId, $timestamp]);
783 $GLOBALS[
'APPLICATION']->set_cookie(
'FORUM_GUEST_TID', implode(
'/', $topics),
false,
'/',
false,
false,
'Y',
false);
797 if ($this->forumUserId > 0)
803 if (Main\Application::getConnection()->getType() ===
'pgsql')
817 $this->forumUserId =
$res;
829 if ($this->getId() <= 0 || $this->
isLocked())
831 if (
Main\
Config\Option::get(
"main",
"new_user_registration",
"") ==
"Y")
834 if($def_group !=
"" && (
$res = explode(
",", $def_group)))
836 $this->groups = array_merge($this->groups,
$res);
842 $this->groups =
$USER->GetUserGroupArray();
847 "select" => [
"GROUP_ID"],
848 "filter" => [
"USER_ID" => $this->getId()],
849 "order" => [
"GROUP_ID" =>
"ASC"]
853 $this->groups[] =
$res[
"GROUP_ID"];
862 $forum = Forum\Forum::getInstance($forum);
863 $this->permissions[$forum->getId()] = $permission;
869 $forum = Forum\Forum::getInstance($forum);
870 if (!array_key_exists($forum->getId(), $this->permissions))
872 $this->permissions[$forum->getId()] = $forum->getPermissionForUser($this);
874 return $this->permissions[$forum->getId()];
909 ($this->editOwn || ($topic[
"POSTS"] <= 0 && $topic[
"POSTS_UNAPPROVED"] <= 0))
927 if ($this->getId() ==
$message->getAuthorId())
933 $topic = Topic::getById(
$message[
"TOPIC_ID"]);
934 if ($topic[
"ABS_LAST_MESSAGE_ID"] ==
$message->getId())
973 private function saveInSession(
string $name, $value)
975 if (method_exists(
Main\Application::getInstance(),
'getKernelSession'))
981 $forumSession = $_SESSION[
'FORUM'];
983 $forumSession = is_array($forumSession) ? $forumSession : [];
984 if (is_array($value) && array_key_exists(
$name, $forumSession) && is_array($forumSession[
$name]))
986 $forumSession[
$name] = $value + $forumSession[
$name];
992 if (method_exists(Main\Application::getInstance(),
'getKernelSession'))
994 Main\Application::getInstance()->getKernelSession()->set(
'FORUM', $forumSession);
998 $_SESSION[
'FORUM'] = $forumSession;
1000 return $forumSession[
$name];
1003 private function getFromSession(
string $name)
1005 if (method_exists(Main\Application::getInstance(),
'getKernelSession'))
1007 $forumSession = Main\Application::getInstance()->getKernelSession()->get(
'FORUM');
1011 $forumSession = $_SESSION[
'FORUM'];
1013 if (is_array($forumSession) && array_key_exists(
$name, $forumSession))
1015 return $forumSession[
$name];
1020 private function getSessId()
1022 if (method_exists(Main\Application::getInstance(),
'getKernelSession'))
1024 return Main\Application::getInstance()->getKernelSession()->getId();
1031 $result = new \Bitrix\Main\ORM\Data\AddResult();
1032 if (($events =
GetModuleEvents(
"forum",
"onBeforeUserAdd",
true)) && !empty($events))
1035 foreach ($events as $ev)
1041 $errorMessage = Loc::getMessage(
"FORUM_EVENT_BEFORE_USER_ADD");
1074 unset(
$data[
"USER_ID"]);
1079 if (($events =
GetModuleEvents(
"forum",
"onBeforeUserUpdate",
true)) && !empty($events))
1082 foreach ($events as $ev)
1088 $errorMessage = Loc::getMessage(
"FORUM_EVENT_BEFORE_USER_UPDATE_ERROR");
static deleteBatch(array $filter)
canReadForum(Forum\Forum $forum)
canDeleteForum(Forum\Forum $forum)
decrementStatistic($message=null)
readTopicsOnForum(int $forumId=0)
incrementStatistic(array $message)
getUnreadMessageId($topicId=0)
setLocation(int $forumId=0, int $topicId=0)
canReadTopic(Topic $topic)
canAddTopic(Forum\Forum $forum)
canEditMessage(Message $message)
canDeleteMessage(Message $message)
canEditForum(Forum\Forum $forum)
static isUserAdmin(array $groups)
setPermissionOnForum($forum, $permission)
canAddMessage(Topic $topic)
static update(int $id, array &$data)
canEditTopic(Topic $topic)
canModerate(Forum\Forum $forum)
getPermissionOnForum($forum)
static onAfterDelete(Main\ORM\Event $event)
static onBeforeUpdate(Main\ORM\Event $event)
static onBeforeDelete(Main\ORM\Event $event)
static deleteBatch(array $filter)
static getConnection($name="")
static get($moduleId, $name, $default="", $siteId=false)
static getList(array $parameters=array())
static onBeforeAdd(Event $event)
static update($primary, array $data)
static GetUserPoints($USER_ID, $arAddParams=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
ExecuteModuleEventEx($arEvent, $arParams=[])
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)