• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_settings.php
  • Класс: CIMSettings
  • Вызов: CIMSettings::SetSetting
static function SetSetting($type, $value, $userId = false)
{
	if (!in_array($type, [self::SETTINGS, self::NOTIFY], true))
	{
		return false;
	}

	global $USER_FIELD_MANAGER;

	$userId = $userId === false ? null : $userId;
	$userId = Common::getUserId($userId);
	if (!$userId)
	{
		return null;
	}

	if (Manager::isSettingsMigrated() || Manager::isUserMigrated($userId))
	{
		$newFormatSettings = [];
		if ($type === self::NOTIFY)
		{
			$newFormatSettings = self::convertNotifySettingsToNewFormat($value, false);
		}
		if ($type === self::SETTINGS)
		{
			$type = 'general';
			$newFormatSettings = $value;
		}

		return Manager::setUserSetting($userId, $type, $newFormatSettings)->isSuccess();
	}

	$arSettings = CUserOptions::GetOption('im', $type, [], $userId);
	foreach ($value as $key => $val)
	{
		$arSettings[$key] = $val;
	}

	if (isset($value[self::STATUS]))
	{
		CIMStatus::Set($userId, ['STATUS' => $value[self::STATUS]]);
	}
	if (isset($value['openDesktopFromPanel']) && CModule::IncludeModule('pull'))
	{
		Event::add(
			$userId,
			[
				'module_id' => 'im',
				'command' => 'settingsUpdate',
				'expiry' => 5,
				'params' => [
					'openDesktopFromPanel' => $value['openDesktopFromPanel'],
				],
				'extra' => Common::getPullExtra()
			]
		);
	}

	$arDefault = self::GetDefaultSettings($type);
	foreach ($arSettings as $key => $val)
	{
		if (isset($arDefault[$key]) && $arDefault[$key] == $val)
		{
			if ($key === self::PRIVACY_SEARCH)
			{
				$USER_FIELD_MANAGER->Update("USER", $userId, ['UF_IM_SEARCH' => '']);
			}
			unset($value[$key]);
		}
	}
	CUserOptions::SetOption('im', $type, $arSettings, false, $userId);
	if (isset($value[self::PRIVACY_SEARCH]))
	{
		$USER_FIELD_MANAGER->Update("USER", $userId, ['UF_IM_SEARCH' => $value[self::PRIVACY_SEARCH]]);
	}

	return true;
}