CCrmPersonTypeRestProxy::innerGetList

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmPersonTypeRestProxy
  4. innerGetList
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmPersonTypeRestProxy
  • Вызов: CCrmPersonTypeRestProxy::innerGetList
protected function innerGetList($order, $filter, $select, $navigation, &$errors)
{
	global $USER;

	if (!is_array($filter))
	{
		$filter = array();
	}

	if (is_string($select))
	{
		$select = [$select];
	}

	$result = array();

	$crmPerms = new CCrmPerms($USER->GetID());
	if (!$crmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'READ'))
	{
		$errors[] = 'Access denied.';
		return false;
	}

	if (!CModule::IncludeModule('sale'))
	{
		$errors[] = 'Sale module is not installed.';
		return false;
	}

	if (!in_array('*', $select)
		&& !in_array('CODE', $select)
		&& in_array('NAME', $select)
	)
	{
		$select[] = 'CODE';
	}

	foreach ($filter as $field => $value)
	{
		if (mb_strpos($field, 'NAME') !== false)
		{
			$newFieldName = str_replace('NAME', 'CODE', $field);
			$filter[$newFieldName] = $value;
			unset($filter[$field]);
		}
	}

	$siteId = '';
	$siteIterator = Bitrix\Main\SiteTable::getList(array(
		'select' => array('LID', 'LANGUAGE_ID'),
		'filter' => array('=DEF' => 'Y', '=ACTIVE' => 'Y')
	));
	if ($defaultSite = $siteIterator->fetch())
	{
		$siteId = $defaultSite['LID'];
	}
	unset($defaultSite, $siteIterator);

	$filter['=PERSON_TYPE_SITE.SITE_ID'] = $siteId;

	if (empty($select))
	{
		$select = ['*'];
	}

	$dbRes = \Bitrix\Crm\Invoice\PersonType::getList([
		'select' => $select,
		'filter' => $filter,
		'order' => $order
	]);
	while($personType = $dbRes->fetch())
	{
		if ($personType['CODE'] === 'CRM_CONTACT' || $personType['CODE'] === 'CRM_COMPANY')
		{
			$personType['NAME'] = $personType['CODE'];

			unset($personType['CODE']);
			unset($personType['ENTITY_REGISTRY_TYPE']);

			$result[] = $personType;
		}
	}

	return $result;
}

Добавить комментарий