Documentation

Factory

General methods


Abstract factory class. Reproduces "Abstract factory" design pattern, where each entity type has its own factory.

Implementation of factory for each type returns set of classes, specific for this type.

Factory service is an input point always, when you need to process data, specific for entity type.

Factory instance is retrieved from [link=13976638]service container[/link].

Hereinafter, "type" means "CRM entity type", such as "Lead", "Deal" and etc. "Smart processes" are related to this as well.

Method Description Available from version
abstract public function getEntityTypeId(): int;
Method returns CRM type ID.
public function getEntityName(): string
Method returns string view for CRM type ID.
public function getEntityAbbreviation(): string
Method returns abbreviated string CRM type ID.
public function getEntityDescription(): string
Method returns type language designation.

Function type


Portion of these methods correlates with corresponding methods from [link=13967500]Model\Dynamic\Type[/link].


Method Description Available from version
public function isMultipleAssignedEnabled(): bool
Returns true, when multiple responsible users feature is active. Always returns false; this feature is not completely implemented yet.
public function isCategoriesSupported(): bool
Returns true, when type supports pipelines.
public function isCategoriesEnabled(): bool
Returns true, when type supports pipelines and this feature is active.
public function isStagesSupported(): bool
Returns true, when type supports stages.
public function isStagesEnabled(): bool
Returns true, when type supports stages and this feature is active.
public function isLinkWithProductsEnabled(): bool
Returns true, when type supports linking binding to products.
public function isBeginCloseDatesEnabled(): bool
Returns true, when type has "Start date" and "End date".
public function isClientEnabled(): bool
Returns true, when type has "Customer" field (binding to contacts and company).
public function isCrmTrackingEnabled(): bool
Returns true, when type supports sales intelligence and utm-tags.
public function isMyCompanyEnabled(): bool
Returns true, when type has "My company details" field.
public function isDocumentGenerationEnabled(): bool
Returns true, when type has activated document print feature.
public function isSourceEnabled(): bool
Returns true, when type has "Source" and "Source information" fields enabled.
public function isUseInUserfieldEnabled(): bool
Returns true, when type can be used in the "Bind to CRM items" field type.
public function isRecyclebinEnabled(): bool
Returns true, when recycle bin feature was activated.
public function isAutomationEnabled(): bool
Returns true, when automation rule and trigger feature is activated.
public function isBizProcEnabled(): bool
Returns true, when workflow designer feature is activated.
public function isObserversEnabled(): bool
Returns true, when type has "Observers" field with corresponding feature.
public function isNewRoutingForDetailEnabled(): bool
Returns true, when links to element detail page of this type must be generated as per the same principle as the links to SPAs.
public function isNewRoutingForListEnabled(): bool
Returns true, when links to element list of this type must be generated as per the same principle as the links to SPAs.
public function isNewRoutingForAutomationEnabled(): bool
Returns true, when links to workflow and trigger settings of this type must be generated as per the same principle as the links to SPAs.

Element fields of specific type


Method Description Available from version
public function getFieldsInfo(): array
Method returns description of element fields of specific type as an array, where key - field code, value is description.
This method operation result is compatible with methods from [link=11318804]old API[/link] \CCrmDeal::GetFieldsInfo(), \CCrmLead::GetFieldsInfo() и т.д.
Field description consist of several keys:
  • TITLE - Field name on the current language.
  • TYPE - Field type, possible lists can be viewed in class constants for [link=13986312]Crm\Field[/link].
  • ATTRIBUTES - Array with field attributes, possible lists are located in class \CCrmFieldInfoAttr.
  • CLASS - FQN for descendant class [link=13986312]Crm\Field[/link], implementing a field-specific business logic.
  • CRM_STATUS_TYPE - When field type is crm_status, contains ENTITY_ID column value for the table b_crm_status.
  • SETTINGS - Array with settings for descendant class [link=13986312]Crm\Field[/link].
public function getFieldsMap(): array
Method returns map with "general" field codes and field codes of specific type, if they differ from "general" (more details at [link=13985532]Crm\Item[/link]).
Key - "general" field code and value - field code of specific type.
public function getEntityFieldNameByMap
(string $commonFieldName): string
Method returns field code of specific type by its "general" code.
public function getCommonFieldNameByMap
(string $entityFieldName): string
Method returns "general" field code by specific field code.
public function getFieldCaption(string $commonFieldName): string
Method returns field language name by its "general" code.
If name is not found, returns the field code itself.
public function isFieldExists(string $commonFieldName): bool
Method returns true, when field with "general" code $commonFieldName is available in elements/items of the specific type.
public function getFieldValueCaption
(string $commonFieldName, $fieldValue): string
Method returns string value for the field with "general" code $commonFieldName and value with $fieldValue.
public function getFieldsCollection(): Field\Collection
Method returns [link=13986312]collection of fields[/link] of this specific code.
Includes custom fields, described below.

Type custom fields


Due to set of custom fields being stored in the database, this data is cached inside factory.

In case data about custom fields is updated after receiving factory instance, you need to reset the cache.


