...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_deal.php
- Класс: \CAllCrmDeal
- Вызов: CAllCrmDeal::CheckFields
public function CheckFields(&$arFields, $ID = false, $options = array()) { global $APPLICATION, $USER_FIELD_MANAGER; $this->LAST_ERROR = ''; $this->checkExceptions = array(); if (!empty($arFields['BEGINDATE']) && !CheckDateTime($arFields['BEGINDATE'])) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_INCORRECT', ['%FIELD_NAME%' => GetMessage('CRM_FIELD_BEGINDATE')]) . "
\n" ; } if (!empty($arFields['CLOSEDATE']) && !CheckDateTime($arFields['CLOSEDATE'])) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_INCORRECT', ['%FIELD_NAME%' => GetMessage('CRM_FIELD_CLOSEDATE')]) . "
\n" ; } if (!empty($arFields['EVENT_DATE']) && !CheckDateTime($arFields['EVENT_DATE'])) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_INCORRECT', ['%FIELD_NAME%' => GetMessage('CRM_FIELD_EVENT_DATE')]) . "
\n" ; } if (($ID == false || isset($arFields['TITLE'])) && empty($arFields['TITLE'])) $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_IS_MISSING', array('%FIELD_NAME%' => GetMessage('CRM_DEAL_FIELD_TITLE')))."
\n"; if( isset($arFields['OPPORTUNITY']) && is_string($arFields['OPPORTUNITY']) && $arFields['OPPORTUNITY'] !== '' ) { $arFields['OPPORTUNITY'] = str_replace(array(',', ' '), array('.', ''), $arFields['OPPORTUNITY']); //HACK: MSSQL returns '.00' for zero value if(mb_strpos($arFields['OPPORTUNITY'], '.') === 0) { $arFields['OPPORTUNITY'] = '0'.$arFields['OPPORTUNITY']; } if (!preg_match('/^-?\d{1,}(\.\d{1,})?$/', $arFields['OPPORTUNITY'])) { $this->LAST_ERROR .= GetMessage('CRM_DEAL_FIELD_OPPORTUNITY_INVALID')."
\n"; } } if (!empty($arFields['PROBABILITY'])) { $arFields['PROBABILITY'] = intval($arFields['PROBABILITY']); if ($arFields['PROBABILITY'] > 100) $arFields['PROBABILITY'] = 100; } if (!is_array($options)) { $options = array(); } $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); } if ($enableUserFieldCheck) { // We have to prepare field data before check (issue #22966) CCrmEntityHelper::NormalizeUserFields( $arFields, self::$sUFEntityID, $USER_FIELD_MANAGER, array('IS_NEW' => ($ID == false)) ); $enableRequiredUserFieldCheck = !(isset($options['DISABLE_REQUIRED_USER_FIELD_CHECK']) && $options['DISABLE_REQUIRED_USER_FIELD_CHECK'] === true); $fieldsToCheck = $arFields; $requiredFields = null; if($enableRequiredUserFieldCheck) { $currentFields = null; if($ID > 0) { if(isset($options['CURRENT_FIELDS']) && is_array($options['CURRENT_FIELDS'])) { $currentFields = $options['CURRENT_FIELDS']; } else { $dbResult = self::GetListEx( array(), array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*') ); $currentFields = $dbResult->Fetch(); } if(!array_key_exists('OBSERVER_IDS', $currentFields)) { $currentFields['OBSERVER_IDS'] = Crm\Observer\ObserverManager::getEntityObserverIDs( \CCrmOwnerType::Deal, $ID ); } } if(is_array($currentFields)) { CCrmEntityHelper::NormalizeUserFields( $currentFields, self::$sUFEntityID, $USER_FIELD_MANAGER, array('IS_NEW' => ($ID == false)) ); //If Stage ID is changed we must perform check of all fields. if(isset($arFields['STAGE_ID']) && $arFields['STAGE_ID'] !== $currentFields['STAGE_ID']) { $fieldsToCheck = array_merge($currentFields, $arFields); if(self::GetSemanticID($arFields['STAGE_ID'], $currentFields['CATEGORY_ID']) === Bitrix\Crm\PhaseSemantics::FAILURE) { //Disable required fields check for failure stage due to backward compatibility. $enableRequiredUserFieldCheck = false; } } elseif(!isset($arFields['STAGE_ID']) && isset($currentFields['STAGE_ID'])) { $fieldsToCheck = array_merge($arFields, array('STAGE_ID' => $currentFields['STAGE_ID'])); } } $requiredFields = Crm\Attribute\FieldAttributeManager::getRequiredFields( CCrmOwnerType::Deal, $ID, $fieldsToCheck, Crm\Attribute\FieldOrigin::UNDEFINED, (is_array($options['FIELD_CHECK_OPTIONS'] ?? null) ? $options['FIELD_CHECK_OPTIONS'] : []) ); $requiredSystemFields = isset($requiredFields[Crm\Attribute\FieldOrigin::SYSTEM]) ? $requiredFields[Crm\Attribute\FieldOrigin::SYSTEM] : array(); if(!empty($requiredSystemFields)) { $validator = new Crm\Entity\DealValidator($ID, $fieldsToCheck); $validationErrors = array(); foreach($requiredSystemFields as $fieldName) { $validator->checkFieldPresence($fieldName, $validationErrors); } if(!empty($validationErrors)) { $e = new CAdminException($validationErrors); $this->checkExceptions[] = $e; $this->LAST_ERROR .= $e->GetString(); } } } $requiredUserFields = $this->getRequiredUserFields($requiredFields); if (!$USER_FIELD_MANAGER->CheckFields( self::$sUFEntityID, $ID, $fieldsToCheck, false, $enableRequiredUserFieldCheck, $requiredUserFields ) ) { $e = $APPLICATION->GetException(); $this->checkExceptions[] = $e; $this->LAST_ERROR .= $e->GetString(); } } return ($this->LAST_ERROR === ''); }