X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FContact.php;h=e057dafd4a8c20859b3ec7057be7ea3f92493673;hb=fedc34282dbad5d2af77cb28585bae41eeb7d1c0;hp=7f834eb93fab5ffe969a5e087cd8c8853433c33d;hpb=0ac9d0bf0e8e29161e9080a3c79d5044e5d1a8b9;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 7f834eb93f..e057dafd4a 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -3371,8 +3371,8 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) * Ensures that is_primary gets assigned to another object if available * Also calls pre/post hooks * - * @var object $type - * @var int $id + * @param string $type + * @param int $id * @return bool */ public static function deleteObjectWithPrimary($type, $id) { @@ -3426,4 +3426,53 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) return $clauses; } + /** + * Get any existing duplicate contacts based on the input parameters. + * + * @param array $input + * Input parameters to be matched. + * @param string $contactType + * @param string $rule + * - Supervised + * - Unsupervised + * @param $excludedContactIDs + * An array of ids not to be included in the results. + * @param bool $checkPermissions + * @param int $ruleGroupID + * ID of the rule group to be used if an override is desirable. + * + * @return array + */ + public static function getDuplicateContacts($input, $contactType, $rule = 'Unsupervised', $excludedContactIDs = array(), $checkPermissions = TRUE, $ruleGroupID = NULL) { + $dedupeParams = CRM_Dedupe_Finder::formatParams($input, $contactType); + $dedupeParams['check_permission'] = $checkPermissions; + $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $contactType, $rule, $excludedContactIDs, $ruleGroupID); + return $ids; + } + + /** + * Get the first duplicate contacts based on the input parameters. + * + * @param array $input + * Input parameters to be matched. + * @param string $contactType + * @param string $rule + * - Supervised + * - Unsupervised + * @param $excludedContactIDs + * An array of ids not to be included in the results. + * @param bool $checkPermissions + * @param int $ruleGroupID + * ID of the rule group to be used if an override is desirable. + * + * @return int|NULL + */ + public static function getFirstDuplicateContact($input, $contactType, $rule = 'Unsupervised', $excludedContactIDs = array(), $checkPermissions = TRUE, $ruleGroupID = NULL) { + $ids = self::getDuplicateContacts($input, $contactType, $rule, $excludedContactIDs, $checkPermissions, $ruleGroupID); + if (empty($ids)) { + return NULL; + } + return $ids[0]; + } + }