- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/webform/form.php
- Класс: Bitrix\Crm\WebForm\Form
- Вызов: Form::getCounters
static function getCounters($formId, $schemeId = null)
{
$result = array(
'ENTITY' => array(),
'COMMON' => array()
);
$entityList = Entity::getList();
$scheme = Entity::getSchemes($schemeId);
if($scheme)
{
foreach($entityList as $entityName => $entityCaption)
{
if(!in_array($entityName, $scheme['ENTITIES']))
{
unset($entityList[$entityName]);
}
}
}
$entityNameMap = [
\CCrmOwnerType::InvoiceName => \CCrmOwnerType::OrderName
];
$entityFieldMap = Internals\FormCounterTable::getEntityFieldsMap();
$counters = Internals\FormCounterTable::getByFormId($formId);
foreach($counters as $counter => $value)
{
if(isset($entityFieldMap[$counter]))
{
$entityName = $entityFieldMap[$counter];
$isDynamic = $entityName === 'DYNAMIC';
if ($isDynamic && ($scheme['DYNAMIC'] ?? false))
{
$entityName = \CCrmOwnerType::resolveName($scheme['MAIN_ENTITY']) ?: $entityName;
}
if(!isset($entityList[$entityName]))
{
continue;
}
$entityCaption = $entityList[$entityName];
$entityTypeId = \CCrmOwnerType::resolveID($entityName);
$entityName = $entityNameMap[$entityName] ?? $entityName;
$link = $isDynamic
? "/crm/type/{$entityTypeId}/list/category/0/"
: Option::get(
'crm',
'path_to_'.mb_strtolower($entityNameMap[$entityName] ?? $entityName) . '_list',
''
)
;
$link .= mb_strpos($link, '?') === false ? '?' : '&';
$link .= 'WEBFORM_ID[]=' . $formId . '&apply_filter=Y';
if (!$link || $entityName === \CCrmOwnerType::OrderName)
{
$link = null;
}
$result['ENTITY'][] = array(
'ENTITY_NAME' => $entityName,
'ENTITY_CAPTION' => $entityCaption,
'VALUE' => $value,
'LINK' => $link,
);
}
else
{
$result['COMMON'][$counter] = $value;
}
}
return $result;
}