Method Description Available from version
public function getUserFieldEntityId(): string
Returns entity ID for custom fields API.
public function clearUserFieldsInfoCache()
Resets data cache for custom fields.
public function getUserFieldsInfo(): array
Returns description for custom fields in the same format as in the method getFieldsInfo().
public function getUserFields(): array
Returns custom fields description of specific type.

Pipelines


Pipeline data is cached inside the factory.


Method Description Available from version
public function getCategories(): array
Returns array with [link=14008946]pipelines[/link] of specific type.
abstract public function createCategory(array $data = []): Category;
Creates [link=14008946]pipeline object[/link] based on the object data.
public function createDefaultCategoryIfNotExist(): Category
Method returns pipeline, if this pipeline exist by default.
When no default pipeline exist, creates this pipeline.
In case failing to create default pipeline, throws exception \Bitrix\Main\InvalidOperationException.
This method is used in location, where pipeline data are mandatory (for example, in the field CATEGORY_ID [link=13967506]table with smart process element[/link]).
public function getDefaultCategory(): ?Category
Returns default pipeline, if available.

Stages


Stage data are cached inside factory.


Method Description Available from version
public function getStagesEntityId
(?int $categoryId = null): ?string
Returns ENTITY_ID [link=13967440]identifier[/link] for table with statuses
When type doesn't support handling of stages, returns null.
public function getStages
(int $categoryId = null): EO_Status_Collection
Returns collection of $categoryId pipeline stages.
If $categoryId is not passed, but type supports pipeline handling, receives the list of pipeline stages by default.
public function purgeStagesCache(): Factor
Clears stage cache.
public function getStage
(string $statusId): ?EO_Status
Returns stage object by string ID $stageId.

Elements


Method Description Available from version
abstract public function getDataClass(): string;
Returns FQN for class table, storing element type.
public function getItemByEntityObject
(EntityObject $object): Item
Returns [link=13985532]element object[/link] by ORM $object.
public function getItems
(array $parameters = []): array
Returns [link=13985532]array with element objects[/link].
Here $parameters - array with structure, fully similar to argument in the method [link=1755489]\\Bitrix\Main\Entity\DataManager::getList()[/link].
public function getItemsFilteredByPermissions
( array $parameters, ?int $userId = null, 
string $operation = UserPermissions::OPERATION_READ ): array
Returns [link=13985532]array with element objects[/link] similar to the method getList, but accounts for user access permission with $userId upon executing the $operation action.
Passes the parameter $userId as is to the method [link=13976638]Service\Container::getUserPermissions()[/link].
public function getItem(int $id): ?Item
Returns [link=13985532]element object[/link] by its $id.
public function getItemsCount
(array $filter = []): int
Returns number of elements by filter $filter.
public function getItemsCountFilteredByPermissions
( array $filter = [], ?int $userId = null, 
string $operation = UserPermissions::OPERATION_READ ): int
Returns number of elements by $filter with account of user access permissions with $userId upon executing action $operation.
Passes the parameter $userId as is in the method [link=13976638]Service\Container::getUserPermissions()[/link].
public function createItem(array $data = []): Item
Creates new [link=13985532]element[/link] with field values from $data.
$data must use "general" keys.
You can pass only values from its own scalar fields. The rest of field types (custom, links) workability is not guaranteed.
public function getItemCategoryId(int $id): ?int
Returns element pipeline ID by its $id.

Updates


Method Description Available from version
public function getAddOperation
(Item $item, Context $context = null): Operation\Add
Returns [link=14005980]operation object[/link] for adding $item with $context.
public function getUpdateOperation
(Item $item, Context $context = null): Operation\Update
Returns [link=14005980]operation object[/link] for updating $item with $context.
public function getDeleteOperation
(Item $item, Context $context = null): Operation\Delete
Returns [link=14005980]operation object[/link] for deleting $item with $context.
public function getConversionOperation
(Item $item, EntityConversionConfig $configs, Context $context = null): 
Operation\Conversion
Returns [link=14005980]operation object[/link] for converting $item with config $configs and context $context.
public function getCopyOperation
(Item $item, Context $context = null): Operation\Copy
Returns [link=14005980]operation object[/link] for copying $item with context $context.
getDependantFieldsMap(): array
Returns set of dependant fields, where key is field code and values if array with field codes, dependant from it.

History of element/item actions


Method Description Available from version
public function getTrackedObject
(Item $itemBeforeSave, Item $item = null): 
TrackedObject
Method returns class object [link=13981068]TrackedObject[/link], used when writing element history using the [link=13980976]history service[/link]. Returns object is configured according to entity type specifics, handled by factory.
Item $itemBeforeSave - element before saving. When it wasn't updated, then it is the current element. Item $item - current element status. When element wasn't updated, this parameter is not used.

UI


Method Description Available from version
public function getEditorAdapter(): EditorAdapter
Method returns configured [link=13980472]adapter service[/link] for editor.

Example


use Bitrix\Crm\Service;

$factory = Service\Container::getInstance()->getFactory(\CCrmOwnerType::Quote);
if ($factory->isStagesEnabled ())
{
    $stages = $factory->getStages();
}
// all elements without access permissions
$allItems = $factory->getItems([]);
// elements with access permissions for reading for current user
$items = $factory->getItemsFilteredByPermissions([]);
© «Bitrix24», 2001-2024
Up