$sortBy = 'ORGANIZATION'; } else { $sortTypeID = Integrity\DuplicateIndexType::PERSON; $sortBy = 'PERSON'; } } $arResult['SORT_TYPE_ID'] = $sortTypeID; $arResult['SORT_BY'] = $sortBy; $sortOrder = $arResult['SORT_ORDER'] = isset($_GET['sortOrder']) && strtoupper($_GET['sortOrder']) === 'DESC' ? SORT_DESC : SORT_ASC; if (empty($selectedTypes)) { $arResult['ITEMS'] = array(); $arResult['ENTITY_INFOS'] = array(); $arResult['HAS_PREV_PAGE'] = false; $arResult['HAS_NEXT_PAGE'] = false; } else { $list = new Integrity\DuplicateList(Integrity\DuplicateIndexType::joinType(array_keys($selectedTypes)), $entityTypeID, $userID, $enablePermissionCheck); $list->setSortTypeID($sortTypeID); $list->setSortOrder($sortOrder); $items = $list->getRootItems(($pageNum - 1) * $itemsPerPage, $itemsPerPage + 1); if (count($items) <= $itemsPerPage) { $arResult['HAS_NEXT_PAGE'] = false; } else { $arResult['HAS_NEXT_PAGE'] = true; array_pop($items); } $arResult['HAS_PREV_PAGE'] = $pageNum > 1; $arResult['ITEMS'] = $items; $entityInfos = array(); /** @var Integrity\Duplicate $item **/ foreach ($items as $item) { $entityID = $item->getRootEntityID();
if (!CCrmAuthorizationHelper::CheckReadPermission($entityTypeName, 0)) { __CrmDedupeListEndResonse(array('ERROR' => 'Access denied.')); } $rootEntityID = isset($_POST['ROOT_ENTITY_ID']) ? (int) $_POST['ROOT_ENTITY_ID'] : 0; $typeID = isset($_POST['INDEX_TYPE_NAME']) ? Integrity\DuplicateIndexType::resolveID($_POST['INDEX_TYPE_NAME']) : Integrity\DuplicateIndexType::UNDEFINED; $layoutName = isset($_POST['LAYOUT_NAME']) ? $_POST['LAYOUT_NAME'] : ''; $layoutID = CCrmOwnerType::ResolveID($layoutName); $matches = isset($_POST['INDEX_MATCHES']) && is_array($_POST['INDEX_MATCHES']) ? $_POST['INDEX_MATCHES'] : array(); if (empty($matches)) { __CrmDedupeListEndResonse(array('ERROR' => 'Matches is not defined.')); } $enableRanking = isset($_POST['ENABLE_RANKING']) && strtoupper($_POST['ENABLE_RANKING']) === 'Y'; $enablePermissionCheck = !CCrmPerms::IsAdmin($currentUserID); $entityInfos = array(); $criterion = Integrity\DuplicateManager::createCriterion($typeID, $matches); $list = new Integrity\DuplicateList($typeID, $entityTypeID, $currentUserID, $enablePermissionCheck); if ($list->isJunk($rootEntityID)) { $result = array('INDEX_TYPE_NAME' => Integrity\DuplicateIndexType::resolveName($typeID), 'ENTITY_TYPE_NAME' => $entityTypeName, 'ENTITY_INFOS' => array(), 'TEXT_TOTALS' => GetMessage("CRM_DEDUPE_LIST_JUNK")); __CrmDedupeListEndResonse($result); } $dup = $criterion->createDuplicate($entityTypeID, $rootEntityID, $currentUserID, $enablePermissionCheck, $enableRanking, 50); if ($dup) { $entities = $dup->getEntitiesByType($entityTypeID); foreach ($entities as $entity) { $entityID = $entity->getEntityID(); $info = array('ID' => $entityID); $entityCriterion = $entity->getCriterion(); if ($entityCriterion !== null) { $info['INDEX_MATCHES'] = $entityCriterion->getMatches(); } if (!$enablePermissionCheck) {