Example #1
0
 private static function ResolveEntityInfo($typeID, $ID)
 {
     $typeID = intval($typeID);
     $ID = intval($ID);
     if (!(CCrmOwnerType::IsDefined($typeID) && $ID > 0)) {
         return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID);
     }
     $fields = null;
     if ($typeID === CCrmOwnerType::Lead) {
         $fields = CCrmLead::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Contact) {
         $fields = CCrmContact::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Company) {
         $fields = CCrmCompany::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Deal) {
         $fields = CCrmDeal::GetByID($ID, false);
     }
     return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID, 'FIELDS' => $fields);
 }
Example #2
0
 public static function PrepareCommunicationInfo(&$arComm, $arFields = null)
 {
     if (!isset($arComm['ENTITY_SETTINGS'])) {
         if (!self::PrepareCommunicationSettings($arComm, $arFields)) {
             $arComm['TITLE'] = '';
             $arComm['DESCRIPTION'] = '';
             return false;
         }
     }
     $title = '';
     $description = '';
     $fullNameFormat = \Bitrix\Crm\Format\PersonNameFormatter::getFormat();
     $entityTypeID = isset($arComm['ENTITY_TYPE_ID']) ? intval($arComm['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined;
     if ($entityTypeID === CCrmOwnerType::Lead) {
         $name = '';
         $secondName = '';
         $lastName = '';
         $leadTitle = '';
         if (is_array($arComm['ENTITY_SETTINGS'])) {
             $settings = $arComm['ENTITY_SETTINGS'];
             $name = isset($settings['NAME']) ? $settings['NAME'] : '';
             $secondName = isset($settings['SECOND_NAME']) ? $settings['SECOND_NAME'] : '';
             $lastName = isset($settings['LAST_NAME']) ? $settings['LAST_NAME'] : '';
             $leadTitle = isset($settings['LEAD_TITLE']) ? $settings['LEAD_TITLE'] : '';
         } else {
             $arEntity = CCrmLead::GetByID($arComm['ENTITY_ID']);
             if ($arEntity) {
                 $name = isset($arEntity['NAME']) ? $arEntity['NAME'] : '';
                 $secondName = isset($arEntity['SECOND_NAME']) ? $arEntity['SECOND_NAME'] : '';
                 $lastName = isset($arEntity['LAST_NAME']) ? $arEntity['LAST_NAME'] : '';
                 $leadTitle = isset($arEntity['TITLE']) ? $arEntity['TITLE'] : '';
             }
         }
         if ($name === '' && $secondName === '' && $lastName === '') {
             $title = $leadTitle;
             //$description = '';
         } else {
             $title = CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $name, 'SECOND_NAME' => $secondName, 'LAST_NAME' => $lastName), false, false);
             $description = $leadTitle;
         }
     } elseif ($entityTypeID === CCrmOwnerType::Contact) {
         // Empty TYPE is person to person communiation, empty ENTITY_ID is unbound communication - no method to build title
         if (!($arComm['TYPE'] === '' && intval($arComm['ENTITY_ID']) === 0)) {
             $name = '';
             $secondName = '';
             $lastName = '';
             $companyTitle = '';
             if (is_array($arComm['ENTITY_SETTINGS'])) {
                 $settings = $arComm['ENTITY_SETTINGS'];
                 $name = isset($settings['NAME']) ? $settings['NAME'] : '';
                 $secondName = isset($settings['SECOND_NAME']) ? $settings['SECOND_NAME'] : '';
                 $lastName = isset($settings['LAST_NAME']) ? $settings['LAST_NAME'] : '';
                 $companyTitle = isset($settings['COMPANY_TITLE']) ? $settings['COMPANY_TITLE'] : '';
             } else {
                 $arEntity = CCrmContact::GetByID($arComm['ENTITY_ID']);
                 if ($arEntity) {
                     $name = isset($arEntity['NAME']) ? $arEntity['NAME'] : '';
                     $secondName = isset($arEntity['SECOND_NAME']) ? $arEntity['SECOND_NAME'] : '';
                     $lastName = isset($arEntity['LAST_NAME']) ? $arEntity['LAST_NAME'] : '';
                     $companyTitle = isset($arEntity['COMPANY_TITLE']) ? $arEntity['COMPANY_TITLE'] : '';
                 }
             }
             $title = CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $name, 'SECOND_NAME' => $secondName, 'LAST_NAME' => $lastName), false, false);
             $description = $companyTitle;
         }
     } elseif ($entityTypeID === CCrmOwnerType::Company) {
         if (is_array($arComm['ENTITY_SETTINGS'])) {
             $settings = $arComm['ENTITY_SETTINGS'];
             $title = isset($settings['COMPANY_TITLE']) ? $settings['COMPANY_TITLE'] : '';
         } else {
             $arEntity = CCrmCompany::GetByID($arComm['ENTITY_ID']);
             if ($arEntity) {
                 $title = isset($arEntity['TITLE']) ? $arEntity['TITLE'] : '';
             }
         }
     }
     $arComm['TITLE'] = $title;
     $arComm['DESCRIPTION'] = $description;
     return true;
 }
