CCrmTimelineBindingRestProxy::bind

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmTimelineBindingRestProxy
  4. bind
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmTimelineBindingRestProxy
  • Вызов: CCrmTimelineBindingRestProxy::bind
protected function bind(array $fields = [])
{
	if(!$this->checkEntityID((int)$fields['OWNER_ID']))
	{
		throw new RestException('OWNER_ID is not defined or invalid.');
	}

	if(!$this->checkEntityID((int)$fields['ENTITY_ID']))
	{
		throw new RestException('ENTITY_ID is not defined or invalid.');
	}

	$entityTypeId = null;
	if (isset($fields['ENTITY_TYPE']))
	{
		$entityTypeName = mb_strtoupper($fields['ENTITY_TYPE']);
		$entityTypeId = \CCrmOwnerType::ResolveID($entityTypeName);
	}

	if (!\CCrmOwnerType::IsEntity($entityTypeId))
	{
		throw new RestException('ENTITY_TYPE is not defined or invalid.');
	}

	if (!\Bitrix\Crm\Security\EntityAuthorization::checkUpdatePermission($entityTypeId, (int)$fields['ENTITY_ID']))
	{
		$errors[] = 'Access denied.';
		return false;
	}

	try
	{
		\Bitrix\Crm\Timeline\Entity\TimelineBindingTable::upsert([
			'OWNER_ID' => (int)$fields['OWNER_ID'],
			'ENTITY_TYPE_ID' => $entityTypeId,
			'ENTITY_ID' => (int)$fields['ENTITY_ID']
		]);
	}
	catch(Main\SystemException $ex)
	{
		$errors[] = $ex->getMessage();
		return false;
	}

	return true;
}

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