Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Development
WordPress
Commits
c732abb6
Unverified
Commit
c732abb6
authored
Sep 09, 2021
by
kcristiano
Committed by
GitHub
Sep 09, 2021
Browse files
Merge pull request #256 from christianwach/qa-dedupe
Add deduping to Quick Add Dashboard Widget
parents
c9b43e19
7800e9ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
includes/admin-metaboxes/civicrm.metabox.contact.add.php
View file @
c732abb6
...
...
@@ -473,15 +473,27 @@ class CiviCRM_For_WordPress_Admin_Metabox_Contact_Add {
wp_send_json
(
$data
);
}
// Build params to create Contact.
$params
=
[
'version'
=>
3
,
'contact_type'
=>
'Individual'
,
// Build params to check for an existing Contact.
$contact
=
[
'first_name'
=>
$data
[
'first_name'
],
'last_name'
=>
$data
[
'last_name'
],
'email'
=>
$data
[
'email'
],
];
// Bail if there is an existing Contact.
$existing_id
=
civi_wp
()
->
admin
->
get_by_dedupe_unsupervised
(
$contact
);
if
(
$existing_id
!==
FALSE
&&
$existing_id
!==
0
)
{
$open
=
'<a href="'
.
$this
->
civi
->
admin
->
get_admin_link
(
'civicrm/contact/view'
,
'reset=1&cid='
.
$existing_id
)
.
'">'
;
$data
[
'notice'
]
=
sprintf
(
__
(
'There seems to be %1$san existing Contact%2$s with these details.'
,
'civicrm'
),
$open
,
'</a>'
);
wp_send_json
(
$data
);
}
// Build params to create Contact.
$params
=
[
'version'
=>
3
,
'contact_type'
=>
'Individual'
,
]
+
$contact
;
// Call the API.
$result
=
civicrm_api
(
'Contact'
,
'create'
,
$params
);
...
...
includes/civicrm.admin.php
View file @
c732abb6
...
...
@@ -863,4 +863,42 @@ class CiviCRM_For_WordPress_Admin {
}
/**
* Gets a suggested CiviCRM Contact ID via the "Unsupervised" Dedupe Rule.
*
* @since 5.43
*
* @param array $contact The array of CiviCRM Contact data.
* @param string $contact_type The Contact Type.
* @return integer|bool $contact_id The suggested Contact ID, or false on failure.
*/
public
function
get_by_dedupe_unsupervised
(
$contact
,
$contact_type
=
'Individual'
)
{
if
(
empty
(
$contact
))
{
return
FALSE
;
}
if
(
!
$this
->
civi
->
initialize
())
{
return
FALSE
;
}
// Get the Dedupe params.
$dedupe_params
=
CRM_Dedupe_Finder
::
formatParams
(
$contact
,
$contact_type
);
$dedupe_params
[
'check_permission'
]
=
FALSE
;
// Use Dedupe Rules to find possible Contact IDs.
$contact_ids
=
CRM_Dedupe_Finder
::
dupesByParams
(
$dedupe_params
,
$contact_type
,
'Unsupervised'
);
// Return the suggested Contact ID if present.
$contact_id
=
0
;
if
(
!
empty
(
$contact_ids
))
{
$contact_ids
=
array_reverse
(
$contact_ids
);
$contact_id
=
(
int
)
array_pop
(
$contact_ids
);
}
// --<
return
$contact_id
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment