• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/subscription.php
  • Класс: Bitrix\Sender\Subscription
  • Вызов: Subscription::add
static function add($code,  array $mailingIdList)
{
	$contactId = null;

	$typeId = Recipient\Type::detect($code);
	$code = Recipient\Normalizer::normalize($code, $typeId);
	$contact = ContactTable::getRow([
		'select' => ['ID'],
		'filter' => [
			'=CODE' => $code,
			'=TYPE_ID' => $typeId,
		]
	]);
	if($contact)
	{
		$contactId = $contact['ID'];
	}
	else
	{
		$contactAddDb = ContactTable::add(['TYPE_ID' => $typeId, 'CODE' => $code]);
		if($contactAddDb->isSuccess())
		{
			$contactId = $contactAddDb->getId();
		}
	}

	if(!empty($contactId))
	{
		foreach ($mailingIdList as $mailingId)
		{
			MailingSubscriptionTable::addSubscription(array(
				'MAILING_ID' => $mailingId, 'CONTACT_ID' => $contactId
			));
		}
	}

	return $contactId;
}