- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/webform/options/deps.php
- Класс: Bitrix\Crm\WebForm\Options\Deps
- Вызов: Deps::toArray
public function toArray()
{
$groupRows = $this->form->get()['DEP_GROUPS'];
$deps = $this->form->get()['DEPENDENCIES'];
if (empty($groupRows))
{
return [];
}
$groups = [];
foreach ($groupRows as $group)
{
$groupId = (string) $group['ID'];
$groupTypeId = (int) $group['TYPE_ID'];
switch ($groupTypeId)
{
case WebForm\Internals\FieldDepGroupTable::TYPE_AND:
$groupLogic = 'and';
break;
default:
$groupLogic = 'or';
}
$groups[$groupId] = [
'id' => $groupId,
'typeId' => $groupTypeId,
'logic' => $groupLogic,
'list' => [],
];
}
$fieldsBySection = [];
$currentSection = false;
foreach ($this->form->getFields() as $field)
{
if ($field['TYPE'] === 'section')
{
$currentSection = $field['NAME'];
}
elseif ($field['TYPE'] === 'page')
{
$currentSection = null;
}
if($currentSection)
{
$fieldsBySection[$currentSection][] = $field['NAME'];
}
}
foreach ($deps as $dep)
{
$condition = [
'target' => $dep['IF_FIELD_CODE'],
'event' => $dep['IF_ACTION'],
'value' => $dep['IF_VALUE'],
'operation' => $dep['IF_VALUE_OPERATION'],
];
if (!empty($fieldsBySection[$dep['DO_FIELD_CODE']]))
{
$fieldNames = $fieldsBySection[$dep['DO_FIELD_CODE']];
}
else
{
$fieldNames = [$dep['DO_FIELD_CODE']];
}
foreach ($fieldNames as $fieldName)
{
$action = [
'target' => $fieldName,
'type' => $dep['DO_ACTION'],
'value' => $dep['DO_VALUE'],
];
$groupId = (string) $dep['GROUP_ID'];
if (!isset($groups[$groupId]))
{
if (count($groups) === 1)
{
$groupId = (string) current($groups)['id'];
}
}
$groups[$groupId]['list'][] = [
'condition' => $condition,
'action' => $action,
];
}
}
return array_values($groups);
}