CCrmEntityBindingProxy::deleteItems

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmEntityBindingProxy
  4. deleteItems
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmEntityBindingProxy
  • Вызов: CCrmEntityBindingProxy::deleteItems
public function deleteItems($ownerEntityID)
{
	$ownerEntityID = (int)$ownerEntityID;
	if($ownerEntityID <= 0)
	{
		throw new RestException('The parameter ownerEntityID is invalid or not defined.');
	}

	$userPermissions = CCrmPerms::GetCurrentUserPermissions();
	if(
		$this->ownerEntityTypeID === CCrmOwnerType::Deal
		&& $this->entityTypeID === CCrmOwnerType::Contact
	)
	{
		$categoryID = CCrmDeal::GetCategoryID($ownerEntityID);
		if($categoryID < 0)
		{
			throw new RestException(
				!CCrmDeal::CheckReadPermission(0, $userPermissions) ? 'Access denied' : 'Not found'
			);
		}
		elseif(!CCrmDeal::CheckReadPermission($ownerEntityID, $userPermissions, $categoryID))
		{
			throw new AccessException();
		}

		DealContactTable::unbindAllContacts($ownerEntityID);

		return true;
	}
	elseif(
		$this->ownerEntityTypeID === CCrmOwnerType::Lead
		&& $this->entityTypeID === CCrmOwnerType::Contact
	)
	{
		if(!CCrmLead::CheckReadPermission($ownerEntityID, $userPermissions))
		{
			throw new AccessException();
		}

		LeadContactTable::unbindAllContacts($ownerEntityID);

		return true;
	}
	elseif(
		$this->ownerEntityTypeID === CCrmOwnerType::Quote
		&& $this->entityTypeID === CCrmOwnerType::Contact
	)
	{
		if(!CCrmQuote::CheckReadPermission($ownerEntityID, $userPermissions))
		{
			throw new AccessException();
		}

		QuoteContactTable::unbindAllContacts($ownerEntityID);
		return true;
	}
	elseif(
		$this->ownerEntityTypeID === CCrmOwnerType::Contact
		&& $this->entityTypeID === CCrmOwnerType::Company
	)
	{
		if(!CCrmContact::CheckReadPermission($ownerEntityID, $userPermissions))
		{
			throw new AccessException();
		}

		ContactCompanyTable::unbindAllCompanies($ownerEntityID);
		return true;
	}
	elseif(
		$this->ownerEntityTypeID === CCrmOwnerType::Company
		&& $this->entityTypeID === CCrmOwnerType::Contact
	)
	{
		if(!CCrmCompany::CheckReadPermission($ownerEntityID, $userPermissions))
		{
			throw new AccessException();
		}

		ContactCompanyTable::unbindAllContacts($ownerEntityID);
		return true;
	}

	$ownerEntityTypeName = CCrmOwnerType::ResolveName($this->ownerEntityTypeID);
	$entityTypeName = CCrmOwnerType::ResolveName($this->entityTypeID);

	throw new RestException("The binding type '{$ownerEntityTypeName} - {$entityTypeName}' is not supported in current context.");
}

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