...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integrity/actualentityselector.php
- Класс: Bitrix\Crm\Integrity\ActualEntitySelector
- Вызов: ActualEntitySelector::setEntity
public function setEntity($entityTypeId, $entityId, $skipRanking = false) { $entityTypeId = (int)$entityTypeId; $entityId = (int)$entityId; $isEntityTypeDynamics = \CCrmOwnerType::isUseDynamicTypeBasedApproach($entityTypeId); foreach($this->entities as $entity) { if (empty($entity['IS_PRIMARY'])) { continue; } if ($entity['TYPE_ID'] !== $entityTypeId) { if (!$isEntityTypeDynamics || $entity['CODE'] !== 'dynamics') { continue; } } // check with lead type if ($entityTypeId === \CCrmOwnerType::Lead) { $isCurrentLeadRC = $entity['CODE'] == 'returnCustomerLeads'; $leadRow = LeadTable::getRow([ 'select' => ['ID', 'IS_RETURN_CUSTOMER', 'CONTACT_ID', 'COMPANY_ID'], 'filter' => ['=ID' => $entityId] ]); $isLeadRC = $leadRow['IS_RETURN_CUSTOMER'] === 'Y'; if ($isCurrentLeadRC != $isLeadRC) { continue; } if ($isLeadRC) { if ($leadRow['CONTACT_ID'] && !$this->getContactId()) { $this->setEntity(\CCrmOwnerType::Contact, $leadRow['CONTACT_ID'], true); } if ($leadRow['COMPANY_ID'] && !$this->getCompanyId()) { $this->setEntity(\CCrmOwnerType::Company, $leadRow['COMPANY_ID'], true); } } $skipRanking = true; } elseif ($entityTypeId === \CCrmOwnerType::Deal) { $dealRows = DealTable::getList([ 'select' => ['ID', 'CONTACT_ID', 'COMPANY_ID'], 'filter' => ['=ID' => $entityId], 'limit' => 3 ]); foreach ($dealRows as $dealRow) { if ($dealRow['CONTACT_ID'] && !$this->getContactId()) { $this->setEntity(\CCrmOwnerType::Contact, $dealRow['CONTACT_ID'], true); } if ($dealRow['COMPANY_ID'] && !$this->getCompanyId()) { $this->setEntity(\CCrmOwnerType::Company, $dealRow['COMPANY_ID'], true); } } $skipRanking = true; } elseif ($entityTypeId === \CCrmOwnerType::Order) { $orderRows = OrderContactCompanyTable::getList([ 'select' => ['ENTITY_TYPE_ID', 'ENTITY_ID'], 'filter' => [ '=ORDER_ID' => $entityId, '=IS_PRIMARY' => 'Y', '=ENTITY_TYPE_ID' => [\CCrmOwnerType::Contact, \CCrmOwnerType::Company], ], 'limit' => 3 ]); foreach ($orderRows as $orderRow) { if ($orderRow['ENTITY_TYPE_ID'] == \CCrmOwnerType::Contact && !$this->getContactId()) { $this->setEntity(\CCrmOwnerType::Contact, $orderRow['ENTITY_ID'], true); } if ($orderRow['ENTITY_TYPE_ID'] == \CCrmOwnerType::Company && !$this->getCompanyId()) { $this->setEntity(\CCrmOwnerType::Company, $orderRow['ENTITY_ID'], true); } } $skipRanking = true; } elseif ($isEntityTypeDynamics) { $dynamicFactory = Crm\Service\Container::getInstance()->getFactory($entityTypeId); $dynamicItem = $dynamicFactory->getItem($entityId); if (!$dynamicItem) { continue; } $this->setDynamicTypeId($entityTypeId); if ($dynamicItem->getCompanyId()) { $this->setEntity(\CCrmOwnerType::Company, $dynamicItem->getCompanyId(), true); } $count = 3; foreach ($dynamicItem->getContacts() as $contact) { $this->setEntity(\CCrmOwnerType::Contact, $contact->getId(), true); if (!--$count) { break; } } $skipRanking = true; } $this->set($entity['CODE'], $entityId, [ 'skipRanking' => $skipRanking, 'skipDuplicates' => true, ] ); } return $this; }