- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/entitypreset.php
- Класс: Bitrix\Crm\EntityPreset
- Вызов: EntityPreset::getSettingsFieldsOfPresets
public function getSettingsFieldsOfPresets($entityTypeId, $type = 'all', $options = array())
{
$result = array();
if (!is_array($options))
$options = array();
$arrangeByCountry = false;
if (isset($options['ARRANGE_BY_COUNTRY'])
&& ($options['ARRANGE_BY_COUNTRY'] === true
|| mb_strtoupper(strval($options['ARRANGE_BY_COUNTRY'])) === 'Y'))
{
$arrangeByCountry = true;
}
$filterByCountryIds = array();
if (isset($options['FILTER_BY_COUNTRY_IDS']))
{
if (!is_array($options['FILTER_BY_COUNTRY_IDS']))
{
$filterByCountryIds = array((int)$options['FILTER_BY_COUNTRY_IDS']);
}
else
{
foreach ($options['FILTER_BY_COUNTRY_IDS'] as $id)
$filterByCountryIds[] = (int)$id;
}
$arrangeByCountry = true;
}
$filterByCountry = !empty($filterByCountryIds);
$filterByPresetIds = array();
if (isset($options['FILTER_BY_PRESET_IDS']))
{
if (!is_array($options['FILTER_BY_PRESET_IDS']))
{
$filterByPresetIds = array((int)$options['FILTER_BY_PRESET_IDS']);
}
else
{
foreach ($options['FILTER_BY_PRESET_IDS'] as $id)
$filterByPresetIds[] = (int)$id;
}
}
$filterByPreset = !empty($filterByPresetIds);
$filter = array('=ENTITY_TYPE_ID' => $entityTypeId);
switch ($type)
{
case 'all':
break;
case 'active':
$filter['=ACTIVE'] = 'Y';
break;
case 'inactive':
$filter['=ACTIVE'] = 'N';
break;
}
if ($this->checkEntityType($entityTypeId))
{
$fieldsAllowed = array();
if ($entityTypeId === self::Requisite)
{
$requisite = new EntityRequisite();
$fieldsAllowed = array_merge($requisite->getRqFields(), $requisite->getUserFields());
$fieldsAllowed = array_diff($fieldsAllowed, EntityRequisite::getFileFields());
unset($requisite);
}
$iResult = array();
$select = array('ID');
if ($arrangeByCountry)
$select[] = 'COUNTRY_ID';
$select[] = 'SETTINGS';
if ($filterByCountry)
$filter['=COUNTRY_ID'] = $filterByCountryIds;
if ($filterByPreset)
$filter['=ID'] = $filterByPresetIds;
$res = $this->getList(array(
'order' => array('SORT' => 'ASC', 'ID' => 'ASC'),
'filter' => $filter,
'select' => $select
));
while ($row = $res->fetch())
{
if (is_array($row['SETTINGS']))
{
$fields = $this->settingsGetFields($row['SETTINGS']);
if (!empty($fields) && (!$arrangeByCountry || isset($row['COUNTRY_ID'])))
{
$countryId = (int)$row['COUNTRY_ID'];
if (empty($filterByCountryIds) || in_array($countryId, $filterByCountryIds, true))
{
foreach ($fields as $fieldInfo)
{
if ($arrangeByCountry)
{
if ($countryId > 0)
{
if (isset($fieldInfo['FIELD_NAME'])
&& !isset($iResult[$countryId][$fieldInfo['FIELD_NAME']]))
{
$iResult[$countryId][$fieldInfo['FIELD_NAME']] = true;
}
}
}
else
{
if (isset($fieldInfo['FIELD_NAME']) && !isset($iResult[$fieldInfo['FIELD_NAME']]))
$iResult[$fieldInfo['FIELD_NAME']] = true;
}
}
}
}
}
}
if ($arrangeByCountry)
{
$countryIds = array_keys($iResult);
$includeZeroCountry = in_array(0, $filterByCountryIds, true);
foreach ($fieldsAllowed as $fieldName)
{
if (!($filterByCountry || $filterByPreset) || $includeZeroCountry)
$result[0][] = $fieldName;
foreach ($countryIds as $countryId)
{
if (isset($iResult[$countryId][$fieldName]))
$result[$countryId][] = $fieldName;
}
}
}
else
{
foreach ($fieldsAllowed as $fieldName)
{
if (isset($iResult[$fieldName]))
$result[] = $fieldName;
}
}
unset($iResult);
}
return $result;
}