...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_deal.php
- Класс: \CAllCrmDeal
- Вызов: CAllCrmDeal::CompareFields
static function CompareFields($arFieldsOrig, $arFieldsModif, $bCheckPerms = true, array $arOptions = null) { if(!is_array($arOptions)) { $arOptions = array(); } $arMsg = Array(); if (isset($arFieldsOrig['TITLE']) && isset($arFieldsModif['TITLE']) && $arFieldsOrig['TITLE'] != $arFieldsModif['TITLE']) $arMsg[] = Array( 'ENTITY_FIELD' => 'TITLE', 'EVENT_NAME' => GetMessage( 'CRM_DEAL_FIELD_COMPARE', array('#FIELD_NAME#' => self::GetFieldCaption('TITLE')) ), 'EVENT_TEXT_1' => $arFieldsOrig['TITLE'], 'EVENT_TEXT_2' => $arFieldsModif['TITLE'], ); if (isset($arFieldsOrig['COMPANY_ID']) && isset($arFieldsModif['COMPANY_ID']) && (int)$arFieldsOrig['COMPANY_ID'] != (int)$arFieldsModif['COMPANY_ID']) { $arCompany = Array(); $arFilterTmp = array('ID' => array($arFieldsOrig['COMPANY_ID'], $arFieldsModif['COMPANY_ID'])); if (!$bCheckPerms) $arFilterTmp["CHECK_PERMISSIONS"] = "N"; $dbRes = CCrmCompany::GetList(Array('TITLE'=>'ASC'), $arFilterTmp); while ($arRes = $dbRes->Fetch()) $arCompany[$arRes['ID']] = $arRes['TITLE']; $arMsg[] = Array( 'ENTITY_FIELD' => 'COMPANY_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_COMPANY_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arCompany, $arFieldsOrig['COMPANY_ID']), 'EVENT_TEXT_2' => CrmCompareFieldsList($arCompany, $arFieldsModif['COMPANY_ID']) ); } if(isset($arOptions['CONTACTS']) && is_array($arOptions['CONTACTS'])) { $addedContactIDs = isset($arOptions['CONTACTS']['ADDED']) && is_array($arOptions['CONTACTS']['ADDED']) ? $arOptions['CONTACTS']['ADDED'] : array(); $removedContactIDs = isset($arOptions['CONTACTS']['REMOVED']) && is_array($arOptions['CONTACTS']['REMOVED']) ? $arOptions['CONTACTS']['REMOVED'] : array(); if(!empty($addedContactIDs) || !empty($removedContactIDs)) { //region Preparation of contact names $dbResult = CCrmContact::GetListEx( array(), array( 'CHECK_PERMISSIONS' => 'N', '@ID' => array_merge($addedContactIDs, $removedContactIDs) ), false, false, array('ID', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME') ); $contactNames = array(); while ($ary = $dbResult->Fetch()) { $contactNames[$ary['ID']] = CCrmContact::PrepareFormattedName($ary); } //endregion if(count($addedContactIDs) <= 1 && count($removedContactIDs) <= 1) { //region Single binding mode $arMsg[] = Array( 'ENTITY_FIELD' => 'CONTACT_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_CONTACT_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList( $contactNames, isset($removedContactIDs[0]) ? $removedContactIDs[0] : 0 ), 'EVENT_TEXT_2' => CrmCompareFieldsList( $contactNames, isset($addedContactIDs[0]) ? $addedContactIDs[0] : 0 ) ); //endregion } else { //region Multiple binding mode //region Add contacts event $texts = array(); foreach($addedContactIDs as $contactID) { if(isset($contactNames[$contactID])) { $texts[] = $contactNames[$contactID]; } } $arMsg[] = Array( 'ENTITY_FIELD' => 'CONTACT_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_CONTACTS_ADDED'), 'EVENT_TEXT_1' => implode(', ', $texts), ); //endregion //region Remove companies event $texts = array(); foreach($removedContactIDs as $contactID) { if(isset($contactNames[$contactID])) { $texts[] = $contactNames[$contactID]; } } $arMsg[] = Array( 'ENTITY_FIELD' => 'CONTACT_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_CONTACTS_REMOVED'), 'EVENT_TEXT_1' => implode(', ', $texts), ); //endregion //endregion } } } 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($arFieldsOrig['STAGE_ID']) && isset($arFieldsModif['STAGE_ID']) && $arFieldsOrig['STAGE_ID'] != $arFieldsModif['STAGE_ID']) { $arStatus = self::GetStageNames( isset($arFieldsOrig['CATEGORY_ID']) ? (int)$arFieldsOrig['CATEGORY_ID'] : 0 ); $arMsg[] = Array( 'ENTITY_FIELD' => 'STAGE_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_DEAL_STAGE'), 'EVENT_TEXT_1' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsOrig['STAGE_ID'])), 'EVENT_TEXT_2' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsModif['STAGE_ID'])) ); } if (isset($arFieldsOrig['TYPE_ID']) && isset($arFieldsModif['TYPE_ID']) && $arFieldsOrig['TYPE_ID'] != $arFieldsModif['TYPE_ID']) { $arStatus = CCrmStatus::GetStatusList('DEAL_TYPE'); $arMsg[] = Array( 'ENTITY_FIELD' => 'TYPE_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_DEAL_TYPE'), 'EVENT_TEXT_1' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsOrig['TYPE_ID'])), 'EVENT_TEXT_2' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $arFieldsModif['TYPE_ID'])) ); } 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'), ); $arCurrency = CCrmCurrencyHelper::PrepareListItems(); if(isset($arFieldsOrig['CURRENCY_ID']) && isset($arFieldsModif['CURRENCY_ID']) && $arFieldsOrig['CURRENCY_ID'] != $arFieldsModif['CURRENCY_ID']) { $arMsg[] = Array( 'ENTITY_FIELD' => 'CURRENCY_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_CURRENCY'), 'EVENT_TEXT_1' => isset($arCurrency[$arFieldsOrig['CURRENCY_ID']]) ? $arCurrency[$arFieldsOrig['CURRENCY_ID']] : '', 'EVENT_TEXT_2' => isset($arCurrency[$arFieldsModif['CURRENCY_ID']]) ? $arCurrency[$arFieldsModif['CURRENCY_ID']] : '' ); } if ( isset($arFieldsOrig['OPPORTUNITY']) && isset($arFieldsModif['OPPORTUNITY']) && $arFieldsOrig['OPPORTUNITY'] != $arFieldsModif['OPPORTUNITY'] ) { $arMsg[] = Array( 'ENTITY_FIELD' => 'OPPORTUNITY', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_OPPORTUNITY'), 'EVENT_TEXT_1' => floatval($arFieldsOrig['OPPORTUNITY']).(($val = CrmCompareFieldsList($arCurrency, ($arFieldsOrig['CURRENCY_ID'] ?? null), '')) != '' ? ' ('.$val.')' : ''), 'EVENT_TEXT_2' => floatval($arFieldsModif['OPPORTUNITY']).(($val = CrmCompareFieldsList($arCurrency, ($arFieldsModif['CURRENCY_ID'] ?? null), '')) != '' ? ' ('.$val.')' : '') ); } if ( isset($arFieldsOrig['IS_MANUAL_OPPORTUNITY']) && isset($arFieldsModif['IS_MANUAL_OPPORTUNITY']) && $arFieldsOrig['IS_MANUAL_OPPORTUNITY'] != $arFieldsModif['IS_MANUAL_OPPORTUNITY'] ) { $arMsg[] = Array( 'ENTITY_FIELD' => 'IS_MANUAL_OPPORTUNITY', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_IS_MANUAL_OPPORTUNITY'), 'EVENT_TEXT_1' => GetMessage('CRM_FIELD_COMPARE_IS_MANUAL_OPPORTUNITY_'.($arFieldsOrig['IS_MANUAL_OPPORTUNITY'] == 'Y' ? 'Y' : 'N')), 'EVENT_TEXT_2' => GetMessage('CRM_FIELD_COMPARE_IS_MANUAL_OPPORTUNITY_'.($arFieldsModif['IS_MANUAL_OPPORTUNITY'] == 'Y' ? 'Y' : 'N')), ); } 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['PROBABILITY']) && isset($arFieldsModif['PROBABILITY']) && $arFieldsOrig['PROBABILITY'] != $arFieldsModif['PROBABILITY']) $arMsg[] = Array( 'ENTITY_FIELD' => 'PROBABILITY', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_PROBABILITY'), 'EVENT_TEXT_1' => intval($arFieldsOrig['PROBABILITY']).'%', 'EVENT_TEXT_2' => intval($arFieldsModif['PROBABILITY']).'%', ); if (array_key_exists('BEGINDATE', $arFieldsOrig) && array_key_exists('BEGINDATE', $arFieldsModif) && ConvertTimeStamp(strtotime($arFieldsOrig['BEGINDATE'])) != $arFieldsModif['BEGINDATE'] && $arFieldsOrig['BEGINDATE'] != $arFieldsModif['BEGINDATE']) { $arMsg[] = Array( 'ENTITY_FIELD' => 'BEGINDATE', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_BEGINDATE'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['BEGINDATE'])? ConvertTimeStamp(strtotime($arFieldsOrig['BEGINDATE'])): GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['BEGINDATE'])? $arFieldsModif['BEGINDATE']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); } if (array_key_exists('CLOSEDATE', $arFieldsOrig) && array_key_exists('CLOSEDATE', $arFieldsModif) && ConvertTimeStamp(strtotime($arFieldsOrig['CLOSEDATE'])) != $arFieldsModif['CLOSEDATE'] && $arFieldsOrig['CLOSEDATE'] != $arFieldsModif['CLOSEDATE']) { $arMsg[] = Array( 'ENTITY_FIELD' => 'CLOSEDATE', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_CLOSEDATE'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['CLOSEDATE'])? ConvertTimeStamp(strtotime($arFieldsOrig['CLOSEDATE'])): GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['CLOSEDATE'])? $arFieldsModif['CLOSEDATE']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); } if (array_key_exists('EVENT_DATE', $arFieldsOrig) && array_key_exists('EVENT_DATE', $arFieldsModif) && ConvertTimeStamp(strtotime($arFieldsOrig['EVENT_DATE'])) != $arFieldsModif['EVENT_DATE'] && $arFieldsOrig['EVENT_DATE'] != $arFieldsModif['EVENT_DATE']) { $arMsg[] = Array( 'ENTITY_FIELD' => 'EVENT_DATE', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_EVENT_DATE'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['EVENT_DATE'])? ConvertTimeStamp(strtotime($arFieldsOrig['EVENT_DATE'])): GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['EVENT_DATE'])? $arFieldsModif['EVENT_DATE']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); } if (isset($arFieldsOrig['EVENT_ID']) && isset($arFieldsModif['EVENT_ID']) && $arFieldsOrig['EVENT_ID'] != $arFieldsModif['EVENT_ID']) { $arStatus = CCrmStatus::GetStatusList('EVENT_TYPE'); $arMsg[] = Array( 'ENTITY_FIELD' => 'EVENT_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_EVENT_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arStatus, $arFieldsOrig['EVENT_ID']), 'EVENT_TEXT_2' => CrmCompareFieldsList($arStatus, $arFieldsModif['EVENT_ID']) ); } if (isset($arFieldsOrig['EVENT_DESCRIPTION']) && isset($arFieldsModif['EVENT_DESCRIPTION']) && $arFieldsOrig['EVENT_DESCRIPTION'] != $arFieldsModif['EVENT_DESCRIPTION']) $arMsg[] = Array( 'ENTITY_FIELD' => 'EVENT_DESCRIPTION', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_EVENT_DESCRIPTION'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['EVENT_DESCRIPTION'])? $arFieldsOrig['EVENT_DESCRIPTION']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['EVENT_DESCRIPTION'])? $arFieldsModif['EVENT_DESCRIPTION']: GetMessage('CRM_FIELD_COMPARE_EMPTY'), ); if (isset($arFieldsOrig['CLOSED']) && isset($arFieldsModif['CLOSED']) && $arFieldsOrig['CLOSED'] != $arFieldsModif['CLOSED']) $arMsg[] = Array( 'ENTITY_FIELD' => 'CLOSED', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_CLOSED'), 'EVENT_TEXT_1' => $arFieldsOrig['CLOSED'] == 'Y'? GetMessage('MAIN_YES'): GetMessage('MAIN_NO'), 'EVENT_TEXT_2' => $arFieldsModif['CLOSED'] == 'Y'? GetMessage('MAIN_YES'): GetMessage('MAIN_NO'), ); if (isset($arFieldsOrig['LOCATION_ID']) && isset($arFieldsModif['LOCATION_ID']) && $arFieldsOrig['LOCATION_ID'] != $arFieldsModif['LOCATION_ID'] ) { $origLocationID = $arFieldsOrig['LOCATION_ID']; $modifLocationID = $arFieldsModif['LOCATION_ID']; $origLocationName = $modifLocationName = ''; if (IsModuleInstalled('sale') && CModule::IncludeModule('sale')) { $location = new CSaleLocation(); if($origLocationID > 0) { $origLocationName = $location->GetLocationString($origLocationID); if ($origLocationName == '') { $origLocationName = "[{$origLocationID}]"; } } if($modifLocationID > 0) { $modifLocationName = $location->GetLocationString($modifLocationID); if ($modifLocationName == '') { $modifLocationName = "[{$modifLocationID}]"; } } } $arMsg[] = Array( 'ENTITY_FIELD' => 'LOCATION_ID', 'EVENT_NAME' => GetMessage('CRM_FIELD_COMPARE_LOCATION_ID'), 'EVENT_TEXT_1' => $origLocationName, 'EVENT_TEXT_2' => $modifLocationName, ); } return $arMsg; }