23 if (is_array(self::$types))
28 if (!\
Bitrix\Main\Loader::includeModule(
'im'))
33 $notifySchema = \CIMNotifySchema::GetNotifySchema();
36 foreach ($notifySchema as $moduleId => $module)
38 if ($module[
'NAME'] ==
'')
40 $info = \CModule::CreateModuleObject($moduleId);
41 $name= $info->MODULE_NAME;
45 $name = $module[
'NAME'];
49 foreach ($module[
'NOTIFY'] as $notifyType => $notifyConfig)
51 if (!$notifyConfig[
'PUSH'] && $notifyConfig[
'DISABLED'][
'PUSH'])
55 $types[$notifyType] = Array(
56 'NAME' => $notifyConfig[
'NAME'],
57 'TYPE' => $notifyType,
58 'DISABLED' => (
bool)$notifyConfig[
'DISABLED'][
'PUSH'],
59 'DEFAULT' => (
bool)$notifyConfig[
'PUSH'],
67 $result[$moduleId] = Array(
69 'MODULE_ID' => $moduleId,
74 self::$types = $result;
81 if (!\
Bitrix\Main\Loader::includeModule(
'im'))
86 if (is_null($userId) && is_object(
$GLOBALS[
'USER']))
91 $userId = intval($userId);
97 if (isset(self::$config[$userId]))
99 return self::$config[$userId];
102 $pushDisabled = !\Bitrix\Pull\Push::getStatus($userId);
104 $userOptions = \CIMSettings::Get($userId)[\CIMSettings::NOTIFY] ?? [];
107 foreach ($userOptions as $optionId => $optionValue)
109 list($clientId, $moduleId, $type) = explode(
'|', $optionId);
110 if ($clientId != \CIMSettings::CLIENT_PUSH)
115 $result[$moduleId][$type] = (bool)$optionValue;
118 $notifySchema = \CIMNotifySchema::GetNotifySchema();
120 foreach ($notifySchema as $moduleId => $module)
122 foreach ($module[
'NOTIFY'] as $notifyType => $notifyConfig)
126 $result[$moduleId][$notifyType] =
false;
130 if (!$notifyConfig[
'PUSH'] && $notifyConfig[
'DISABLED'][
'PUSH'])
135 if (!isset($result[$moduleId][$notifyType]) || $notifyConfig[
'DISABLED'][
'PUSH'])
137 $result[$moduleId][$notifyType] = (bool)$notifyConfig[
'PUSH'];
142 self::$config[$userId] = $result;
147 public static function setConfig($config, $userId =
null)
149 if (!\
Bitrix\Main\Loader::includeModule(
'im'))
159 if (is_null($userId) && is_object(
$GLOBALS[
'USER']))
161 $userId =
$GLOBALS[
'USER']->getId();
163 $userId = intval($userId);
169 $types = self::getTypes();
170 $userConfig = self::getConfig($userId);
171 $userOptions = \CIMSettings::Get($userId)[\CIMSettings::NOTIFY] ?? [];
174 foreach (
$types as $moduleId => $module)
176 foreach ($module[
'TYPES'] as $typeId => $type)
178 if (isset(
$config[$moduleId][$typeId]))
181 $userConfig[$moduleId][$typeId] = (bool)
$config[$moduleId][$typeId];
183 if ($type[
'DEFAULT'] == $userConfig[$moduleId][$typeId])
185 unset($userOptions[
'push|'.$moduleId.
'|'.$typeId]);
189 $userOptions[
'push|'.$moduleId.
'|'.$typeId] = $userConfig[$moduleId][$typeId];
196 \CIMSettings::Set(\CIMSettings::NOTIFY, $userOptions, $userId);
197 \CIMSettings::ClearCache($userId);
198 unset(self::$config[$userId]);