- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_owner_type.php
- Класс: \CCrmOwnerType
- Вызов: CCrmOwnerType::TryGetOwnerInfos
static function TryGetOwnerInfos($typeID, $ID, &$owners, $options = array())
{
$typeID = intval($typeID);
$ID = intval($ID);
if(!is_array($options))
{
$options = array();
}
$entityTypeIDKey = isset($options['ENTITY_TYPE_ID_KEY']) ? $options['ENTITY_TYPE_ID_KEY'] : '';
if($entityTypeIDKey === '')
{
$entityTypeIDKey = 'ENTITY_TYPE_ID';
}
$entityIDKey = isset($options['ENTITY_ID_KEY']) ? $options['ENTITY_ID_KEY'] : '';
if($entityIDKey === '')
{
$entityIDKey = 'ENTITY_ID';
}
$additionalData = isset($options['ADDITIONAL_DATA']) && is_array($options['ADDITIONAL_DATA']) ? $options['ADDITIONAL_DATA'] : null;
$enableMapping = isset($options['ENABLE_MAPPING']) ? (bool)$options['ENABLE_MAPPING'] : false;
$bindingThreshold = 500;
switch($typeID)
{
case self::Contact:
{
$companyIDs = \Bitrix\Crm\Binding\ContactCompanyTable::getContactCompanyIDs($ID);
for($i = 0, $length = min(count($companyIDs), $bindingThreshold); $i < $length; $i++)
{
$companyID = $companyIDs[$i];
$info = array(
$entityTypeIDKey => self::Company,
$entityIDKey => $companyID
);
if($additionalData !== null)
{
$info = array_merge($info, $additionalData);
}
if($enableMapping)
{
$owners[self::Company.'_'.$companyID] = $info;
}
else
{
$owners[] = $info;
}
}
return true;
}
//break;
case self::Deal:
{
$dbRes = CCrmDeal::GetListEx(array(), array('=ID' => $ID), false, false, array('CONTACT_ID', 'COMPANY_ID'));
$arRes = $dbRes ? $dbRes->Fetch() : null;
if(!is_array($arRes))
{
return false;
}
$contactID = isset($arRes['CONTACT_ID']) ? intval($arRes['CONTACT_ID']) : 0;
$companyID = isset($arRes['COMPANY_ID']) ? intval($arRes['COMPANY_ID']) : 0;
if($contactID <= 0 && $companyID <= 0)
{
return false;
}
if($contactID > 0)
{
$info = array(
$entityTypeIDKey => self::Contact,
$entityIDKey => $contactID
);
if($additionalData !== null)
{
$info = array_merge($info, $additionalData);
}
if($enableMapping)
{
$owners[self::Contact.'_'.$contactID] = &$info;
}
else
{
$owners[] = &$info;
}
unset($info);
}
if($companyID > 0)
{
$info = array(
$entityTypeIDKey => self::Company,
$entityIDKey => $companyID
);
if($additionalData !== null)
{
$info = array_merge($info, $additionalData);
}
if($enableMapping)
{
$owners[self::Company.'_'.$companyID] = &$info;
}
else
{
$owners[] = &$info;
}
unset($info);
}
return true;
}
//break;
case self::Quote:
{
$dbRes = CCrmQuote::GetList(array(), array('=ID' => $ID), false, false, array('CONTACT_ID', 'COMPANY_ID'));
$arRes = $dbRes ? $dbRes->Fetch() : null;
if(!is_array($arRes))
{
return false;
}
$contactID = isset($arRes['CONTACT_ID']) ? intval($arRes['CONTACT_ID']) : 0;
$companyID = isset($arRes['COMPANY_ID']) ? intval($arRes['COMPANY_ID']) : 0;
if($contactID <= 0 && $companyID <= 0)
{
return false;
}
if($contactID > 0)
{
$info = array(
$entityTypeIDKey => self::Contact,
$entityIDKey => $contactID
);
if($additionalData !== null)
{
$info = array_merge($info, $additionalData);
}
if($enableMapping)
{
$owners[self::Contact.'_'.$contactID] = &$info;
}
else
{
$owners[] = &$info;
}
unset($info);
}
if($companyID > 0)
{
$info = array(
$entityTypeIDKey => self::Company,
$entityIDKey => $companyID
);
if($additionalData !== null)
{
$info = array_merge($info, $additionalData);
}
if($enableMapping)
{
$owners[self::Company.'_'.$companyID] = &$info;
}
else
{
$owners[] = &$info;
}
unset($info);
}
return true;
}
//break;
}
return false;
}