• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Settings/UserConfiguration.php
  • Класс: BitrixImV2SettingsUserConfiguration
  • Вызов: UserConfiguration::load
public function load(int $userId): Result
{
	$this->userId = $userId;

	$result = new Result();
	$cache = CacheManager::getUserCache($userId);
	$bindings = $cache->getValue();
	if (!empty($bindings))
	{
		$this->generalPreset = Preset::getInstance($bindings[CacheManager::GENERAL_PRESET]);
		$this->notifyPreset = Preset::getInstance($bindings[CacheManager::NOTIFY_PRESET]);

		return $result->setResult(true);
	}

	$query =
		OptionUserTable::query()
			->addSelect('NOTIFY_GROUP_ID', CacheManager::NOTIFY_PRESET)
			->addSelect('GENERAL_GROUP_ID', CacheManager::GENERAL_PRESET)
			->where('USER_ID', $userId)
			->setLimit(1)
	;

	$bindings = $query->fetch();
	if ($bindings === false)
	{
		$presetId = Configuration::restoreBindings($userId);

		$bindings = [
			CacheManager::GENERAL_PRESET => $presetId,
			CacheManager::NOTIFY_PRESET => $presetId,
		];
	}

	$this->generalPreset = Preset::getInstance($bindings[CacheManager::GENERAL_PRESET]);
	$this->notifyPreset = Preset::getInstance($bindings[CacheManager::NOTIFY_PRESET]);

	$cache->setValue([
		CacheManager::NOTIFY_PRESET => $this->notifyPreset->getId(),
		CacheManager::GENERAL_PRESET => $this->generalPreset->getId(),
	]);

	return $result->setResult(true);
}