Example #3
0
 public static function RewriteClientFields(&$arFields, $bDualFields = true)
 {
     $arCompany = $companyEMail = $companyPhone = null;
     $arContact = $contactEMail = $contactPhone = null;
     $companyId = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0;
     $contactId = isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0;
     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 = Bitrix\Crm\Format\CompanyAddressFormatter::format($arCompany, array('TYPE_ID' => \Bitrix\Crm\EntityAddress::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 = Bitrix\Crm\Format\ContactAddressFormatter::format($arContact);
                 } elseif ($k === 'CLIENT_EMAIL') {
                     $v = $contactEMail;
                 } elseif ($k === 'CLIENT_PHONE') {
                     $v = $contactPhone;
                 }
                 if ($bDualFields) {
                     $arFields['~' . $k] = $v;
                 }
                 $arFields[$k] = $bDualFields ? htmlspecialcharsbx($v) : $v;
             }
         }
     }
 }
Example #4
0
function GetCrmEntityCommunications($entityType, $entityID, $communicationType)
{
    $fullNameFormat = \Bitrix\Crm\Format\PersonNameFormatter::getFormat();
    if ($entityType === 'LEAD') {
        $data = array('ownerEntityType' => 'LEAD', 'ownerEntityId' => $entityID, 'entityType' => 'LEAD', 'entityId' => $entityID, 'entityTitle' => "{$entityType}_{$entityID}", 'entityDescription' => '', 'tabId' => 'main', 'communications' => array());
        $entity = CCrmLead::GetByID($entityID);
        if (!$entity) {
            return array('ERROR' => 'Invalid data');
        }
        // Prepare title
        $name = isset($entity['NAME']) ? $entity['NAME'] : '';
        $secondName = isset($entity['SECOND_NAME']) ? $entity['SECOND_NAME'] : '';
        $lastName = isset($entity['LAST_NAME']) ? $entity['LAST_NAME'] : '';
        if ($name !== '' || $secondName !== '' || $lastName !== '') {
            $data['entityTitle'] = CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $name, 'SECOND_NAME' => $secondName, 'LAST_NAME' => $lastName), false, false);
            $data['entityDescription'] = isset($entity['TITLE']) ? $entity['TITLE'] : '';
        } else {
            $data['entityTitle'] = isset($entity['TITLE']) ? $entity['TITLE'] : '';
            $data['entityDescription'] = '';
        }
        // Try to load entity communications
        if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) {
            return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED'));
        }
        if ($communicationType !== '') {
            $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType));
            while ($arField = $dbResFields->Fetch()) {
                if (empty($arField['VALUE'])) {
                    continue;
                }
                $comm = array('type' => $communicationType, 'value' => $arField['VALUE']);
                $data['communications'][] = $comm;
            }
        }
        return array('DATA' => array('TABS' => array(array('id' => 'lead', 'title' => GetMessage('CRM_COMMUNICATION_TAB_LEAD'), 'active' => true, 'items' => array($data)))));
    } elseif ($entityType === 'DEAL') {
        $entity = CCrmDeal::GetByID($entityID);
        if (!$entity) {
            return array('ERROR' => 'Invalid data');
        }
        $dealData = array();
        // Prepare company data
        $entityCompanyData = null;
        $entityCompanyID = isset($entity['COMPANY_ID']) ? intval($entity['COMPANY_ID']) : 0;
        $entityCompany = $entityCompanyID > 0 ? CCrmCompany::GetByID($entityCompanyID) : null;
        if (is_array($entityCompany)) {
            $entityCompanyData = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => 'COMPANY', 'entityId' => $entityCompanyID, 'entityTitle' => isset($entityCompany['TITLE']) ? $entityCompany['TITLE'] : '', 'entityDescription' => '', 'communications' => array());
            if ($communicationType !== '') {
                $entityCompanyComms = CCrmActivity::PrepareCommunications('COMPANY', $entityCompanyID, $communicationType);
                foreach ($entityCompanyComms as &$entityCompanyComm) {
                    $comm = array('type' => $entityCompanyComm['TYPE'], 'value' => $entityCompanyComm['VALUE']);
                    $entityCompanyData['communications'][] = $comm;
                }
                unset($entityCompanyComm);
            }
        }
        // Try to get contact of deal
        $entityContactID = isset($entity['CONTACT_ID']) ? intval($entity['CONTACT_ID']) : 0;
        if ($entityContactID > 0) {
            $entityContact = CCrmContact::GetByID($entityContactID);
            if (is_array($entityContact)) {
                $item = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => 'CONTACT', 'entityId' => $entityContactID, 'entityTitle' => CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $entityContact['NAME'], 'LAST_NAME' => $entityContact['LAST_NAME'], 'SECOND_NAME' => $entityContact['SECOND_NAME']), false, false), 'tabId' => 'deal', 'communications' => array());
                $entityCompany = isset($entityContact['COMPANY_ID']) ? CCrmCompany::GetByID($entityContact['COMPANY_ID']) : null;
                if ($entityCompany && isset($entityCompany['TITLE'])) {
                    $item['entityDescription'] = $entityCompany['TITLE'];
                }
                if ($communicationType !== '') {
                    $entityContactComms = CCrmActivity::PrepareCommunications('CONTACT', $entityContactID, $communicationType);
                    foreach ($entityContactComms as &$entityContactComm) {
                        $comm = array('type' => $entityContactComm['TYPE'], 'value' => $entityContactComm['VALUE']);
                        $item['communications'][] = $comm;
                    }
                    unset($entityContactComm);
                }
                if ($communicationType === '' || !empty($item['communications'])) {
                    $dealData["CONTACT_{$entityContactID}"] = $item;
                }
            }
        }
        if ($entityCompanyData && !empty($entityCompanyData['communications'])) {
            $dealData['COMPANY_' . $entityCompanyID] = $entityCompanyData;
            $dealData['COMPANY_' . $entityCompanyID]['tabId'] = 'deal';
        }
        // Try to get previous communications
        $entityComms = CCrmActivity::GetCommunicationsByOwner('DEAL', $entityID, $communicationType);
        foreach ($entityComms as &$entityComm) {
            CCrmActivity::PrepareCommunicationInfo($entityComm);
            $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}";
            if (!isset($dealData[$key])) {
                $dealData[$key] = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => CCrmOwnerType::ResolveName($entityComm['ENTITY_TYPE_ID']), 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'deal', 'communications' => array());
            }
            if ($communicationType !== '') {
                $commFound = false;
                foreach ($dealData[$key]['communications'] as &$comm) {
                    if ($comm['value'] === $entityComm['VALUE']) {
                        $commFound = true;
                        break;
                    }
                }
                unset($comm);
                if ($commFound) {
                    continue;
                }
                $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']);
                $dealData[$key]['communications'][] = $comm;
            }
        }
        unset($entityComm);
        $companyData = array();
        // Try to get contacts of company
        if ($entityCompany > 0) {
            $entityComms = CCrmActivity::GetCompanyCommunications($entityCompanyID, $communicationType);
            foreach ($entityComms as &$entityComm) {
                CCrmActivity::PrepareCommunicationInfo($entityComm);
                $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}";
                if (!isset($companyData[$key])) {
                    $companyData[$key] = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => CCrmOwnerType::ResolveName($entityComm['ENTITY_TYPE_ID']), 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'company', 'communications' => array());
                }
                if ($communicationType !== '') {
                    $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']);
                    $companyData[$key]['communications'][] = $comm;
                }
            }
            unset($entityComm);
        }
        if ($entityCompanyData && !empty($entityCompanyData['communications'])) {
            $companyData['COMPANY_' . $entityCompanyID] = $entityCompanyData;
            $companyData['COMPANY_' . $entityCompanyID]['tabId'] = 'company';
        }
        return array('DATA' => array('TABS' => array(array('id' => 'deal', 'title' => GetMessage('CRM_COMMUNICATION_TAB_DEAL'), 'active' => true, 'items' => array_values($dealData)), array('id' => 'company', 'title' => GetMessage('CRM_COMMUNICATION_TAB_COMPANY'), 'items' => array_values($companyData)))));
    } elseif ($entityType === 'COMPANY') {
        $companyData = array();
        $entity = CCrmCompany::GetByID($entityID);
        if (!$entity) {
            return array('ERROR' => 'Invalid data');
        }
        $companyItem = array('ownerEntityType' => 'COMPANY', 'ownerEntityId' => $entityID, 'entityType' => 'COMPANY', 'entityId' => $entityID, 'entityTitle' => isset($entity['TITLE']) ? $entity['TITLE'] : "{$entityType}_{$entityID}", 'entityDescription' => '', 'tabId' => 'company', 'communications' => array());
        // Try to load entity communications
        if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) {
            return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED'));
        }
        if ($communicationType !== '') {
            $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType));
            while ($arField = $dbResFields->Fetch()) {
                if (empty($arField['VALUE'])) {
                    continue;
                }
                $comm = array('type' => $communicationType, 'value' => $arField['VALUE']);
                $companyItem['communications'][] = $comm;
            }
        }
        $companyData["{$entityType}_{$entityID}"] = $companyItem;
        if ($communicationType !== '') {
            $entityComms = CCrmActivity::GetCompanyCommunications($entityID, $communicationType, 50);
            foreach ($entityComms as &$entityComm) {
                CCrmActivity::PrepareCommunicationInfo($entityComm);
                $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}";
                if (!isset($companyData[$key])) {
                    $companyData[$key] = array('ownerEntityType' => 'COMPANY', 'ownerEntityId' => $entityID, 'entityType' => $entityComm['ENTITY_TYPE'], 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'company', 'communications' => array());
                }
                $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']);
                $companyData[$key]['communications'][] = $comm;
            }
            unset($entityComm);
        }
        return array('DATA' => array('TABS' => array(array('id' => 'company', 'title' => GetMessage('CRM_COMMUNICATION_TAB_COMPANY'), 'active' => true, 'items' => array_values($companyData)))));
    } elseif ($entityType === 'CONTACT') {
        $contactData = array();
        $entity = CCrmContact::GetByID($entityID);
        if (!$entity) {
            return array('ERROR' => 'Invalid data');
        }
        $entityCompany = isset($entity['COMPANY_ID']) ? CCrmCompany::GetByID($entity['COMPANY_ID']) : null;
        $contactItem = array('ownerEntityType' => 'CONTACT', 'ownerEntityId' => $entityID, 'entityType' => 'CONTACT', 'entityId' => $entityID, 'entityTitle' => CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $entity['NAME'], 'LAST_NAME' => $entity['LAST_NAME'], 'SECOND_NAME' => $entity['SECOND_NAME']), false, false), 'entityDescription' => $entityCompany && isset($entityCompany['TITLE']) ? $entityCompany['TITLE'] : '', 'tabId' => 'contact', 'communications' => array());
        // Try to load entity communications
        if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) {
            return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED'));
        }
        if ($communicationType !== '') {
            $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType));
            while ($arField = $dbResFields->Fetch()) {
                if (empty($arField['VALUE'])) {
                    continue;
                }
                $comm = array('type' => $communicationType, 'value' => $arField['VALUE']);
                $contactItem['communications'][] = $comm;
            }
        }
        $contactData["{$entityType}_{$entityID}"] = $contactItem;
        return array('DATA' => array('TABS' => array(array('id' => 'contact', 'title' => GetMessage('CRM_COMMUNICATION_TAB_CONTACT'), 'active' => true, 'items' => array_values($contactData)))));
    }
    return array('ERROR' => 'Invalid data');
}
Example #5
0
             unset($item);
         } else {
             $companyComms = CCrmActivity::PrepareCommunications(CCrmOwnerType::CompanyName, $companyID, $commType);
             foreach ($companyComms as &$comm) {
                 $item['COMMUNICATIONS'][] = array('TYPE' => $comm['TYPE'], 'VALUE' => $comm['VALUE']);
             }
             unset($comm);
             if (!empty($item['COMMUNICATIONS'])) {
                 $items[$companyKey] =& $item;
             }
             unset($item);
         }
     }
 }
 $contactID = isset($entity['UF_CONTACT_ID']) ? intval($entity['UF_CONTACT_ID']) : 0;
 $contact = $contactID > 0 ? CCrmContact::GetByID($contactID, true) : null;
 if (is_array($contact)) {
     $info = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID);
     if (CCrmActivity::PrepareCommunicationInfo($info, $contact)) {
         $contactKey = "CONTACT_{$contactID}";
         $item = array('OWNER_ID' => $contactID, 'OWNER_TYPE_ID' => CCrmOwnerType::Contact, 'TITLE' => $info['TITLE'], 'DESCRIPTION' => $info['DESCRIPTION'], 'IMAGE_URL' => CCrmMobileHelper::PrepareContactImageUrl($contact, array('WIDTH' => 40, 'HEIGHT' => 40)), 'COMMUNICATIONS' => array());
         if ($commType === 'PERSON') {
             $items[$contactKey] =& $item;
             unset($item);
         } else {
             $contactComms = CCrmActivity::PrepareCommunications('CONTACT', $contactID, $commType);
             foreach ($contactComms as &$comm) {
                 $item['COMMUNICATIONS'][] = array('TYPE' => $comm['TYPE'], 'VALUE' => $comm['VALUE']);
             }
             unset($comm);
             if (!empty($item['COMMUNICATIONS'])) {
Example #6
0
 public static function __RewritePayerInfo($companyId, $contactId, &$arInvoiceProperties)
 {
     $arCompany = $companyEMail = $companyPhone = null;
     $arContact = $contactEMail = $contactPhone = null;
     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 ($arInvoiceProperties as $propertyKey => $property) {
                 $curVal = $arInvoiceProperties[$propertyKey]['VALUE'];
                 if ($property['FIELDS']['CODE'] === 'COMPANY' || $property['FIELDS']['CODE'] === 'COMPANY_NAME') {
                     if (isset($arCompany['TITLE'])) {
                         $curVal = $arCompany['TITLE'];
                     }
                 } elseif ($property['FIELDS']['CODE'] === 'CONTACT_PERSON' && $contactId > 0) {
                     if (isset($arContact['FULL_NAME'])) {
                         $curVal = $arContact['FULL_NAME'];
                     }
                 } elseif ($property['FIELDS']['CODE'] === 'COMPANY_ADR') {
                     $curVal = Bitrix\Crm\Format\CompanyAddressFormatter::format($arCompany, array('TYPE_ID' => \Bitrix\Crm\EntityAddress::Registered));
                 } elseif ($property['FIELDS']['CODE'] === 'INN') {
                     $todo = 'todo';
                     // TODO:
                 } elseif ($property['FIELDS']['CODE'] === 'KPP') {
                     $todo = 'todo';
                     // TODO:
                 } elseif ($property['FIELDS']['CODE'] === 'EMAIL') {
                     $curVal = $contactEMail != '' ? $contactEMail : $companyEMail;
                 } elseif ($property['FIELDS']['CODE'] === 'PHONE') {
                     $curVal = $contactPhone != '' ? $contactPhone : $companyPhone;
                 }
                 $arInvoiceProperties[$propertyKey]['VALUE'] = $curVal;
             }
         }
     } elseif ($contactId > 0) {
         if (is_array($arContact) && count($arContact) > 0) {
             foreach ($arInvoiceProperties as $propertyKey => $property) {
                 $curVal = $arInvoiceProperties[$propertyKey]['VALUE'];
                 if ($property['FIELDS']['CODE'] === 'FIO') {
                     if (isset($arContact['FULL_NAME'])) {
                         $curVal = $arContact['FULL_NAME'];
                     }
                 } elseif ($property['FIELDS']['CODE'] === 'EMAIL') {
                     $curVal = $contactEMail;
                 } elseif ($property['FIELDS']['CODE'] === 'PHONE') {
                     $curVal = $contactPhone;
                 } elseif ($property['FIELDS']['CODE'] === 'ADDRESS') {
                     $curVal = Bitrix\Crm\Format\ContactAddressFormatter::format($arContact);
                 }
                 $arInvoiceProperties[$propertyKey]['VALUE'] = $curVal;
             }
         }
     }
 }
Example #7
0
 private static function TryInternalizeCrmEntityID($type, $value, &$ID)
 {
     if (preg_match('/^\\[([A-Z]+)\\]/i', $value, $m) > 0) {
         $valueType = CCrmOwnerType::Undefined;
         $prefix = strtoupper($m[1]);
         if ($prefix === 'L') {
             $valueType = CCrmOwnerType::Lead;
         } elseif ($prefix === 'C') {
             $valueType = CCrmOwnerType::Contact;
         } elseif ($prefix === 'CO') {
             $valueType = CCrmOwnerType::Company;
         } elseif ($prefix === 'D') {
             $valueType = CCrmOwnerType::Deal;
         }
         if ($valueType !== CCrmOwnerType::Undefined && $valueType !== $type) {
             return false;
         }
         $value = substr($value, strlen($m[0]));
     }
     // 1. Try to interpret data as entity ID
     // 2. Try to interpret data as entity name
     if ($type === CCrmOwnerType::Lead) {
         if (is_numeric($value)) {
             $arEntity = CCrmLead::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         $rsEntities = CCrmLead::GetList(array(), array('=TITLE' => $value), array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
     } elseif ($type === CCrmOwnerType::Contact) {
         if (is_numeric($value)) {
             $arEntity = CCrmContact::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         // Try to interpret value as FULL_NAME
         $rsEntities = CCrmContact::GetListEx(array(), array('=FULL_NAME' => $value), false, false, array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
         if (preg_match('/\\s*([^\\s]+)\\s+([^\\s]+)\\s*/', $value, $match) > 0) {
             // Try to interpret value as '#NAME# #LAST_NAME#'
             $rsEntities = CCrmContact::GetListEx(array(), array('=NAME' => $match[1], '=LAST_NAME' => $match[2]), false, false, array('ID'));
             while ($arEntity = $rsEntities->Fetch()) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
             // Try to interpret value as '#LAST_NAME# #NAME#'
             $rsEntities = CCrmContact::GetListEx(array(), array('=LAST_NAME' => $match[1], '=NAME' => $match[2]), false, false, array('ID'));
             while ($arEntity = $rsEntities->Fetch()) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         } else {
             // Try to interpret value as '#LAST_NAME#'
             $rsEntities = CCrmContact::GetListEx(array(), array('=LAST_NAME' => $value), false, false, array('ID'));
             while ($arEntity = $rsEntities->Fetch()) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
     } elseif ($type === CCrmOwnerType::Company) {
         if (is_numeric($value)) {
             $arEntity = CCrmCompany::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         $rsEntities = CCrmCompany::GetList(array(), array('=TITLE' => $value), array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
     } elseif ($type === CCrmOwnerType::Deal) {
         if (is_numeric($value)) {
             $arEntity = CCrmDeal::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         $rsEntities = CCrmDeal::GetList(array(), array('=TITLE' => $value), array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
     }
     return false;
 }