CCrmRestProxyBase::externalizeFields

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmRestProxyBase
  4. externalizeFields
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmRestProxyBase
  • Вызов: CCrmRestProxyBase::externalizeFields
protected function externalizeFields(&$fields, &$fieldsInfo)
{
	if(!is_array($fields))
	{
		return;
	}

	//Multi fields processing
	if(isset($fields['FM']))
	{
		foreach($fields['FM'] as $fmTypeID => &$fmItems)
		{
			foreach($fmItems as &$fmItem)
			{
				$fmItem['TYPE_ID'] = $fmTypeID;
				unset($fmItem['ENTITY_ID'], $fmItem['ELEMENT_ID']);
			}
			unset($fmItem);
			$fields[$fmTypeID] = $fmItems;
		}
		unset($fmItems);
		unset($fields['FM']);
	}

	foreach($fields as $k => $v)
	{
		$info = $fieldsInfo[$k] ?? null;
		if(!$info)
		{
			unset($fields[$k]);
			continue;
		}

		$attrs = $info['ATTRIBUTES'] ?? array();
		$isMultiple = in_array(CCrmFieldInfoAttr::Multiple, $attrs, true);
		$isHidden = in_array(CCrmFieldInfoAttr::Hidden, $attrs, true);
		$isDynamic = in_array(CCrmFieldInfoAttr::Dynamic, $attrs, true);

		if($isHidden)
		{
			unset($fields[$k]);
			continue;
		}

		$fieldType = $info['TYPE'] ?? '';
		if($fieldType === 'date')
		{
			if(!is_array($v))
			{
				$fields[$k] = CRestUtil::ConvertDate($v);
			}
			else
			{
				$fields[$k] = array();
				foreach($v as &$value)
				{
					$fields[$k][] = CRestUtil::ConvertDate($value);
				}
				unset($value);
			}
		}
		elseif($fieldType === 'datetime')
		{
			if(!is_array($v))
			{
				$fields[$k] = CRestUtil::ConvertDateTime($v);
			}
			else
			{
				$fields[$k] = array();
				foreach($v as &$value)
				{
					$fields[$k][] = CRestUtil::ConvertDateTime($value);
				}
				unset($value);
			}
		}
		elseif($fieldType === 'file')
		{
			$this->tryExternalizeFileField($fields, $k, $isMultiple, $isDynamic);
		}
		elseif($fieldType === 'webdav')
		{
			$this->tryExternalizeWebDavElementField($fields, $k, $isMultiple);
		}
		elseif($fieldType === 'diskfile')
		{
			$this->tryExternalizeDiskFileField($fields, $k, $isMultiple);
		}
		elseif($fieldType === 'attached_diskfile')
		{
			$this->tryExternalizeAttachedDiskFileField($fields, $k, $isMultiple);
		}
		elseif($fieldType === 'product_file')
		{
			$this->tryExternalizeProductFileField($fields, $k, false, false);
		}
		elseif($fieldType === 'product_property')
		{
			$this->tryExternalizeProductPropertyField($fields, $fieldsInfo, $k);
		}
		elseif($fieldType === 'recurring_params' || $fieldType === 'crm_timeline_bindings')
		{
			$this->externalizeFields($fields[$k], $fieldsInfo[$k]['FIELDS']);
		}
	}

	$id = (int)($fields['ID'] ?? 0);
	if ($id > 0 && \CCrmOwnerType::IsDefined($this->getOwnerTypeID()))
	{
		$fields = \Bitrix\Crm\Entity\CommentsHelper::prepareFieldsFromCompatibleRestToRead(
			$this->getOwnerTypeID(),
			$id,
			$fields,
		);
	}
}

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