CCrmTimelineBindingRestProxy::unbind

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmTimelineBindingRestProxy
  4. unbind
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmTimelineBindingRestProxy
  • Вызов: CCrmTimelineBindingRestProxy::unbind
protected function unbind(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;
	}

	$resultBind = Bitrix\Crm\Timeline\Entity\TimelineBindingTable::getList([
		'filter' => [
			'OWNER_ID' => (int)$fields['OWNER_ID'],
			'ENTITY_TYPE_ID' => $entityTypeId,
			'ENTITY_ID' => (int)$fields['ENTITY_ID']
		],
	]);

	if (!$resultBind->fetch())
	{
		throw new RestException('Not found.');
	}

	try
	{
		\Bitrix\Crm\Timeline\Entity\TimelineBindingTable::delete(array(
			'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;
}

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