CAllCrmCompany::CheckFields

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmCompany
  4. CheckFields
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_company.php
  • Класс: \CAllCrmCompany
  • Вызов: CAllCrmCompany::CheckFields
public function CheckFields(&$arFields, $ID = false, $options = array())
{
	global $APPLICATION, $USER_FIELD_MANAGER;
	$this->LAST_ERROR = '';
	$this->checkExceptions = [];

	if (($ID == false || isset($arFields['TITLE'])) && empty($arFields['TITLE']))
	{
		$this->LAST_ERROR .=
			GetMessage(
				'CRM_ERROR_FIELD_IS_MISSING',
				['%FIELD_NAME%' => GetMessage('CRM_COMPANY_FIELD_TITLE')]
			) . "
" ; } if (isset($arFields['FM']) && is_array($arFields['FM'])) { $CCrmFieldMulti = new CCrmFieldMulti(); if (!$CCrmFieldMulti->CheckComplexFields($arFields['FM'])) { $this->LAST_ERROR .= $CCrmFieldMulti->LAST_ERROR; } } if (isset($arFields['LOGO']) && is_array($arFields['LOGO'])) { if (($strError = CFile::CheckFile($arFields['LOGO'], 0, false, CFile::GetImageExtensions())) != '') $this->LAST_ERROR .= $strError."
"; } if (!is_array($options)) { $options = []; } $isRestoration = isset($options['IS_RESTORATION']) && $options['IS_RESTORATION']; if ($isRestoration) { $enableUserFieldCheck = false; } else { $enableUserFieldCheck = !(isset($options['DISABLE_USER_FIELD_CHECK']) && $options['DISABLE_USER_FIELD_CHECK'] === true); } $factory = Container::getInstance()->getFactory(CCrmOwnerType::Company); if (isset($arFields['CATEGORY_ID'])) { if (!$factory->isCategoryAvailable($arFields['CATEGORY_ID'])) { if ($isRestoration) { $arFields['CATEGORY_ID'] = $factory->getDefaultCategory()->getId(); } else { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_INCORRECT', ['%FIELD_NAME%' => self::GetFieldCaption('CATEGORY_ID')]) . "
"; } } } if (isset($arFields['IS_MY_COMPANY']) && $arFields['IS_MY_COMPANY'] == 'Y') { $categoryId = $arFields['CATEGORY_ID'] ?? $options['CURRENT_FIELDS']['CATEGORY_ID']; if ($categoryId > 0) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_MY_COMPANY_IN_CUSTOM_CATEGORY') . "
"; } } if ($enableUserFieldCheck) { // We have to prepare field data before check (issue #22966) CCrmEntityHelper::NormalizeUserFields( $arFields, self::$sUFEntityID, $USER_FIELD_MANAGER, ['IS_NEW' => ($ID == false)] ); $enableRequiredUserFieldCheck = !(isset($options['DISABLE_REQUIRED_USER_FIELD_CHECK']) && $options['DISABLE_REQUIRED_USER_FIELD_CHECK'] === true); $isUpdate = ($ID > 0); $fieldsToCheck = $arFields; if ($enableRequiredUserFieldCheck) { $requiredFields = Crm\Attribute\FieldAttributeManager::getRequiredFields( CCrmOwnerType::Company, $ID, $fieldsToCheck, Crm\Attribute\FieldOrigin::UNDEFINED, isset($options['FIELD_CHECK_OPTIONS']) && is_array($options['FIELD_CHECK_OPTIONS']) ? $options['FIELD_CHECK_OPTIONS'] : [] ); $requiredSystemFields = $requiredFields[Crm\Attribute\FieldOrigin::SYSTEM] ?? []; if (!empty($requiredSystemFields)) { $validator = new Crm\Entity\CompanyValidator($ID, $fieldsToCheck); $validationErrors = []; foreach($requiredSystemFields as $fieldName) { if ( !$isUpdate || array_key_exists($fieldName, $fieldsToCheck) || ( isset($fieldsToCheck['FM']) && is_array($fieldsToCheck['FM']) && array_key_exists($fieldName, $fieldsToCheck['FM']) ) ) { $validator->checkFieldPresence($fieldName, $validationErrors); } } if (!empty($validationErrors)) { $e = new CAdminException($validationErrors); $this->checkExceptions[] = $e; $this->LAST_ERROR .= $e->GetString(); } } } if (isset($arFields['CATEGORY_ID'])) { // category specified user fields $filteredUserFields = (new CCrmUserType($USER_FIELD_MANAGER, self::$sUFEntityID)) ->setOption(['categoryId' => $arFields['CATEGORY_ID']]) ->GetEntityFields($ID) ; } if ( !$USER_FIELD_MANAGER->CheckFields( self::$sUFEntityID, $ID, $fieldsToCheck, false, $enableRequiredUserFieldCheck, $requiredFields[Crm\Attribute\FieldOrigin::CUSTOM] ?? null, isset($filteredUserFields) ? array_keys($filteredUserFields) : null ) ) { $e = $APPLICATION->GetException(); $this->checkExceptions[] = $e; $this->LAST_ERROR .= $e->GetString(); } } // Temporary crutch. // This check will be removed when operations will be completely supported for companies: $allowSetSystemFields = $options['ALLOW_SET_SYSTEM_FIELDS'] ?? false; if ($allowSetSystemFields) { $currentUserId = isset($options['CURRENT_USER']) ? (int)$options['CURRENT_USER'] : CCrmSecurityHelper::GetCurrentUserID() ; $checkSystemFieldsResult = (new \Bitrix\Crm\Service\Operation\Import( $factory->createItem(), new \Bitrix\Crm\Service\Operation\Settings(Container::getInstance()->getContext()), $factory->getFieldsCollection() ))->checkSystemFieldsValues([ \Bitrix\Crm\Item::FIELD_NAME_CREATED_TIME => isset($arFields['DATE_CREATE']) ? Main\Type\DateTime::createFromUserTime($arFields['DATE_CREATE']) : null , \Bitrix\Crm\Item::FIELD_NAME_UPDATED_TIME => isset($arFields['DATE_MODIFY']) ? Main\Type\DateTime::createFromUserTime($arFields['DATE_MODIFY']) : null , \Bitrix\Crm\Item::FIELD_NAME_CREATED_BY => (isset($arFields['CREATED_BY_ID']) && $arFields['CREATED_BY_ID'] != $currentUserId) ? (int)$arFields['CREATED_BY_ID'] : null , \Bitrix\Crm\Item::FIELD_NAME_UPDATED_BY => (isset($arFields['MODIFY_BY_ID']) && $arFields['MODIFY_BY_ID'] != $currentUserId) ? (int)$arFields['MODIFY_BY_ID'] : null , ]); if (!$checkSystemFieldsResult->isSuccess()) { $this->LAST_ERROR .= implode(', ', $checkSystemFieldsResult->getErrorMessages()); } } return $this->LAST_ERROR === ''; }

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