コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }
コード例 #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;
 }