3namespace Bitrix\Im\Configuration;
5use Bitrix\Im\Call\VideoStrategyType;
6use Bitrix\Im\Model\OptionStateTable;
7use Bitrix\Im\Model\OptionUserTable;
8use Bitrix\Im\V2\Application\Features;
9use Bitrix\Main\ArgumentException;
10use Bitrix\Main\Config\Option;
11use Bitrix\Main\ObjectPropertyException;
12use Bitrix\Main\ORM\Fields\ExpressionField;
13use Bitrix\Main\ORM\Fields\Relations\Reference;
14use Bitrix\Main\ORM\Query\Join;
15use Bitrix\Main\SystemException;
16use Bitrix\Main\UserTable;
46 if (!isset(self::$instanceList[
$userId]))
55 return self::$instanceList[
$userId];
65 return $this->userSettings[$settingName];
76 if (!empty($preset) && isset($preset[
'general'][
'settings']) && is_array($preset[
'general'][
'settings']))
78 $preset[
'general'][
'settings'] =
79 array_replace_recursive(self::getDefaultSettings(), $preset[
'general'][
'settings'])
82 $this->userSettings = $preset[
'general'][
'settings'];
99 'backgroundImage' =>
false,
102 'generalNotify' =>
true,
104 'nativeNotify' =>
true,
105 'openDesktopFromPanel' =>
true,
106 'viewOffline' => Option::get(
"im",
"view_offline"),
107 'viewGroup' => Option::get(
"im",
"view_group"),
108 'viewLastMessage' =>
true,
109 'viewBirthday' =>
true,
110 'viewCommonUsers' =>
true,
111 'enableSound' =>
true,
112 'enableBigSmile' =>
true,
113 'enableDarkTheme' =>
'auto',
114 'isCurrentThemeDark' =>
false,
115 'enableRichLink' =>
true,
116 'linesTabEnable' =>
true,
117 'linesNewGroupEnable' =>
false,
118 'sendByEnter' => Option::get(
"im",
"send_by_enter"),
119 'correctText' => Option::get(
"im",
"correct_text"),
120 'panelPositionHorizontal' => Option::get(
"im",
"panel_position_horizontal"),
121 'panelPositionVertical' => Option::get(
"im",
"panel_position_vertical"),
122 'loadLastMessage' =>
true,
123 'loadLastNotify' => Option::get(
"im",
"load_last_notify"),
124 'notifyAutoRead' =>
true,
125 'notifyScheme' =>
'simple',
126 'notifySchemeLevel' =>
'important',
127 'notifySchemeSendSite' =>
true,
129 'notifySchemeSendXmpp' =>
true,
130 'notifySchemeSendPush' =>
true,
131 'privacyMessage' => Option::get(
"im",
"privacy_message"),
132 'privacyChat' => Option::get(
"im",
"privacy_chat"),
133 'privacyCall' => Option::get(
"im",
"privacy_call"),
134 'privacySearch' => Option::get(
"im",
"privacy_search"),
135 'privacyProfile' => Option::get(
"im",
"privacy_profile"),
136 'callAcceptIncomingVideo' => VideoStrategyType::ALLOW_ALL,
137 'backgroundImageId' => 1,
138 'chatAlignment' =>
'left',
140 'pinnedChatSort' =>
'byCost',
159 $encodedSettings = array_merge($defaultSettings, $encodedSettings);
162 foreach ($encodedSettings as
$name => $value)
165 'GROUP_ID' => $groupId,
171 OptionStateTable::multiplyInsertWithoutDuplicate(
$rows);
185 OptionUserTable::query()
186 ->addSelect(
'GENERAL_GROUP_ID')
191 $groupId = is_array(
$result) ?
$result[
'GENERAL_GROUP_ID'] :
null;
194 return $defaultSettings;
198 OptionStateTable::query()
199 ->setSelect([
'NAME',
'VALUE'])
200 ->where(
'GROUP_ID', $groupId)
201 ->whereLike(
'NAME', static::ENTITY.
'%')
205 foreach (
$query->exec() as $rowSetting)
207 $settings[$rowSetting[
'NAME']] = $rowSetting[
'VALUE'];
212 return $defaultSettings;
217 return array_replace_recursive($defaultSettings,
$settings);
225 $settingName = static::getNotifySettingByType($notifyType);
239 $settingName = static::getNotifySettingByType($notifyType);
240 if ($settingName ===
'')
245 $encodedSettingName = static::encodeName($settingName);
246 $encodedDefaultSettings = static::encodeSettings(static::getDefaultSettings());
248 if (!array_key_exists($encodedSettingName, $encodedDefaultSettings))
256 $filteredUsers = static::filterChunk(
$userList, $settingName);
260 $chunkList = array_chunk(
$userList, static::CHUNK_LENGTH);
261 foreach ($chunkList as $chunk)
263 $filteredUsers = array_merge($filteredUsers, static::filterChunk($chunk, $settingName));
267 return $filteredUsers;
272 $notifySchemas = static::getUserNotifySchemas(
$userList);
273 $filteredUserListWithSimpleScheme = static::filterUsersWithSimpleNotifyScheme($notifySchemas[
'simple'], $settingName);
275 return array_merge($filteredUserListWithSimpleScheme, $notifySchemas[
'expert']);
283 return 'notifySchemeSendSite';
285 return 'notifySchemeSendEmail';
287 return 'notifySchemeSendXmpp';
289 return 'notifySchemeSendPush';
306 $default = static::getDefaultSettings();
307 $notifySchemeValue = $default[
'notifyScheme'];
308 $encodedSettingName = static::encodeName(
'notifyScheme');
311 OptionUserTable::query()
312 ->addSelect(
'USER_ID')
313 ->addSelect(
new ExpressionField(
'NOTIFY_SCHEMA',
"COALESCE(%s, '$notifySchemeValue')", [
'OPTION_STATE.VALUE']))
314 ->registerRuntimeField(
319 Join::on(
'this.USER_ID',
'ref.ID'),
320 [
'join_type' => Join::TYPE_INNER]
323 ->registerRuntimeField(
327 OptionStateTable::class,
328 Join::on(
'this.GENERAL_GROUP_ID',
'ref.GROUP_ID')
329 ->where(
'ref.NAME', $encodedSettingName),
330 [
'join_type' => Join::TYPE_LEFT]
334 ->where(
'USER.ACTIVE',
'Y')
335 ->where(
'USER.IS_REAL_USER',
'Y')
342 foreach (
$query->exec() as $row)
344 if($row[
'NOTIFY_SCHEMA'] ===
'simple')
346 $notifySchemas[
'simple'][] = (int)$row[
'USER_ID'];
348 elseif ($row[
'NOTIFY_SCHEMA'] ===
'expert')
350 $notifySchemas[
'expert'][] = (int)$row[
'USER_ID'];
354 return $notifySchemas;
364 $encodedSettingName = static::encodeName($settingName);
365 $defaultSettingValue = static::getDefaultSettings()[$settingName] ?
'Y' :
'N';
367 OptionUserTable::query()
368 ->addSelect(
'USER_ID')
369 ->registerRuntimeField(
374 Join::on(
'this.USER_ID',
'ref.ID'),
375 [
'join_type' => Join::TYPE_INNER]
378 ->registerRuntimeField(
382 OptionStateTable::class,
383 Join::on(
'this.GENERAL_GROUP_ID',
'ref.GROUP_ID')
384 ->where(
'ref.NAME', $encodedSettingName),
385 [
'join_type' => Join::TYPE_LEFT]
389 ->where(
'USER.ACTIVE',
'Y')
390 ->where(
'USER.IS_REAL_USER',
'Y')
391 ->whereExpr(
"COALESCE(%s, '$defaultSettingValue') = 'Y'", [
'OPTION_STATE.VALUE'])
394 $filteredUserList = [];
395 foreach (
$query->exec() as $row)
397 $filteredUserList[] = (int)$row[
'USER_ID'];
400 return $filteredUserList;
415 OptionStateTable::query()
416 ->setSelect([
'NAME',
'VALUE'])
417 ->where(
'GROUP_ID', $groupId)
418 ->whereLike(
'NAME', static::ENTITY.
'%')
422 foreach (
$query->exec() as $rowSetting)
424 $settings[$rowSetting[
'NAME']] = $rowSetting[
'VALUE'];
429 return $defaultSettings;
442 return array_replace(
$settings, $redefinedSettings);
450 foreach ($defaultSettings as
$name => $value)
464 $result[
'openDesktopFromPanel'] =
false;
489 OptionStateTable::query()
490 ->setSelect([
'NAME',
'VALUE'])
491 ->where(
'GROUP_ID', $groupId)
492 ->whereLike(
'NAME', self::ENTITY.
'%')
495 foreach (
$query->exec() as $row)
497 if (array_key_exists($row[
'NAME'], $encodedSettings))
499 if ($row[
'VALUE'] === $encodedSettings[$row[
'NAME']])
501 unset($encodedSettings[$row[
'NAME']]);
504 OptionStateTable::update(
506 'GROUP_ID' => $groupId,
507 'NAME' => $row[
'NAME']
509 [
'VALUE' => $encodedSettings[$row[
'NAME']]]
511 unset($encodedSettings[$row[
'NAME']]);
516 foreach ($encodedSettings as
$name => $value)
519 'GROUP_ID' => $groupId,
524 if ($addedSettings !== [])
526 OptionStateTable::addMulti($addedSettings,
true);
540 $encodedSettings = [];
543 $encodeName = self::encodeName(
$name);
545 if (mb_strlen($encodeName) > 64 || mb_strlen($value) > 255)
552 $encodedSettings[$encodeName] =
'Y';
556 $encodedSettings[$encodeName] =
'N';
560 $encodedSettings[$encodeName] = $value;
564 return $encodedSettings;
576 $decodedSettings = [];
577 foreach ($rowSettings as
$name => $value)
579 $decodedName = self::decodeName(
$name);
582 $decodedSettings[$decodedName] =
true;
586 $decodedSettings[$decodedName] =
false;
590 $decodedSettings[$decodedName] = $value;
593 if ($decodedName ===
'backgroundImageId')
595 $decodedSettings[$decodedName] = (int)$value;
599 return $decodedSettings;
609 private static function encodeName(
string $name): string
611 return static::ENTITY . static::SEPARATOR .
$name;
621 private static function decodeName(
string $setting): string
623 return str_replace(static::ENTITY . static::SEPARATOR,
'', $setting);
635 $verifiedSettings = [];
640 if (!array_key_exists(
$name , $defaultSettings))
648 $verifiedSettings[
$name] =
649 in_array($value, [
'online',
'dnd',
'away'])
651 : $defaultSettings[
$name]
655 case 'panelPositionHorizontal':
656 $verifiedSettings[
$name] =
657 in_array($value, [
'left',
'center',
'right'])
659 : $defaultSettings[
$name]
663 case 'panelPositionVertical':
664 $verifiedSettings[
$name] =
665 in_array($value, [
'top',
'bottom'])
667 : $defaultSettings[
$name]
672 $verifiedSettings[
$name] =
673 in_array($value, [
'simple',
'expert'])
675 : $defaultSettings[
$name]
679 case 'enableDarkTheme':
680 $verifiedSettings[
$name] =
681 in_array($value, [
'auto',
'light',
'dark'])
683 : $defaultSettings[
$name]
687 case 'privacyMessage':
690 case 'privacySearch':
691 $verifiedSettings[
$name] =
692 in_array($value, [self::PRIVACY_RESULT_ALL, self::PRIVACY_RESULT_CONTACT],
true)
694 : $defaultSettings[
$name]
698 case 'privacyProfile':
699 $verifiedSettings[
$name] =
703 self::PRIVACY_RESULT_ALL,
704 self::PRIVACY_RESULT_CONTACT,
705 self::PRIVACY_RESULT_NOBODY
710 : $defaultSettings[
$name];
713 case 'backgroundImage':
714 $verifiedSettings[
$name] = $value;
717 case 'notifySchemeLevel':
718 $verifiedSettings[
$name] =
719 in_array($value, [
'normal',
'important'])
721 : $defaultSettings[
$name];
725 $status = explode(
',', $value);
740 case 'callAcceptIncomingVideo':
741 $verifiedSettings[
$name] =
742 in_array($value, VideoStrategyType::getList())
744 : $defaultSettings[
$name]
749 $verifiedSettings[
$name] = $value ===
'Y' || $value ===
true;
752 $verifiedSettings[
$name] = !($value ===
'N' || $value ===
false);
754 case 'backgroundImageId':
755 $verifiedSettings[
$name] = (int)$value > 0 ? (
int)$value : 1;
757 case 'chatAlignment':
758 $verifiedSettings[
$name] =
759 in_array($value, [
'left',
'center'])
761 : $defaultSettings[
$name]
764 case 'pinnedChatSort':
765 $verifiedSettings[
$name] =
766 ($value ===
'byDate')
768 : $defaultSettings[
$name]
772 if (array_key_exists(
$name, $defaultSettings))
774 $verifiedSettings[
$name] = is_bool($value) ? $value : $defaultSettings[
$name];
781 return $verifiedSettings;
static getUserPresetFromCache(int $userId)
static createWithUserId(int $userId)
static getNotifySettingByType(string $notifyType)
static filterAllowedUsersBySimpleNotificationSettings(array $userList, string $notifyType)
static updateGroupSettings(int $groupId, array $settings)
const PRIVACY_RESULT_CONTACT
static setSettings(int $groupId, array $settings=[], bool $forInitialize=false)
static getDefaultSettings()
static getGroupSettings(int $groupId)
static getUserSettings(int $userId)
static filterChunk(array $userList, string $settingName)
const PRIVACY_RESULT_NOBODY
static allowedUserBySimpleNotificationSettings(int $userId, string $notifyType)
static encodeSettings(array $settings)
static filterGroupSettingsByDefault(array $settings)
static getRedefinedSettings()
static decodeSettings(array $rowSettings)
static prepareRawGroupSettings(array $settings)
static filterUsersWithSimpleNotifyScheme(array $userList, string $settingName)
static checkingValues(array $settings)
static getUserNotifySchemas(array $userList)
static isDesktopRedirectAvailable()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
IsModuleInstalled($module_id)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"