public function findDuplicates(Crm\EntityAdapter $adapter, DuplicateSearchParams $params)
 {
     $result = array();
     $fieldNames = $params->getFieldNames();
     $processAllFields = empty($fieldNames);
     $title = $processAllFields || in_array('TITLE', $fieldNames, true) ? $adapter->getFieldValue('TITLE', '') : '';
     if ($title !== '') {
         $criterion = new DuplicateOrganizationCriterion($title);
         $criterion->setStrictComparison($this->useStrictComparison);
         $duplicate = $criterion->find();
         if ($duplicate !== null) {
             $result[] = $duplicate;
         }
     }
     if ($processAllFields || in_array('FM.PHONE', $fieldNames, true)) {
         $phones = $this->findMultifieldDuplicates('PHONE', $adapter, $params);
         if (!empty($phones)) {
             $result = array_merge($result, $phones);
         }
     }
     if ($processAllFields || in_array('FM.EMAIL', $fieldNames, true)) {
         $email = $this->findMultifieldDuplicates('EMAIL', $adapter, $params);
         if (!empty($email)) {
             $result = array_merge($result, $email);
         }
     }
     return $result;
 }
 public function findDuplicates(Crm\EntityAdapter $adapter, DuplicateSearchParams $params)
 {
     $result = array();
     $fieldNames = $params->getFieldNames();
     $processAllFields = empty($fieldNames);
     $lastName = $processAllFields || in_array('LAST_NAME', $fieldNames, true) ? $adapter->getFieldValue('LAST_NAME', '') : '';
     if ($lastName !== '') {
         $name = $processAllFields || in_array('NAME', $fieldNames, true) ? $adapter->getFieldValue('NAME', '') : '';
         $secondName = $processAllFields || in_array('SECOND_NAME', $fieldNames, true) ? $adapter->getFieldValue('SECOND_NAME', '') : '';
         $criterion = new DuplicatePersonCriterion($lastName, $name, $secondName);
         $duplicate = $criterion->find(\CCrmOwnerType::Undefined, 20);
         if ($duplicate !== null) {
             $result[] = $duplicate;
         }
     }
     if ($processAllFields || in_array('FM.PHONE', $fieldNames, true)) {
         $phones = $this->findMultifieldDuplicates('PHONE', $adapter, $params);
         if (!empty($phones)) {
             $result = array_merge($result, $phones);
         }
     }
     if ($processAllFields || in_array('FM.EMAIL', $fieldNames, true)) {
         $email = $this->findMultifieldDuplicates('EMAIL', $adapter, $params);
         if (!empty($email)) {
             $result = array_merge($result, $email);
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 public function findMultifieldDuplicates($type, \Bitrix\Crm\EntityAdapter $adapter, DuplicateSearchParams $params)
 {
     if (!is_string($type)) {
         throw new Main\ArgumentTypeException('type', 'string');
     }
     if ($type !== 'EMAIL' && $type !== 'PHONE') {
         throw new Main\NotSupportedException("Type: '{$type}' is not supported in current context");
     }
     $allMultiFields = $adapter->getFieldValue('FM');
     $multiFields = is_array($allMultiFields) && isset($allMultiFields[$type]) ? $allMultiFields[$type] : null;
     if (!is_array($multiFields) || empty($multiFields)) {
         return array();
     }
     $criterions = array();
     $dups = array();
     foreach ($multiFields as &$multiField) {
         $value = isset($multiField['VALUE']) ? $multiField['VALUE'] : '';
         if ($value === '') {
             continue;
         }
         $criterion = new DuplicateCommunicationCriterion($type, $value);
         $isExists = false;
         foreach ($criterions as $curCriterion) {
             /** @var DuplicateCriterion $curCriterion */
             if ($criterion->equals($curCriterion)) {
                 $isExists = true;
                 break;
             }
         }
         if ($isExists) {
             continue;
         }
         $criterions[] = $criterion;
         $duplicate = $criterion->find();
         if ($duplicate !== null) {
             $dups[] = $duplicate;
         }
     }
     unset($multiField);
     return $dups;
 }
Exemplo n.º 4
0
 public static function create(array $fields = null, $sourceEntityTypeID = \CCrmOwnerType::Undefined, $destinationEntityTypeID = \CCrmOwnerType::Undefined)
 {
     if (!is_int($sourceEntityTypeID)) {
         throw new Main\ArgumentTypeException('sourceEntityTypeID', 'integer');
     }
     if (!is_int($destinationEntityTypeID)) {
         throw new Main\ArgumentTypeException('destinationEntityTypeID', 'integer');
     }
     if ($sourceEntityTypeID !== \CCrmOwnerType::Undefined && !\CCrmOwnerType::IsDefined($sourceEntityTypeID)) {
         $sourceEntityTypeID = \CCrmOwnerType::Undefined;
     }
     if ($destinationEntityTypeID !== \CCrmOwnerType::Undefined && !\CCrmOwnerType::IsDefined($destinationEntityTypeID)) {
         $destinationEntityTypeID = \CCrmOwnerType::Undefined;
     }
     if (\CCrmOwnerType::IsDefined($sourceEntityTypeID) && !\CCrmOwnerType::IsDefined($destinationEntityTypeID)) {
         $destinationEntityTypeID = $sourceEntityTypeID;
     }
     $adapter = null;
     if ($sourceEntityTypeID !== \CCrmOwnerType::Undefined && $destinationEntityTypeID !== \CCrmOwnerType::Undefined) {
         if ($sourceEntityTypeID === \CCrmOwnerType::Lead) {
             if ($destinationEntityTypeID === \CCrmOwnerType::Company) {
                 $adapter = new EntityAdapter(\CCrmOwnerType::Lead, \CCrmOwnerType::Company, new Mapper(array('COMPANY_TITLE' => 'TITLE')));
             }
         } elseif ($sourceEntityTypeID === \CCrmOwnerType::Company) {
             if ($destinationEntityTypeID === \CCrmOwnerType::Lead) {
                 $adapter = new EntityAdapter(\CCrmOwnerType::Company, \CCrmOwnerType::Lead, new Mapper(array('TITLE' => 'COMPANY_TITLE')));
             }
         }
     }
     if ($adapter === null) {
         $adapter = new EntityAdapter($sourceEntityTypeID, $destinationEntityTypeID);
     }
     if ($fields !== null) {
         $adapter->setFields($fields);
     }
     return $adapter;
 }