...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_contact.php
- Класс: \CAllCrmContact
- Вызов: CAllCrmContact::CompareFields
static function CompareFields(array $arFieldsOrig, array $arFieldsModif, array $arOptions = null) { if(!is_array($arOptions)) { $arOptions = array(); } $arMsg = Array(); if ( isset($arFieldsOrig['HONORIFIC'], $arFieldsModif['HONORIFIC']) && $arFieldsOrig['HONORIFIC'] !== $arFieldsModif['HONORIFIC'] ) { $honorifics = CCrmStatus::GetStatusList('HONORIFIC'); $arMsg[] = [ 'ENTITY_FIELD' => 'HONORIFIC', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_HONORIFIC'), 'EVENT_TEXT_1' => htmlspecialcharsbx(CrmCompareFieldsList($honorifics, $arFieldsOrig['HONORIFIC'])), 'EVENT_TEXT_2' => htmlspecialcharsbx(CrmCompareFieldsList($honorifics, $arFieldsModif['HONORIFIC'])) ]; } if (isset($arFieldsOrig['NAME']) && isset($arFieldsModif['NAME']) && $arFieldsOrig['NAME'] != $arFieldsModif['NAME']) $arMsg[] = Array( 'ENTITY_FIELD' => 'NAME', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_NAME'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['NAME'])? $arFieldsOrig['NAME']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['NAME'])? $arFieldsModif['NAME']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); if (isset($arFieldsOrig['LAST_NAME']) && isset($arFieldsModif['LAST_NAME']) && $arFieldsOrig['LAST_NAME'] != $arFieldsModif['LAST_NAME']) $arMsg[] = Array( 'ENTITY_FIELD' => 'LAST_NAME', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_LAST_NAME'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['LAST_NAME'])? $arFieldsOrig['LAST_NAME']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['LAST_NAME'])? $arFieldsModif['LAST_NAME']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); if (isset($arFieldsOrig['SECOND_NAME']) && isset($arFieldsModif['SECOND_NAME']) && $arFieldsOrig['SECOND_NAME'] != $arFieldsModif['SECOND_NAME']) $arMsg[] = Array( 'ENTITY_FIELD' => 'SECOND_NAME', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_SECOND_NAME'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['SECOND_NAME'])? $arFieldsOrig['SECOND_NAME']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['SECOND_NAME'])? $arFieldsModif['SECOND_NAME']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); if (isset($arFieldsOrig['FM']) && isset($arFieldsModif['FM'])) $arMsg = array_merge($arMsg, CCrmFieldMulti::CompareFields($arFieldsOrig['FM'], $arFieldsModif['FM'])); if (isset($arFieldsOrig['POST']) && isset($arFieldsModif['POST']) && $arFieldsOrig['POST'] != $arFieldsModif['POST']) $arMsg[] = Array( 'ENTITY_FIELD' => 'POST', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_POST'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['POST'])? $arFieldsOrig['POST']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['POST'])? $arFieldsModif['POST']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); $addressOptions = array(); if(isset($arOptions['ADDRESS_FIELDS'])) { $addressOptions['FIELDS'] = $arOptions['ADDRESS_FIELDS']; } $arMsg = array_merge( $arMsg, ContactAddress::prepareChangeEvents( $arFieldsOrig, $arFieldsModif, ContactAddress::Primary, $addressOptions ) ); if (isset($arFieldsOrig['COMMENTS']) && isset($arFieldsModif['COMMENTS']) && $arFieldsOrig['COMMENTS'] != $arFieldsModif['COMMENTS']) $arMsg[] = Array( 'ENTITY_FIELD' => 'COMMENTS', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_COMMENTS'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['COMMENTS'])? TextHelper::convertBbCodeToHtml($arFieldsOrig['COMMENTS']): GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['COMMENTS'])? TextHelper::convertBbCodeToHtml($arFieldsModif['COMMENTS']): GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); if(isset($arOptions['COMPANIES']) && is_array($arOptions['COMPANIES'])) { $addedCompanyIDs = isset($arOptions['COMPANIES']['ADDED']) && is_array($arOptions['COMPANIES']['ADDED']) ? $arOptions['COMPANIES']['ADDED'] : array(); $removedCompanyIDs = isset($arOptions['COMPANIES']['REMOVED']) && is_array($arOptions['COMPANIES']['REMOVED']) ? $arOptions['COMPANIES']['REMOVED'] : array(); if(!empty($addedCompanyIDs) || !empty($removedCompanyIDs)) { //region Preparation of company titles $dbResult = CCrmCompany::GetListEx( array(), array( 'CHECK_PERMISSIONS' => 'N', '@ID' => array_merge($addedCompanyIDs, $removedCompanyIDs) ), false, false, array('ID', 'TITLE') ); $companyTitles = array(); while ($ary = $dbResult->Fetch()) { $companyTitles[$ary['ID']] = $ary['TITLE']; } //endregion if(count($addedCompanyIDs) <= 1 && count($removedCompanyIDs) <= 1) { //region Single binding mode $arMsg[] = Array( 'ENTITY_FIELD' => 'COMPANY_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_COMPANY_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList( $companyTitles, isset($removedCompanyIDs[0]) ? $removedCompanyIDs[0] : 0 ), 'EVENT_TEXT_2' => CrmCompareFieldsList( $companyTitles, isset($addedCompanyIDs[0]) ? $addedCompanyIDs[0] : 0 ) ); //endregion } else { //region Multiple binding mode //region Add companies event $texts = array(); foreach($addedCompanyIDs as $companyID) { if(isset($companyTitles[$companyID])) { $texts[] = $companyTitles[$companyID]; } } $arMsg[] = Array( 'ENTITY_FIELD' => 'COMPANY_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_COMPANIES_ADDED'), 'EVENT_TEXT_1' => implode(', ', $texts), ); //endregion //region Remove companies event $texts = array(); foreach($removedCompanyIDs as $companyID) { if(isset($companyTitles[$companyID])) { $texts[] = $companyTitles[$companyID]; } } $arMsg[] = Array( 'ENTITY_FIELD' => 'COMPANY_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_COMPANIES_REMOVED'), 'EVENT_TEXT_1' => implode(', ', $texts), ); //endregion //endregion } } } if (isset($arFieldsOrig['SOURCE_ID']) && isset($arFieldsModif['SOURCE_ID']) && $arFieldsOrig['SOURCE_ID'] != $arFieldsModif['SOURCE_ID']) { $arStatus = CCrmStatus::GetStatusList('SOURCE'); $arMsg[] = Array( 'ENTITY_FIELD' => 'SOURCE_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_SOURCE_ID'), 'EVENT_TEXT_1' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsOrig['SOURCE_ID'])), 'EVENT_TEXT_2' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsModif['SOURCE_ID'])) ); } if (isset($arFieldsOrig['SOURCE_DESCRIPTION']) && isset($arFieldsModif['SOURCE_DESCRIPTION']) && $arFieldsOrig['SOURCE_DESCRIPTION'] != $arFieldsModif['SOURCE_DESCRIPTION']) $arMsg[] = Array( 'ENTITY_FIELD' => 'SOURCE_DESCRIPTION', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_SOURCE_DESCRIPTION'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['SOURCE_DESCRIPTION'])? $arFieldsOrig['SOURCE_DESCRIPTION']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['SOURCE_DESCRIPTION'])? $arFieldsModif['SOURCE_DESCRIPTION']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); if (isset($arFieldsOrig['TYPE_ID']) && isset($arFieldsModif['TYPE_ID']) && $arFieldsOrig['TYPE_ID'] != $arFieldsModif['TYPE_ID']) { $arStatus = CCrmStatus::GetStatusList('CONTACT_TYPE'); $arMsg[] = Array( 'ENTITY_FIELD' => 'TYPE_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_TYPE_ID'), 'EVENT_TEXT_1' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsOrig['TYPE_ID'])), 'EVENT_TEXT_2' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsModif['TYPE_ID'])) ); } if (isset($arFieldsOrig['ASSIGNED_BY_ID']) && isset($arFieldsModif['ASSIGNED_BY_ID']) && (int)$arFieldsOrig['ASSIGNED_BY_ID'] != (int)$arFieldsModif['ASSIGNED_BY_ID']) { $arUser = Array(); $dbUsers = CUser::GetList( 'last_name', 'asc', array('ID' => implode('|', array(intval($arFieldsOrig['ASSIGNED_BY_ID']), intval($arFieldsModif['ASSIGNED_BY_ID'])))), array('FIELDS' => array('ID', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'LOGIN', 'TITLE', 'EMAIL')) ); while ($arRes = $dbUsers->Fetch()) $arUser[$arRes['ID']] = CUser::FormatName(CSite::GetNameFormat(false), $arRes); $arMsg[] = Array( 'ENTITY_FIELD' => 'ASSIGNED_BY_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_ASSIGNED_BY_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arUser, $arFieldsOrig['ASSIGNED_BY_ID']), 'EVENT_TEXT_2' => CrmCompareFieldsList($arUser, $arFieldsModif['ASSIGNED_BY_ID']) ); } if (isset($arFieldsModif['BIRTHDATE'])) { $origBirthdate = isset($arFieldsOrig['BIRTHDATE']) ? $arFieldsOrig['BIRTHDATE'] : ''; $modifBirthdate = isset($arFieldsModif['BIRTHDATE']) ? $arFieldsModif['BIRTHDATE'] : ''; if($origBirthdate !== $modifBirthdate) { $arMsg[] = Array( 'ENTITY_FIELD' => 'BIRTHDATE', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_BIRTHDATE'), 'EVENT_TEXT_1' => $origBirthdate !== '' ? $origBirthdate : GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => $modifBirthdate !== '' ? $modifBirthdate : GetMessage('CRM_FIELD_COMPARE_EMPTY') ); } } return $arMsg; }