...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_quote.php
- Класс: \CAllCrmQuote
- Вызов: CAllCrmQuote::RewriteClientFields
static function RewriteClientFields(&$arFields, $bDualFields = true) { $arCompany = $companyEMail = $companyPhone = null; $arContact = $contactEMail = $contactPhone = null; $companyId = isset($arFields['COMPANY_ID']) ? (int)$arFields['COMPANY_ID'] : 0; $contactBindings = isset($arFields['CONTACT_BINDINGS']) && is_array($arFields['CONTACT_BINDINGS']) ? $arFields['CONTACT_BINDINGS'] : array(); $contactId = \Bitrix\Crm\Binding\EntityBinding::getPrimaryEntityID(CCrmOwnerType::Contact, $contactBindings); if($contactId === 0 && isset($arFields['CONTACT_ID'])) { $contactId = (int)$arFields['CONTACT_ID']; } foreach(self::GetClientFields() as $fieldName) { $arFields[$fieldName] = ''; if ($bDualFields) $arFields["~$fieldName"] = ''; } if ($companyId > 0) { $arCompany = CCrmCompany::GetByID($companyId); // Get multifields values (EMAIL and PHONE) $arFieldsMulti = CCrmFieldMulti::GetEntityFields('COMPANY', $companyId, 'EMAIL', true, false); if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) $companyEMail = $arFieldsMulti[0]['VALUE']; $arFieldsMulti = CCrmFieldMulti::GetEntityFields('COMPANY', $companyId, 'PHONE', true, false); if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) $companyPhone = $arFieldsMulti[0]['VALUE']; unset($arFieldsMulti); } if ($contactId > 0) { $arContact = CCrmContact::GetByID($contactId); // Get multifields values (EMAIL and PHONE) $arFieldsMulti = CCrmFieldMulti::GetEntityFields('CONTACT', $contactId, 'EMAIL', true, false); if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) $contactEMail = $arFieldsMulti[0]['VALUE']; $arFieldsMulti = CCrmFieldMulti::GetEntityFields('CONTACT', $contactId, 'PHONE', true, false); if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) $contactPhone = $arFieldsMulti[0]['VALUE']; unset($arFieldsMulti); } if ($companyId > 0) { if (is_array($arCompany) && count($arCompany) >0) { foreach (self::$clientFields as $k) { $v = ''; if ($k === 'CLIENT_TITLE') { if (isset($arCompany['TITLE'])) $v = $arCompany['TITLE']; } elseif ($k === 'CLIENT_CONTACT' && $contactId > 0) { if (isset($arContact['FULL_NAME'])) $v = $arContact['FULL_NAME']; } elseif ($k === 'CLIENT_ADDR') { $v = AddressFormatter::getSingleInstance()->formatTextComma( CompanyAddress::mapEntityFields( $arCompany, ['TYPE_ID' => EntityAddressType::Registered] ) ); } elseif ($k === 'CLIENT_EMAIL') { $v = ($contactEMail != '') ? $contactEMail : $companyEMail; } elseif ($k === 'CLIENT_PHONE') { $v = ($contactPhone != '') ? $contactPhone : $companyPhone; } if ($bDualFields) $arFields['~'.$k] = $v; $arFields[$k] = $bDualFields ? htmlspecialcharsbx($v) : $v; } } } elseif ($contactId > 0) { if (is_array($arContact) && count($arContact) >0) { foreach (self::$clientFields as $k) { $v = ''; if ($k === 'CLIENT_TITLE') { if (isset($arContact['FULL_NAME'])) $v = $arContact['FULL_NAME']; } elseif ($k === 'CLIENT_CONTACT' && $contactId > 0) { $v = ''; } elseif ($k === 'CLIENT_ADDR') { $v = AddressFormatter::getSingleInstance()->formatTextComma( ContactAddress::mapEntityFields($arContact) ); } elseif ($k === 'CLIENT_EMAIL') { $v = $contactEMail; } elseif ($k === 'CLIENT_PHONE') { $v = $contactPhone; } if ($bDualFields) $arFields['~'.$k] = $v; $arFields[$k] = $bDualFields ? htmlspecialcharsbx($v) : $v; } } } }