• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/Configuration/Notification.php
  • Класс: BitrixImConfigurationNotification
  • Вызов: Notification::isAllowed
public function isAllowed(int $userId, string $type): bool
{
	if (!General::allowedUserBySimpleNotificationSettings($userId, $type))
	{
		return false;
	}

	$encodedSetting = self::encodeName($this->module, $this->name, $type);

	$defaultSettings = self::getDefaultSettings();

	$defaultSettings = self::encodeSettings($defaultSettings);

	if (!array_key_exists($encodedSetting, $defaultSettings))
	{
		$encodedSetting = self::encodeName('im', 'default', $type);
	}

	$value = $defaultSettings[$encodedSetting] === 'Y' ? 'Y' : 'N';

	$result =
		OptionUserTable::query()
			->addSelect('USER_ID')
			->registerRuntimeField(
				'USER',
				new Reference(
					'USER',
					UserTable::class,
					Join::on('this.USER_ID', 'ref.ID'),
					['join_type' => Join::TYPE_INNER]
				)
			)
			->registerRuntimeField(
				'OPTION_STATE',
				new Reference(
					'OPTION_STATE',
					OptionStateTable::class,
					Join::on('this.NOTIFY_GROUP_ID', 'ref.GROUP_ID')
						->where('ref.NAME', $encodedSetting),
					['join_type' => Join::TYPE_LEFT]
				)
			)
			->whereExpr("IFNULL(%s, '$value') = 'Y'", ['OPTION_STATE.VALUE'])
			->where('USER_ID', $userId)
			->where('USER.ACTIVE', 'Y')
			->where('USER.IS_REAL_USER', 'Y')
			->fetch()
	;

	$result = $result !== false;

	if ($type !== self::PUSH)
	{
		return $result;
	}
	//checked push

	if ($result)
	{
		$query =
			PushTable::query()
			->addSelect('ID')
			->where('USER_ID', $userId)
			->setLimit(1)
		;
		$pushId = $query->fetch();

		return $pushId !== false;
	}

	return false;
}