Пример #1
0
 private function createDuplicate(array &$fields)
 {
     $rootEntityID = isset($fields['ROOT_ENTITY_ID']) ? (int) $fields['ROOT_ENTITY_ID'] : 0;
     $typeID = isset($fields['TYPE_ID']) ? (int) $fields['TYPE_ID'] : 0;
     $matches = isset($fields['MATCHES']) ? $fields['MATCHES'] : '';
     $matches = $matches !== '' ? unserialize($matches) : array();
     $quantity = isset($fields['QUANTITY']) ? (int) $fields['QUANTITY'] : 0;
     $result = new Duplicate(DuplicateManager::createCriterion($typeID, $matches), array());
     $result->setRootEntityID($rootEntityID);
     $isJunk = isset($fields['IS_JUNK']) && strtoupper($fields['IS_JUNK']) === 'Y';
     if ($isJunk) {
         $result->markAsJunk(true);
         //Try to supply more information for junked item (if root entity is already deleted)
         $rootPersName = isset($fields['ROOT_ENTITY_NAME']) ? $fields['ROOT_ENTITY_NAME'] : '';
         if ($rootPersName !== '') {
             $names = explode(' ', $rootPersName);
             $qty = count($names);
             for ($i = 0; $i < $qty; $i++) {
                 $names[$i] = ucfirst($names[$i]);
             }
             $result->setRootPersonName(implode(' ', $names));
         }
         $rootOrgTitle = isset($fields['ROOT_ENTITY_TITLE']) ? $fields['ROOT_ENTITY_TITLE'] : '';
         if ($rootOrgTitle !== '') {
             $result->setRootOrganizationTitle(ucfirst($rootOrgTitle));
         }
     }
     $result->setTotalEntityCount($quantity);
     return $result;
 }