3namespace Bitrix\Im\Configuration;
5use Bitrix\Im\Model\OptionStateTable;
6use Bitrix\Im\Model\OptionUserTable;
7use Bitrix\Main\ArgumentException;
8use Bitrix\Main\Db\SqlQueryException;
9use Bitrix\Main\EventManager;
10use Bitrix\Main\ObjectPropertyException;
11use Bitrix\Main\ORM\Fields\Relations\Reference;
12use Bitrix\Main\ORM\Query\Join;
13use Bitrix\Main\SystemException;
14use Bitrix\Main\UserTable;
15use Bitrix\Pull\Model\PushTable;
19 public const SITE =
'site';
20 public const MAIL =
'mail';
21 public const XMPP =
'xmpp';
22 public const PUSH =
'push';
34 private static $types = [
47 $this->module = $module;
56 $this->module = $module;
62 public function setName(
string $name): void
79 $encodedSetting = self::encodeName($this->module, $this->name,
$type);
87 $encodedSetting = self::encodeName(
'im',
'default',
$type);
93 OptionUserTable::query()
94 ->addSelect(
'USER_ID')
95 ->registerRuntimeField(
100 Join::on(
'this.USER_ID',
'ref.ID'),
101 [
'join_type' => Join::TYPE_INNER]
104 ->registerRuntimeField(
108 OptionStateTable::class,
109 Join::on(
'this.NOTIFY_GROUP_ID',
'ref.GROUP_ID')
110 ->where(
'ref.NAME', $encodedSetting),
111 [
'join_type' => Join::TYPE_LEFT]
114 ->whereExpr(
"COALESCE(%s, '$value') = 'Y'", [
'OPTION_STATE.VALUE'])
116 ->where(
'USER.ACTIVE',
'Y')
117 ->where(
'USER.IS_REAL_USER',
'Y')
123 if (
$type !== self::PUSH)
137 $pushId =
$query->fetch();
139 return $pushId !==
false;
165 $encodedSetting = self::encodeName($this->module, $this->name,
$type);
173 $encodedSetting = self::encodeName(
'im',
'default',
$type);
181 $filteredUsers = $this->filterChunk(
$userList, $encodedSetting, $value);
185 $chunkList = array_chunk(
$userList, static::CHUNK_LENGTH);
186 foreach ($chunkList as $chunk)
188 $filteredUsers = array_merge($filteredUsers, $this->filterChunk($chunk, $encodedSetting, $value));
192 if (
$type !== self::PUSH)
194 return $filteredUsers;
198 if (empty($filteredUsers))
200 return $filteredUsers;
203 $rowFilteredPushUsers =
205 ->addSelect(
'USER_ID')
206 ->whereIn(
'USER_ID', $filteredUsers)
210 foreach ($rowFilteredPushUsers->exec() as
$user)
212 $filteredUsers[] = (int)
$user[
'USER_ID'];
215 return array_unique($filteredUsers);
218 private function filterChunk(
array $userListChunk, $encodedSettingName, $value):
array
221 OptionUserTable::query()
222 ->addSelect(
'USER_ID')
223 ->registerRuntimeField(
228 Join::on(
'this.USER_ID',
'ref.ID'),
229 [
'join_type' => Join::TYPE_INNER]
232 ->registerRuntimeField(
236 OptionStateTable::class,
237 Join::on(
'this.NOTIFY_GROUP_ID',
'ref.GROUP_ID')
238 ->where(
'ref.NAME', $encodedSettingName),
239 [
'join_type' => Join::TYPE_LEFT]
242 ->whereExpr(
"COALESCE(%s, '$value') = 'Y'", [
'OPTION_STATE.VALUE'])
243 ->whereIn(
'USER_ID', $userListChunk)
244 ->where(
'USER.ACTIVE',
'Y')
245 ->where(
'USER.IS_REAL_USER',
'Y');
250 $filteredUsers[] = (int)
$user[
'USER_ID'];
253 return $filteredUsers;
263 if (isset(
$defaultSettings[$this->module][
'NOTIFY'][$this->name][
'DISABLED'][mb_strtoupper($feature)]))
283 $encodedName = self::encodeName($this->module, $this->name,
$type);
294 !empty($cachedPreset)
301 if (!$notifySettings)
308 if (is_null($notifySettings[$encodedName]))
313 return $notifySettings[$encodedName] ===
'Y';
317 OptionStateTable::query()
319 ->registerRuntimeField(
323 OptionUserTable::class,
324 Join::on(
'this.GROUP_ID',
'ref.NOTIFY_GROUP_ID'),
325 [
'join_type' => Join::TYPE_INNER]
328 ->where(
'OPTION_USER.USER_ID',
$userId)
329 ->where(
'NAME', $encodedName)
332 $value =
$query->fetch()[
'VALUE'];
339 return $value ===
'Y';
349 if (!empty(self::$defaultSettings))
351 return self::$defaultSettings;
365 self::$defaultSettings[
$moduleId][
'NAME'] =
366 isset($notifyType[
'NOTIFY'], $notifyType[
'NAME'])
367 ? $notifyType[
'NAME']
370 $notify = $notifyType[
'NOTIFY'] ?? $notifyType;
372 foreach ($notify as $notifyEvent =>
$config)
378 $config[
'DISABLED'][] = self::PUSH;
381 $disabled[
'SITE'] = in_array(self::SITE,
$config[
'DISABLED'],
true);
382 $disabled[
'MAIL'] = in_array(self::MAIL,
$config[
'DISABLED'],
true);
383 $disabled[
'XMPP'] = in_array(self::XMPP,
$config[
'DISABLED'],
true);
384 $disabled[
'PUSH'] = in_array(self::PUSH,
$config[
'DISABLED'],
true);
386 $config[
'DISABLED'] = $disabled;
401 return self::$defaultSettings;
408 $send[
'SITE'] = $generalSettings[
'notifySchemeSendSite'] ?? $defaultGeneralSettings[
'notifySchemeSendSite'];
409 $send[
'MAIL'] = $generalSettings[
'notifySchemeSendEmail'] ?? $defaultGeneralSettings[
'notifySchemeSendEmail'];
410 $send[
'XMPP'] = $generalSettings[
'notifySchemeSendXmpp'] ?? $defaultGeneralSettings[
'notifySchemeSendXmpp'];
411 $send[
'PUSH'] = $generalSettings[
'notifySchemeSendPush'] ?? $defaultGeneralSettings[
'notifySchemeSendPush'];
415 foreach ($notifySettings as
$moduleId => $moduleSchema)
417 foreach ($moduleSchema[
'NOTIFY'] as $eventName => $eventSchema)
419 foreach ([
'SITE',
'MAIL',
'XMPP',
'PUSH'] as
$type)
421 if ($eventSchema[
'DISABLED'][
$type])
429 : $eventSchema[
$type]
435 return $notifySettings;
450 OptionStateTable::query()
451 ->setSelect([
'NAME',
'VALUE'])
452 ->registerRuntimeField(
456 OptionUserTable::class,
457 Join::on(
'this.GROUP_ID',
'ref.NOTIFY_GROUP_ID'),
458 [
'join_type' => Join::TYPE_INNER]
461 ->where(
'OPTION_USER_TABLE.USER_ID',
$userId)
462 ->whereLike(
'NAME', static::ENTITY.
'%')
466 foreach (
$query->exec() as $rowSetting)
468 $rowSettings[] = $rowSetting;
471 if (empty($rowSettings))
476 $decodedSettings = static::decodeSettings($rowSettings);
493 OptionStateTable::query()
494 ->setSelect([
'NAME',
'VALUE'])
495 ->where(
'GROUP_ID', $groupId)
496 ->whereLike(
'NAME', static::ENTITY .
'%')
500 foreach (
$query->exec() as $rowSetting)
524 foreach ($defaultModuleSettings[
'NOTIFY'] ?? [] as $notifyKey => $notifyValue)
526 $defaultModuleSettings[
'NOTIFY'][$notifyKey] =
527 array_replace_recursive($notifyValue, $moduleSettings[$notifyKey] ?? [])
553 OptionStateTable::query()
554 ->setSelect([
'NAME',
'VALUE'])
555 ->where(
'GROUP_ID', $groupId)
556 ->whereLike(
'NAME', self::ENTITY .
'%')
559 $enabledSettings = [];
560 $disabledSettings = [];
561 foreach (
$query->exec() as $row)
563 if (array_key_exists($row[
'NAME'], $encodedSettings))
565 if ($row[
'VALUE'] === $encodedSettings[$row[
'NAME']])
567 unset($encodedSettings[$row[
'NAME']]);
570 if ($encodedSettings[$row[
'NAME']] ===
'Y')
572 $enabledSettings[] = [
573 'GROUP_ID' => $groupId,
574 'NAME' => $row[
'NAME']
576 unset($encodedSettings[$row[
'NAME']]);
579 if ($encodedSettings[$row[
'NAME']] ===
'N')
581 $disabledSettings[] = [
582 'GROUP_ID' => $groupId,
583 'NAME' => $row[
'NAME']
585 unset($encodedSettings[$row[
'NAME']]);
590 foreach ($encodedSettings as $name => $value)
598 'GROUP_ID' => $groupId,
603 if (!empty($addedSettings))
605 OptionStateTable::addMulti($addedSettings,
true);
607 if (!empty($enabledSettings))
609 OptionStateTable::updateMulti($enabledSettings, [
'VALUE' =>
'Y'],
true);
611 if (!empty($disabledSettings))
613 OptionStateTable::updateMulti($disabledSettings, [
'VALUE' =>
'N'],
true);
631 $selectedSettings = [];
633 OptionStateTable::query()
634 ->setSelect([
'NAME',
'VALUE'])
635 ->where(
'GROUP_ID', $groupId)
636 ->whereLike(
'NAME', self::ENTITY .
'%')
638 foreach (
$query->exec() as $row)
640 $selectedSettings[$row[
'NAME']] = $row[
'VALUE'];
647 foreach ($encodedSettings as $name => $value)
649 if (!array_key_exists($name,
$defaultSettings) || isset($selectedSettings[$name]))
655 'GROUP_ID' => $groupId,
661 OptionStateTable::multiplyInsertWithoutDuplicate(
$rows);
670 $names[
$moduleId][
'NAME'] = $notifyTypes[
'NAME'];
671 if ($notifyTypes[
'NAME'] ==
'')
673 $moduleObject = \CModule::CreateModuleObject(
$moduleId);
674 $names[
$moduleId][
'NAME'] = $moduleObject->MODULE_NAME;
676 foreach ($notifyTypes[
'NOTIFY'] as $eventId =>
$event)
694 $decodedSettings = [];
696 foreach ($rowSettings as $rowSetting)
698 if (!$rowSetting[
'NAME'])
703 $setting = self::decodeName($rowSetting[
'NAME']);
705 if ($setting ===
null)
709 $module = $setting[self::MODULE];
710 $name = $setting[self::NAME];
712 if(!in_array((
int)$setting[self::TYPE], [1,2,3,4]))
717 $type = self::getType((
int)$setting[self::TYPE]);
719 $decodedSettings[$module][
'NOTIFY'][$name][
$type] = $rowSetting[
'VALUE'] ===
'Y';
722 return $decodedSettings;
735 $encodedSettings = [];
737 foreach (
$settings as $moduleName => $notifies)
739 if (!is_array($notifies))
744 foreach ($notifies as $notify)
746 if (!is_array($notify))
751 foreach ($notify as $notifyName => $types)
753 foreach ($types as
$type => $value)
755 $setting = self::encodeName($moduleName, $notifyName,
$type);
757 if (!$setting || mb_strlen($setting) > 64)
762 $encodedSettings[$setting] = $value ?
'Y' :
'N';
769 return $encodedSettings;
779 private static function decodeName(
string $setting): ?
array
781 $row = explode(static::SEPARATOR, $setting);
783 if (!array_key_exists(self::MODULE, $row)
784 || !array_key_exists(self::NAME, $row)
785 || !array_key_exists(self::TYPE, $row)
803 private static function encodeName(
string $module,
string $name,
string $type): ?string
810 $postfix = self::getPostfix(
$type);
812 if ($postfix ===
null)
833 private static function getPostfix(
string $type): ?int
835 return self::$types[mb_strtoupper(
$type)] ??
null;
843 private static function getType(
int $postfix): ?string
845 $arr = array_flip(self::$types);
847 return $arr[$postfix];
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getUserPresetFromCache(int $userId)
static filterAllowedUsersBySimpleNotificationSettings(array $userList, string $notifyType)
static getDefaultSettings()
static allowedUserBySimpleNotificationSettings(int $userId, string $notifyType)
static updateGroupSettings(int $groupId, array $settings)
checkDisableFeature(string $feature)
isAllowed(int $userId, string $type)
static setSettings(int $groupId, array $settings=[], bool $forInitialize=false)
static getDefaultSettings()
getDefaultFeature(string $feature)
filterAllowedUsers(array $userList, string $type)
static getGroupSettings(int $groupId)
__construct(string $module, string $name)
static getUserSettings(int $userId)
static encodeSettings(array $settings)
static getSimpleNotifySettings(array $generalSettings)
static filterGroupSettingsByDefault(array $settings)
getValue(int $userId, string $type)
static decodeSettings(array $rowSettings)
setModule(string $module)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
ExecuteModuleEventEx($arEvent, $arParams=[])
</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."%"