Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use \Bitrix\Crm;
- \Bitrix\Main\Loader::includeModule('crm');
- $result = array();
- $preset = \Bitrix\Crm\EntityPreset::getSingleInstance();
- $entityTypeId = \Bitrix\Crm\EntityPreset::Requisite;
- $requisite = \Bitrix\Crm\EntityRequisite::getSingleInstance();
- $entityFieldsTitles = $requisite->getFieldsTitles(1);
- $countryList = array();
- foreach (\Bitrix\Crm\EntityPreset::getCountryList() as $k => $v)
- $countryList[$k] = $v;
- if ($preset->checkEntityType($entityTypeId))
- {
- $fieldsAllowed = array();
- foreach (array_merge($requisite->getRqFields(), $requisite->getUserFields()) as $fieldName)
- {
- $fieldsAllowed[$fieldName] = true;
- }
- $presetList = $requisite->getFixedPresetList();
- $res = $preset->getList(array(
- 'order' => array('SORT' => 'ASC', 'ID' => 'ASC'),
- 'filter' => array('=ENTITY_TYPE_ID' => $entityTypeId, '=ACTIVE' => 'Y', '!ID' => 1),
- 'select' => array('ID', 'NAME', 'COUNTRY_ID', 'SETTINGS')
- ));
- while ($row = $res->fetch())
- {
- $presetTitle = trim(strval($row['NAME']));
- if (empty($presetTitle))
- $row['NAME'] = '['.$row['ID'].'] - '.GetMessage('CRM_REQUISITE_PRESET_NAME_EMPTY');
- $presetList[] = $row;
- }
- $topItems = array(array('id' => '', 'title' => GetMessage('CRM_PRESET_EDIT_SELECT_FIELDS_NONE')));
- $items = array();
- $otherItems = array();
- $usedFields = array();
- foreach ($presetList as $row)
- {
- if (1 === intval($row['COUNTRY_ID']) && is_array($row['SETTINGS']))
- {
- $fields = $preset->settingsGetFields($row['SETTINGS']);
- if (!empty($fields))
- {
- $countryId = isset($row['COUNTRY_ID']) ? (int)$row['COUNTRY_ID'] : 0;
- $countryPostfix = isset($countryList[$countryId]) ?
- " ({$countryList[$countryId]})" : '';
- $g = $i = 0;
- foreach ($fields as $fieldInfo)
- {
- if (isset($fieldsAllowed[$fieldInfo['FIELD_NAME']]))
- {
- if ($g === 0)
- {
- $groupItem = array('type' => 'group', 'title' => $row['NAME'].$countryPostfix);
- if ($countryId === 1)
- {
- $topItems[] = $groupItem;
- }
- else
- {
- $items[] = $groupItem;
- }
- $g++;
- }
- $title = $entityFieldsTitles[$fieldInfo['FIELD_NAME']];
- if (!empty($title))
- {
- $item = array(
- 'id' => $fieldInfo['FIELD_NAME'],
- 'title' => $title
- );
- if ($countryId === 1)
- {
- $topItems[] = $item;
- }
- else
- {
- $items[] = $item;
- }
- $usedFields[$fieldInfo['FIELD_NAME']] = true;
- $i++;
- }
- }
- }
- if ($i === 0 && $g === 1)
- {
- if ($countryId === 1)
- {
- unset($topItems[key($topItems)]);
- }
- else
- {
- unset($items[key($items)]);
- }
- }
- }
- }
- }
- $g = $i = 0;
- foreach (array_keys($fieldsAllowed) as $fieldName)
- {
- if (!isset($usedFields[$fieldName]))
- {
- if ($g === 0)
- {
- $otherItems[] = array(
- 'type' => 'group', 'title' => GetMessage('CRM_PRESET_EDIT_SELECT_OTHER_FIELDS')
- );
- $g++;
- }
- $title = $entityFieldsTitles[$fieldName];
- if (!empty($title))
- {
- $otherItems[] = $item = array(
- 'id' => $fieldName,
- 'title' => $entityFieldsTitles[$fieldName]
- );
- $i++;
- }
- }
- }
- if ($i === 0 && $g === 1)
- {
- unset($otherItems[key($otherItems)]);
- }
- $result = array_merge($topItems, $items, $otherItems);
- }
- echo "<pre>";
- print_r($result);
- echo "</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement