Documentation

RelationManager

RelationManager - is a service object, retrieved via [link=13976638]\Bitrix\Crm\Service\Container[/link]. It's used for customer code and bindings API communication. Object allows to get information about existing binding types, find bound items or create new bindings or binding types.

Creating and editing binding types

Binding types can be have two types — [link=13963826]standard and custom[/link]. Bindings API allows handling both of them. However, customer code can create, edit and delete only custom bindings. There are existing methods for these operations with corresponding names:
RelationManager::bindTypes,
RelationManager::updateTypesBinding,
RelationManager::unbindTypes).

Upon execution all these methods return the object \Bitrix\Main\Result. If in-progress errors occur, they are stored inside as objects \Bitrix\Main\Error. Majority of errors have its code as a constant RelationManager::ERROR_CODE_*, used to determine what's went wrong.

You can check for existing binding between entities via the method RelationManager::areTypesBound. It returns true in case of both standard and custom binding types.

getAvailableForParentBindingEntityTypes

RelationManager::getAvailableForParentBindingEntityTypes(
   ?int $currentEntityId = null
): array[]

Method allows getting array of all entity types that can be parent for passed entity type. When passing null, it returns all entities that can be parent entities.

Returned array can have the following structure:

$result = [
	// entityTypeId
	2 => [
		'entityTypeId' => 2,
		'title' => 'Deal',
	],
	7 => [
		'entityTypeId' => 7,
		'title' => 'Quote',
	],
];

getAvailableForChildBindingEntityTypes

RelationManager::getAvailableForChildBindingEntityTypes(
   ?int $currentEntityId = null
): array[]

Method is similar to the previous one. It returns array of all entity types that can be descendants of current type or descendants in general.

Getting binding types

Method Description Available from version
RelationManager::getRelation(
   RelationIdentifier $identifier
): ?Relation
Method returns specific binding type, if it exists.
RelationManager::getRelations(
   int $entityTypeId
): Relation\Collection
Method returns collection of all binding types with $entityTypeId (not important if its parent or descendant).
RelationManager::getParentRelations(
   int $childEntityTypeId
): Relation\Collection
Method returns collection all binding types, with $childEntityTypeId mentioned as descendant entity.
RelationManager::getChildRelations(
   int $parentEntityTypeId
): Relation\Collection
Method returns collection of all binding types with $parentEntityTypeId mentioned as parent entity.

Creating and deleting entities

The method RelationManager::bindItems can bind two items. The method RelationManager::unbindItems can delete this binding.

Similar to the binding types editing method, these methods return the object \Bitrix\Main\Result that stores occurring errors. The majority of them have the code as a constant RelationManager::ERROR_CODE_*.

You can check if items have bindings via the method RelationManager::areItemsBound.

Getting items with bindings

Method Description Available from version
RelationManager::getElements(
   ItemIdentifier $identifier
): ItemIdentifier[]
Returns all items, bound with passed item.
RelationManager::getParentElements(
   ItemIdentifier $child
): ItemIdentifier[]
Method returns all parent items bound with passed item.
RelationManager::getChildElements(
   ItemIdentifier $parent
): ItemIdentifier[]
Method returns all parent items with bindings to passed item.

© «Bitrix24», 2001-2024
Up