...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_owner_type.php
- Класс: \CCrmOwnerType
- Вызов: CCrmOwnerType::TryGetEntityInfo
static function TryGetEntityInfo($typeID, $ID, &$info, $checkPermissions = true) { $typeID = intval($typeID); $ID = intval($ID); if(self::$INFO_STUB === null) { self::$INFO_STUB = [ 'TITLE' => '', 'LEGEND' => '', 'IMAGE_FILE_ID' => 0, 'RESPONSIBLE_ID' => 0, 'SHOW_URL' => '', 'ENTITY_TYPE_CAPTION' => '', ]; } if($ID <= 0) { $info = self::$INFO_STUB; return false; } $key = "{$typeID}_{$ID}"; if($checkPermissions && !CCrmAuthorizationHelper::CheckReadPermission($typeID, $ID)) { $info = self::$INFO_STUB; return false; } if(isset(self::$INFOS[$key])) { if(is_array(self::$INFOS[$key])) { $info = self::$INFOS[$key]; return true; } else { $info = self::$INFO_STUB; return false; } } switch($typeID) { case self::Lead: { $dbRes = CCrmLead::GetListEx( array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'HONORIFIC', 'TITLE', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'ASSIGNED_BY_ID') ); $arRes = $dbRes ? $dbRes->Fetch() : null; if(!is_array($arRes)) { self::$INFOS[$key] = false; $info = self::$INFO_STUB; return false; } self::$INFOS[$key] = array( 'TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'LEGEND' => CCrmLead::PrepareFormattedName($arRes), 'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0, 'IMAGE_FILE_ID' => 0, 'SHOW_URL' => self::GetEntityShowPath(self::Lead, $ID), 'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Lead), ); $info = self::$INFOS[$key]; return true; } case self::Contact: { $dbRes = CCrmContact::GetListEx( array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'COMPANY_ID', 'COMPANY_TITLE', 'PHOTO', 'ASSIGNED_BY_ID') ); $arRes = $dbRes ? $dbRes->Fetch() : null; if(!is_array($arRes)) { self::$INFOS[$key] = false; $info = self::$INFO_STUB; return false; } self::$INFOS[$key] = array( 'TITLE' => CCrmContact::PrepareFormattedName($arRes), 'LEGEND' => isset($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '', 'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0, 'IMAGE_FILE_ID' => isset($arRes['PHOTO']) ? intval($arRes['PHOTO']) : 0, 'SHOW_URL' => self::GetEntityShowPath(self::Contact, $ID), 'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Contact), ); $info = self::$INFOS[$key]; return true; } case self::Company: { $dbRes = CCrmCompany::GetListEx( array(), array( '=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'TITLE', 'COMPANY_TYPE', 'INDUSTRY', 'LOGO', 'ASSIGNED_BY_ID') ); $arRes = $dbRes ? $dbRes->Fetch() : null; if(!is_array($arRes)) { self::$INFOS[$key] = false; $info = self::$INFO_STUB; return false; } if(self::$COMPANY_TYPE === null) { self::$COMPANY_TYPE = CCrmStatus::GetStatusList('COMPANY_TYPE'); } if(self::$COMPANY_INDUSTRY === null) { self::$COMPANY_INDUSTRY = CCrmStatus::GetStatusList('INDUSTRY'); } $legendParts = array(); $typeID = isset($arRes['COMPANY_TYPE']) ? $arRes['COMPANY_TYPE'] : ''; if($typeID !== '' && isset(self::$COMPANY_TYPE[$typeID])) { $legendParts[] = self::$COMPANY_TYPE[$typeID]; } $industryID = isset($arRes['INDUSTRY']) ? $arRes['INDUSTRY'] : ''; if($industryID !== '' && isset(self::$COMPANY_INDUSTRY[$industryID])) { $legendParts[] = self::$COMPANY_INDUSTRY[$industryID]; } self::$INFOS[$key] = array( 'TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'LEGEND' => !empty($legendParts) ? implode(', ', $legendParts) : '', 'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0, 'IMAGE_FILE_ID' => isset($arRes['LOGO']) ? intval($arRes['LOGO']) : 0, 'SHOW_URL' => self::GetEntityShowPath(self::Company, $ID), 'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Company), ); $info = self::$INFOS[$key]; return true; } case self::DealRecurring: case self::Deal: { $dbRes = CCrmDeal::GetListEx( array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('TITLE', 'ASSIGNED_BY_ID', 'DATE_CREATE', 'OPPORTUNITY', 'CURRENCY_ID') ); $arRes = $dbRes ? $dbRes->Fetch() : null; if(!is_array($arRes)) { self::$INFOS[$key] = false; $info = self::$INFO_STUB; return false; } $date = new Bitrix\Main\Type\Date($arRes['DATE_CREATE']); self::$INFOS[$key] = array( 'TITLE' => $arRes['TITLE'], 'LEGEND' => GetMessage('CRM_OWNER_TYPE_DEAL_LEGEND', [ "#DATE_CREATE#" => FormatDate( Bitrix\Main\Context::getCurrent()->getCulture()->getLongDateFormat(), $date->getTimestamp() ), "#SUM_WITH_CURRENCY#" => \CCrmCurrency::MoneyToString( $arRes['OPPORTUNITY'], $arRes['CURRENCY_ID'] ), ]), 'OPPORTUNITY' => $arRes['OPPORTUNITY'], 'CURRENCY_ID' => $arRes['CURRENCY_ID'], 'DATE_CREATE' => $arRes['DATE_CREATE'], 'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0, 'IMAGE_FILE_ID' => 0, 'SHOW_URL' => self::GetEntityShowPath(self::Deal, $ID), 'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Deal), ); $info = self::$INFOS[$key]; return true; } case self::Invoice: { $dbRes = CCrmInvoice::GetList( array(), array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ORDER_TOPIC', 'RESPONSIBLE_ID') ); $arRes = $dbRes ? $dbRes->Fetch() : null; if(!is_array($arRes)) { self::$INFOS[$key] = false; $info = self::$INFO_STUB; return false; } self::$INFOS[$key] = array( 'TITLE' => isset($arRes['ORDER_TOPIC']) ? $arRes['ORDER_TOPIC'] : '', 'LEGEND' => '', 'RESPONSIBLE_ID' => isset($arRes['RESPONSIBLE_ID']) ? intval($arRes['RESPONSIBLE_ID']) : 0, 'IMAGE_FILE_ID' => 0, 'SHOW_URL' => static::GetEntityShowPath(static::Invoice, $ID), 'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Invoice), ); $info = self::$INFOS[$key]; return true; } case self::Quote: { $dbRes = CCrmQuote::GetList( array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('TITLE', 'ASSIGNED_BY_ID') ); $arRes = $dbRes ? $dbRes->Fetch() : null; if(!is_array($arRes)) { self::$INFOS[$key] = false; $info = self::$INFO_STUB; return false; } self::$INFOS[$key] = array( 'TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'LEGEND' => '', 'RESPONSIBLE_ID' => isset($arRes['ASSIGNED_BY_ID']) ? intval($arRes['ASSIGNED_BY_ID']) : 0, 'IMAGE_FILE_ID' => 0, 'SHOW_URL' => static::GetEntityShowPath(self::Quote, $ID), 'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Quote), ); $info = self::$INFOS[$key]; return true; } case self::Order: { $result = \Bitrix\Crm\Order\Order::getList( array( 'filter' => array('=ID' => $ID), 'select' => array('ACCOUNT_NUMBER', 'CREATED_BY', 'RESPONSIBLE_ID'), 'limit' => 1 ) ); $result = $result ? $result->fetch() : null; if(!is_array($result)) { self::$INFOS[$key] = false; $info = self::$INFO_STUB; return false; } self::$INFOS[$key] = array( 'TITLE' => isset($result['ACCOUNT_NUMBER']) ? $result['ACCOUNT_NUMBER'] : '', 'LEGEND' => '', 'RESPONSIBLE_ID' => isset($result['RESPONSIBLE_ID']) ? (int)($result['CREATED_BY']) : 0, 'IMAGE_FILE_ID' => 0, 'SHOW_URL' => Service\Sale\EntityLinkBuilder\EntityLinkBuilder::getInstance() ->getOrderDetailsLink($ID), 'ENTITY_TYPE_CAPTION' => static::GetDescription(static::Order), ); $info = self::$INFOS[$key]; return true; } default: $factory = Container::getInstance()->getFactory($typeID); if ($factory) { $item = $factory->getItems([ 'select' => [ \Bitrix\Crm\Item::FIELD_NAME_ID, \Bitrix\Crm\Item::FIELD_NAME_TITLE, \Bitrix\Crm\Item::FIELD_NAME_ASSIGNED, ], 'filter' => [ '=' . \Bitrix\Crm\Item::FIELD_NAME_ID => $ID, ] ])[0] ?? null; if ($item) { $info = [ 'TITLE' => $item->getHeading(), 'LEGEND' => '', 'RESPONSIBLE_ID' => $item->getAssignedById(), 'IMAGE_FILE_ID' => 0, 'SHOW_URL' => Container::getInstance()->getRouter()->getItemDetailUrl( $factory->getEntityTypeId(), $item->getId() ), 'ENTITY_TYPE_CAPTION' => $factory->getEntityDescription(), ]; self::$INFOS[$key] = $info; return true; } } } $info = self::$INFO_STUB; return false; }