• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/entitymanagefacility.php
  • Класс: Bitrix\Crm\EntityManageFacility
  • Вызов: EntityManageFacility::addLead
public function addLead(array &$fields, $updateSearch = true, $options = array())
{
	$this->clearErrors();

	if (!$this->canAddLead())
	{
		return null;
	}

	$isRCLeadAdded = false;
	if ($this->canAddReturnCustomerLead())
	{
		if ($this->selector->getCompanyId())
		{
			$fields['COMPANY_ID'] = $this->selector->getCompanyId();
			if (!$this->selector->getContactId())
			{
				$userPermissions = \CCrmPerms::getUserPermissions($this->getUserId($fields));
				$fields['CONTACT_IDS'] = array_filter(
					Binding\ContactCompanyTable::getCompanyContactIDs($fields['COMPANY_ID']),
					function ($contactId) use ($userPermissions)
					{
						return \CCrmContact::CheckReadPermission($contactId, $userPermissions);
					}
				);
			}
		}
		if ($this->selector->getContactId())
		{
			$fields['CONTACT_ID'] = $this->selector->getContactId();
		}

		if ($this->selector->getCompanyId() || $this->selector->getContactId())
		{
			$fields['IS_RETURN_CUSTOMER'] = 'Y';
			$isRCLeadAdded = true;
		}
	}
	else
	{
		$fields['IS_RETURN_CUSTOMER'] = 'N';
	}

	$updateClientFields = $fields;
	if (!isset($options['DISABLE_USER_FIELD_CHECK']))
	{
		$options['DISABLE_USER_FIELD_CHECK'] = true;
	}

	// use entity configuration setting when create
	if (!isset($fields['OPENED']) || empty($fields['OPENED']))
	{
		$fields['OPENED'] = Settings\LeadSettings::getCurrent()->getOpenedFlag() ? 'Y' : 'N';
	}

	$lead = new \CCrmLead(false);
	$leadId = $lead->add($fields, $updateSearch, $options);
	if (!$leadId)
	{
		$this->errors[] = $lead->LAST_ERROR;
		return $leadId;
	}

	if ($isRCLeadAdded)
	{
		$this->updateClientFields($fields, true, $updateSearch, $options);
	}

	$this->traceEntity(\CCrmOwnerType::Lead, $leadId);

	return $leadId;
}