...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_usertype.php
- Класс: \CCrmUserType
- Вызов: CCrmUserType::TryInternalizeCrmEntityID
static function TryInternalizeCrmEntityID($type, $value, &$ID) { if($value === '') { return false; } if(preg_match('/^\[([A-Z]+)\]/i', $value, $m) > 0) { $valueType = CCrmOwnerType::Undefined; $prefix = mb_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; } elseif($prefix === 'O') { $valueType = CCrmOwnerType::Order; } if($valueType !== CCrmOwnerType::Undefined && $valueType !== $type) { return false; } $value = mb_substr($value, mb_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::GetListEx(array(), array('=TITLE'=> $value), false, false, 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, '@CATEGORY_ID' => 0,), 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], '@CATEGORY_ID' => 0,), 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], '@CATEGORY_ID' => 0,), 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, '@CATEGORY_ID' => 0,), 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, '@CATEGORY_ID' => 0,), 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; }