Binding::addAction

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Binding
  4. addAction
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/controller/activity/binding.php
  • Класс: Bitrix\Crm\Controller\Activity\Binding
  • Вызов: Binding::addAction
public function addAction(int $activityId, int $entityTypeId, int $entityId): ?bool
{
	if (!$this->doesActivityExist($activityId))
	{
		return null;
	}

	if (!$this->canEdit($entityTypeId, $entityId))
	{
		$this->addError(\Bitrix\Crm\Controller\ErrorCode::getAccessDeniedError());

		return null;
	}
	$bindings = $this->getExistingBindings($activityId);
	if (is_null($bindings))
	{
		return null;
	}

	foreach ($bindings as $binding)
	{
		if (
			(int)$binding['OWNER_TYPE_ID'] === $entityTypeId
			&& (int)$binding['OWNER_ID'] === $entityId
		)
		{
			$this->addError(new Error(
				Loc::getMessage('CRM_ACTIVITY_BINDING_ALREADY_BOUND_ERROR'),
				'ACTIVITY_IS_ALREADY_BOUND'
			));

			return null;
		}
	}
	$bindings[] = [
		'OWNER_TYPE_ID' => $entityTypeId,
		'OWNER_ID' => $entityId,
	];

	return $this->updateBindings($activityId, $bindings);
}

Добавить комментарий