CCrmInstantEditorHelper::PrepareUpdate

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmInstantEditorHelper
  4. PrepareUpdate
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_component_helper.php
  • Класс: \CCrmInstantEditorHelper
  • Вызов: CCrmInstantEditorHelper::PrepareUpdate
static function PrepareUpdate($ownerTypeID, &$arFields, &$arFieldNames, &$arFieldValues)
{
	$count = count($arFieldNames);
	$fieldMap = array();
	for($i = 0; $i < $count; $i++)
	{
		$fieldName = $arFieldNames[$i];
		$fieldValue = isset($arFieldValues[$i]) ? $arFieldValues[$i] : '';

		if($fieldName === 'COMMENTS' || $fieldName === 'USER_DESCRIPTION')
		{
			$arFields[$fieldName] = \Bitrix\Crm\Format\TextHelper::sanitizeHtml($fieldValue);
		}
		elseif(mb_strpos($fieldName, 'FM.') === 0)
		{
			// Processing of multifield name (FM.[TYPE].[VALUE_TYPE].[ID])
			$fmParts = explode('.', mb_substr($fieldName, 3));
			if(count($fmParts) === 3)
			{
				[$fmType, $fmValueType, $fmID] = $fmParts;

				$fmType = strval($fmType);
				$fmValueType = strval($fmValueType);
				$fmID = intval($fmID);

				if($fmType !== '' && $fmValueType !== '' && $fmID > 0)
				{
					if(!isset($arFields['FM']))
					{
						$arFields['FM'] = array();
					}

					if(!isset($arFields['FM'][$fmType]))
					{
						$arFields['FM'][$fmType] = array();
					}

					$arFields['FM'][$fmType][$fmID] = array('VALUE_TYPE' => $fmValueType, 'VALUE' => $fieldValue);
				}
			}
		}
		elseif(array_key_exists($fieldName, $arFields))
		{
			$arFields[$fieldName] = $fieldValue;
		}

		$fieldMap[$fieldName] = isset($arFields[$fieldName]) ? $arFields[$fieldName] : null;
	}

	//Cleanup not changed user fields
	foreach($arFields as $fieldName => $fieldValue)
	{
		if(mb_strpos($fieldName, 'UF_') === 0 && !isset($fieldMap[$fieldName]))
		{
			unset($arFields[$fieldName]);
		}
	}

	if($ownerTypeID === CCrmOwnerType::Lead
		|| $ownerTypeID === CCrmOwnerType::Deal
		|| $ownerTypeID === CCrmOwnerType::Contact
		|| $ownerTypeID === CCrmOwnerType::Company)
	{
		if(isset($arFields['CREATED_BY_ID']))
		{
			unset($arFields['CREATED_BY_ID']);
		}

		if(isset($arFields['DATE_CREATE']))
		{
			unset($arFields['DATE_CREATE']);
		}

		if(isset($arFields['MODIFY_BY_ID']))
		{
			unset($arFields['MODIFY_BY_ID']);
		}

		if(isset($arFields['DATE_MODIFY']))
		{
			unset($arFields['DATE_MODIFY']);
		}
	}
}

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