3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM contacts.
31 * Contacts are the main entity in CiviCRM and this api is more robust than most.
32 * - Get action allows all params supported by advanced search.
33 * - Create action allows creating several related entities at once (e.g. email).
34 * - Create allows checking for duplicate contacts.
35 * Use getfields to list the full range of parameters and options supported by each action.
37 * @package CiviCRM_APIv3
41 * Create or update a Contact.
43 * @param array $params
46 * @throws API_Exception
51 function civicrm_api3_contact_create($params) {
52 $contactID = CRM_Utils_Array
::value('contact_id', $params, CRM_Utils_Array
::value('id', $params));
54 if ($contactID && !empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::EDIT
)) {
55 throw new \Civi\API\Exception\
UnauthorizedException('Permission denied to modify contact record');
58 if (!empty($params['dupe_check'])) {
59 $ids = CRM_Contact_BAO_Contact
::getDuplicateContacts($params, $params['contact_type'], 'Unsupervised', array(), $params['check_permission']);
60 if (count($ids) > 0) {
61 throw new API_Exception("Found matching contacts: " . implode(',', $ids), "duplicate", array("ids" => $ids));
65 $values = _civicrm_api3_contact_check_params($params);
70 if (array_key_exists('api_key', $params) && !empty($params['check_permissions'])) {
71 if (CRM_Core_Permission
::check('edit api keys') || CRM_Core_Permission
::check('administer CiviCRM')) {
74 elseif ($contactID && CRM_Core_Permission
::check('edit own api keys') && CRM_Core_Session
::singleton()->get('userID') == $contactID) {
78 throw new \Civi\API\Exception\
UnauthorizedException('Permission denied to modify api key');
83 // If we get here, we're ready to create a new contact
84 if (($email = CRM_Utils_Array
::value('email', $params)) && !is_array($params['email'])) {
85 $defLocType = CRM_Core_BAO_LocationType
::getDefault();
86 $params['email'] = array(
90 'location_type_id' => ($defLocType->id
) ?
$defLocType->id
: 1,
96 if (!empty($params['home_url'])) {
97 $websiteTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Website', 'website_type_id');
98 $params['website'] = array(
100 'website_type_id' => key($websiteTypes),
101 'url' => $params['home_url'],
106 _civicrm_api3_greeting_format_params($params);
110 if (empty($params['contact_type']) && $contactID) {
111 $params['contact_type'] = CRM_Contact_BAO_Contact
::getContactType($contactID);
114 if (!isset($params['contact_sub_type']) && $contactID) {
115 $params['contact_sub_type'] = CRM_Contact_BAO_Contact
::getContactSubType($contactID);
118 _civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $contactID);
120 $params = array_merge($params, $values);
121 //@todo we should just call basic_create here - but need to make contact:create accept 'id' on the bao
122 $contact = _civicrm_api3_contact_update($params, $contactID);
124 if (is_a($contact, 'CRM_Core_Error')) {
125 throw new API_Exception($contact->_errors
[0]['message']);
129 _civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id
]);
132 $values = _civicrm_api3_contact_formatResult($params, $values);
134 return civicrm_api3_create_success($values, $params, 'Contact', 'create');
138 * Adjust Metadata for Create action.
140 * @param array $params
141 * Array of parameters determined by getfields.
143 function _civicrm_api3_contact_create_spec(&$params) {
144 $params['contact_type']['api.required'] = 1;
145 $params['id']['api.aliases'] = array('contact_id');
146 $params['current_employer'] = array(
147 'title' => 'Current Employer',
148 'description' => 'Name of Current Employer',
149 'type' => CRM_Utils_Type
::T_STRING
,
151 $params['dupe_check'] = array(
152 'title' => 'Check for Duplicates',
153 'description' => 'Throw error if contact create matches dedupe rule',
154 'type' => CRM_Utils_Type
::T_BOOLEAN
,
156 $params['skip_greeting_processing'] = array(
157 'title' => 'Skip Greeting processing',
158 'description' => 'Do not process greetings, (these can be done by scheduled job and there may be a preference to do so for performance reasons)',
159 'type' => CRM_Utils_Type
::T_BOOLEAN
,
162 $params['prefix_id']['api.aliases'] = array('individual_prefix', 'individual_prefix_id');
163 $params['suffix_id']['api.aliases'] = array('individual_suffix', 'individual_suffix_id');
164 $params['gender_id']['api.aliases'] = array('gender');
168 * Retrieve one or more contacts, given a set of search params.
170 * @param array $params
175 function civicrm_api3_contact_get($params) {
177 _civicrm_api3_contact_get_supportanomalies($params, $options);
178 $contacts = _civicrm_api3_get_using_query_object('Contact', $params, $options);
179 $contacts = _civicrm_api3_contact_formatResult($params, $contacts);
180 return civicrm_api3_create_success($contacts, $params, 'Contact');
186 * @param array $result
189 * @throws \CRM_Core_Exception
191 function _civicrm_api3_contact_formatResult($params, $result) {
192 $apiKeyPerms = array('edit api keys', 'administer CiviCRM');
193 $allowApiKey = empty($params['check_permissions']) || CRM_Core_Permission
::check(array($apiKeyPerms));
195 if (is_array($result)) {
196 // Single-value $result
197 if (isset($result['api_key'])) {
198 unset($result['api_key']);
201 // Multi-value $result
202 foreach ($result as $key => $row) {
203 if (is_array($row)) {
204 unset($result[$key]['api_key']);
213 * Get number of contacts matching the supplied criteria.
215 * @param array $params
219 function civicrm_api3_contact_getcount($params) {
221 _civicrm_api3_contact_get_supportanomalies($params, $options);
222 $count = _civicrm_api3_get_using_query_object('Contact', $params, $options, 1);
227 * Adjust Metadata for Get action.
229 * @param array $params
230 * Array of parameters determined by getfields.
232 function _civicrm_api3_contact_get_spec(&$params) {
233 $params['contact_is_deleted']['api.default'] = 0;
235 // We declare all these pseudoFields as there are other undocumented fields accessible
236 // via the api - but if check permissions is set we only allow declared fields
237 $params['address_id'] = array(
238 'title' => 'Primary Address ID',
239 'type' => CRM_Utils_Type
::T_INT
,
241 $params['street_address'] = array(
242 'title' => 'Primary Address Street Address',
243 'type' => CRM_Utils_Type
::T_STRING
,
245 $params['supplemental_address_1'] = array(
246 'title' => 'Primary Address Supplemental Address 1',
247 'type' => CRM_Utils_Type
::T_STRING
,
249 $params['supplemental_address_2'] = array(
250 'title' => 'Primary Address Supplemental Address 2',
251 'type' => CRM_Utils_Type
::T_STRING
,
253 $params['supplemental_address_3'] = array(
254 'title' => 'Primary Address Supplemental Address 3',
255 'type' => CRM_Utils_Type
::T_STRING
,
257 $params['current_employer'] = array(
258 'title' => 'Current Employer',
259 'type' => CRM_Utils_Type
::T_STRING
,
261 $params['city'] = array(
262 'title' => 'Primary Address City',
263 'type' => CRM_Utils_Type
::T_STRING
,
265 $params['postal_code_suffix'] = array(
266 'title' => 'Primary Address Post Code Suffix',
267 'type' => CRM_Utils_Type
::T_STRING
,
269 $params['postal_code'] = array(
270 'title' => 'Primary Address Post Code',
271 'type' => CRM_Utils_Type
::T_STRING
,
273 $params['geo_code_1'] = array(
274 'title' => 'Primary Address Latitude',
275 'type' => CRM_Utils_Type
::T_STRING
,
277 $params['geo_code_2'] = array(
278 'title' => 'Primary Address Longitude',
279 'type' => CRM_Utils_Type
::T_STRING
,
281 $params['state_province_id'] = array(
282 'title' => 'Primary Address State Province ID',
283 'type' => CRM_Utils_Type
::T_INT
,
284 'pseudoconstant' => array(
285 'table' => 'civicrm_state_province',
288 $params['state_province_name'] = array(
289 'title' => 'Primary Address State Province Name',
290 'type' => CRM_Utils_Type
::T_STRING
,
291 'pseudoconstant' => array(
292 'table' => 'civicrm_state_province',
295 $params['state_province'] = array(
296 'title' => 'Primary Address State Province',
297 'type' => CRM_Utils_Type
::T_STRING
,
298 'pseudoconstant' => array(
299 'table' => 'civicrm_state_province',
302 $params['country_id'] = array(
303 'title' => 'Primary Address Country ID',
304 'type' => CRM_Utils_Type
::T_INT
,
305 'pseudoconstant' => array(
306 'table' => 'civicrm_country',
309 $params['country'] = array(
310 'title' => 'Primary Address country',
311 'type' => CRM_Utils_Type
::T_STRING
,
312 'pseudoconstant' => array(
313 'table' => 'civicrm_country',
316 $params['worldregion_id'] = array(
317 'title' => 'Primary Address World Region ID',
318 'type' => CRM_Utils_Type
::T_INT
,
319 'pseudoconstant' => array(
320 'table' => 'civicrm_world_region',
323 $params['worldregion'] = array(
324 'title' => 'Primary Address World Region',
325 'type' => CRM_Utils_Type
::T_STRING
,
326 'pseudoconstant' => array(
327 'table' => 'civicrm_world_region',
330 $params['phone_id'] = array(
331 'title' => 'Primary Phone ID',
332 'type' => CRM_Utils_Type
::T_INT
,
334 $params['phone'] = array(
335 'title' => 'Primary Phone',
336 'type' => CRM_Utils_Type
::T_STRING
,
338 $params['phone_type_id'] = array(
339 'title' => 'Primary Phone Type ID',
340 'type' => CRM_Utils_Type
::T_INT
,
342 $params['provider_id'] = array(
343 'title' => 'Primary Phone Provider ID',
344 'type' => CRM_Utils_Type
::T_INT
,
346 $params['email_id'] = array(
347 'title' => 'Primary Email ID',
348 'type' => CRM_Utils_Type
::T_INT
,
350 $params['email'] = array(
351 'title' => 'Primary Email',
352 'type' => CRM_Utils_Type
::T_STRING
,
354 $params['on_hold'] = array(
355 'title' => 'Primary Email On Hold',
356 'type' => CRM_Utils_Type
::T_BOOLEAN
,
358 $params['im'] = array(
359 'title' => 'Primary Instant Messenger',
360 'type' => CRM_Utils_Type
::T_STRING
,
362 $params['im_id'] = array(
363 'title' => 'Primary Instant Messenger ID',
364 'type' => CRM_Utils_Type
::T_INT
,
366 $params['group'] = array(
368 'pseudoconstant' => array(
369 'table' => 'civicrm_group',
372 $params['tag'] = array(
374 'pseudoconstant' => array(
375 'table' => 'civicrm_tag',
378 $params['uf_user'] = array(
379 'title' => 'CMS User',
380 'type' => CRM_Utils_Type
::T_BOOLEAN
,
382 $params['birth_date_low'] = array('name' => 'birth_date_low', 'type' => CRM_Utils_Type
::T_DATE
, 'title' => ts('Birth Date is equal to or greater than'));
383 $params['birth_date_high'] = array('name' => 'birth_date_high', 'type' => CRM_Utils_Type
::T_DATE
, 'title' => ts('Birth Date is equal to or less than'));
384 $params['deceased_date_low'] = array('name' => 'deceased_date_low', 'type' => CRM_Utils_Type
::T_DATE
, 'title' => ts('Deceased Date is equal to or greater than'));
385 $params['deceased_date_high'] = array('name' => 'deceased_date_high', 'type' => CRM_Utils_Type
::T_DATE
, 'title' => ts('Deceased Date is equal to or less than'));
389 * Support for historical oddities.
391 * We are supporting 'showAll' = 'all', 'trash' or 'active' for Contact get
393 * - hopefully some day we'll come up with a std syntax for the 3-way-boolean of
396 * We also support 'filter_group_id' & 'filter.group_id'
398 * @param array $params
399 * As passed into api get or getcount function.
400 * @param array $options
401 * Array of options (so we can modify the filter).
403 function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
404 if (isset($params['showAll'])) {
405 if (strtolower($params['showAll']) == "active") {
406 $params['contact_is_deleted'] = 0;
408 if (strtolower($params['showAll']) == "trash") {
409 $params['contact_is_deleted'] = 1;
411 if (strtolower($params['showAll']) == "all" && isset($params['contact_is_deleted'])) {
412 unset($params['contact_is_deleted']);
415 // support for group filters
416 if (array_key_exists('filter_group_id', $params)) {
417 $params['filter.group_id'] = $params['filter_group_id'];
418 unset($params['filter_group_id']);
420 // filter.group_id works both for 1,2,3 and array (1,2,3)
421 if (array_key_exists('filter.group_id', $params)) {
422 if (is_array($params['filter.group_id'])) {
423 $groups = $params['filter.group_id'];
426 $groups = explode(',', $params['filter.group_id']);
428 unset($params['filter.group_id']);
429 $options['input_params']['group'] = $groups;
431 if (isset($params['group'])) {
432 $groups = $params['group'];
433 $allGroups = CRM_Core_PseudoConstant
::group();
434 if (is_array($groups) && in_array(key($groups), CRM_Core_DAO
::acceptedSQLOperators(), TRUE)) {
435 // Get the groups array.
436 $groupsArray = $groups[key($groups)];
437 foreach ($groupsArray as &$group) {
438 if (!is_numeric($group) && array_search($group, $allGroups)) {
439 $group = array_search($group, $allGroups);
442 // Now reset the $groups array with the ids not the titles.
443 $groups[key($groups)] = $groupsArray;
445 // handle format like 'group' => array('title1', 'title2').
446 elseif (is_array($groups)) {
447 foreach ($groups as $k => &$group) {
448 if (!is_numeric($group) && array_search($group, $allGroups)) {
449 $group = array_search($group, $allGroups);
451 if (!is_numeric($k) && array_search($k, $allGroups)) {
453 $groups[array_search($k, $allGroups)] = $group;
457 elseif (!is_numeric($groups) && array_search($groups, $allGroups)) {
458 $groups = array_search($groups, $allGroups);
460 $params['group'] = $groups;
465 * Delete a Contact with given contact_id.
467 * @param array $params
468 * input parameters per getfields
470 * @throws \Civi\API\Exception\UnauthorizedException
474 function civicrm_api3_contact_delete($params) {
475 $contactID = CRM_Utils_Array
::value('id', $params);
477 if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::DELETE
)) {
478 throw new \Civi\API\Exception\
UnauthorizedException('Permission denied to modify contact record');
481 $session = CRM_Core_Session
::singleton();
482 if ($contactID == $session->get('userID')) {
483 return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
485 $restore = !empty($params['restore']) ?
$params['restore'] : FALSE;
486 $skipUndelete = !empty($params['skip_undelete']) ?
$params['skip_undelete'] : FALSE;
489 // restrict permanent delete if a contact has financial trxn associated with it
491 if ($skipUndelete && CRM_Financial_BAO_FinancialItem
::checkContactPresent(array($contactID), $error)) {
492 return civicrm_api3_create_error($error['_qf_default']);
494 if (CRM_Contact_BAO_Contact
::deleteContact($contactID, $restore, $skipUndelete,
495 CRM_Utils_Array
::value('check_permissions', $params))) {
496 return civicrm_api3_create_success();
499 return civicrm_api3_create_error('Could not delete contact');
505 * Check parameters passed in.
507 * This function is on it's way out.
509 * @param array $params
512 * @throws API_Exception
513 * @throws CiviCRM_API3_Exception
515 function _civicrm_api3_contact_check_params(&$params) {
517 switch (strtolower(CRM_Utils_Array
::value('contact_type', $params))) {
519 civicrm_api3_verify_mandatory($params, NULL, array('household_name'));
523 civicrm_api3_verify_mandatory($params, NULL, array('organization_name'));
527 civicrm_api3_verify_one_mandatory($params, NULL, array(
537 if (!empty($params['contact_sub_type']) && !empty($params['contact_type'])) {
538 if (!(CRM_Contact_BAO_ContactType
::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
539 throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $params['contact_sub_type']));
543 // The BAO no longer supports the legacy param "current_employer" so here is a shim for api backward-compatability
544 if (!empty($params['current_employer'])) {
545 $organizationParams = array(
546 'organization_name' => $params['current_employer'],
549 $dupeIds = CRM_Contact_BAO_Contact
::getDuplicateContacts($organizationParams, 'Organization', 'Supervised', array(), FALSE);
551 // check for mismatch employer name and id
552 if (!empty($params['employer_id']) && !in_array($params['employer_id'], $dupeIds)) {
553 throw new API_Exception('Employer name and Employer id Mismatch');
556 // show error if multiple organisation with same name exist
557 if (empty($params['employer_id']) && (count($dupeIds) > 1)) {
558 throw new API_Exception('Found more than one Organisation with same Name.');
562 $params['employer_id'] = $dupeIds[0];
565 $result = civicrm_api3('Contact', 'create', array(
566 'organization_name' => $params['current_employer'],
567 'contact_type' => 'Organization',
569 $params['employer_id'] = $result['id'];
577 * Helper function for Contact create.
579 * @param array $params
580 * (reference ) an assoc array of name/value pairs.
581 * @param int $contactID
582 * If present the contact with that ID is updated.
584 * @return CRM_Contact_BAO_Contact|CRM_Core_Error
586 function _civicrm_api3_contact_update($params, $contactID = NULL) {
587 //@todo - doesn't contact create support 'id' which is already set- check & remove
589 $params['contact_id'] = $contactID;
592 return CRM_Contact_BAO_Contact
::create($params);
596 * Validate the addressee or email or postal greetings.
598 * @param array $params
599 * Array per getfields metadata.
601 * @throws API_Exception
603 function _civicrm_api3_greeting_format_params($params) {
604 $greetingParams = array('', '_id', '_custom');
605 foreach (array('email', 'postal', 'addressee') as $key) {
606 $greeting = '_greeting';
607 if ($key == 'addressee') {
611 $formatParams = FALSE;
612 // Unset display value from params.
613 if (isset($params["{$key}{$greeting}_display"])) {
614 unset($params["{$key}{$greeting}_display"]);
617 // check if greetings are present in present
618 foreach ($greetingParams as $greetingValues) {
619 if (array_key_exists("{$key}{$greeting}{$greetingValues}", $params)) {
620 $formatParams = TRUE;
625 if (!$formatParams) {
631 'greeting_type' => "{$key}{$greeting}",
634 $greetings = CRM_Core_PseudoConstant
::greeting($filter);
635 $greetingId = CRM_Utils_Array
::value("{$key}{$greeting}_id", $params);
636 $greetingVal = CRM_Utils_Array
::value("{$key}{$greeting}", $params);
637 $customGreeting = CRM_Utils_Array
::value("{$key}{$greeting}_custom", $params);
639 if (!$greetingId && $greetingVal) {
640 $params["{$key}{$greeting}_id"] = CRM_Utils_Array
::key($params["{$key}{$greeting}"], $greetings);
643 if ($customGreeting && $greetingId &&
644 ($greetingId != array_search('Customized', $greetings))
646 throw new API_Exception(ts('Provide either %1 greeting id and/or %1 greeting or custom %1 greeting',
651 if ($greetingVal && $greetingId &&
652 ($greetingId != CRM_Utils_Array
::key($greetingVal, $greetings))
654 throw new API_Exception(ts('Mismatch in %1 greeting id and %1 greeting',
660 if (!$customGreeting && ($greetingId == array_search('Customized', $greetings))) {
661 throw new API_Exception(ts('Please provide a custom value for %1 greeting',
666 elseif ($greetingVal) {
668 if (!in_array($greetingVal, $greetings)) {
669 throw new API_Exception(ts('Invalid %1 greeting', array(1 => $key)));
672 $greetingId = CRM_Utils_Array
::key($greetingVal, $greetings);
675 if ($customGreeting) {
676 $greetingId = CRM_Utils_Array
::key('Customized', $greetings);
679 $customValue = isset($params['contact_id']) ? CRM_Core_DAO
::getFieldValue(
680 'CRM_Contact_DAO_Contact',
681 $params['contact_id'],
682 "{$key}{$greeting}_custom"
685 if (array_key_exists("{$key}{$greeting}_id", $params) && empty($params["{$key}{$greeting}_id"])) {
688 elseif (array_key_exists("{$key}{$greeting}", $params) && empty($params["{$key}{$greeting}"])) {
691 elseif ($customValue && array_key_exists("{$key}{$greeting}_custom", $params)
692 && empty($params["{$key}{$greeting}_custom"])
697 $params["{$key}{$greeting}_id"] = $greetingId;
699 if (!$customValue && !$customGreeting && array_key_exists("{$key}{$greeting}_custom", $params)) {
700 unset($params["{$key}{$greeting}_custom"]);
704 $params["{$key}{$greeting}_id"] = '';
705 $params["{$key}{$greeting}_custom"] = '';
708 if (isset($params["{$key}{$greeting}"])) {
709 unset($params["{$key}{$greeting}"]);
715 * Adjust Metadata for Get action.
717 * @param array $params
718 * Array of parameters determined by getfields.
720 function _civicrm_api3_contact_getquick_spec(&$params) {
721 $params['name']['api.required'] = TRUE;
722 $params['name']['title'] = ts('String to search on');
723 $params['name']['type'] = CRM_Utils_Type
::T_STRING
;
724 $params['field']['type'] = CRM_Utils_Type
::T_STRING
;
725 $params['field']['title'] = ts('Field to search on');
726 $params['field']['options'] = array(
730 'external_identifier',
740 $params['table_name']['type'] = CRM_Utils_Type
::T_STRING
;
741 $params['table_name']['title'] = ts('Table alias to search on');
742 $params['table_name']['api.default'] = 'cc';
746 * Old Contact quick search api.
750 * @param array $params
753 * @throws \API_Exception
755 function civicrm_api3_contact_getquick($params) {
756 $name = CRM_Utils_Type
::escape(CRM_Utils_Array
::value('name', $params), 'String');
757 $table_name = CRM_Utils_String
::munge($params['table_name']);
758 // get the autocomplete options from settings
759 $acpref = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
760 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
761 'contact_autocomplete_options'
767 'phone_numeric' => 'phe',
768 'street_address' => 'sts',
770 'postal_code' => 'sts',
773 // get the option values for contact autocomplete
774 $acOptions = CRM_Core_OptionGroup
::values('contact_autocomplete_options', FALSE, FALSE, FALSE, NULL, 'name');
776 $list = $from = array();
777 foreach ($acpref as $value) {
778 if ($value && !empty($acOptions[$value])) {
779 $list[$value] = $acOptions[$value];
782 // If we are doing quicksearch by a field other than name, make sure that field is added to results
783 if (!empty($params['field_name'])) {
784 $field_name = CRM_Utils_String
::munge($params['field_name']);
785 // Unique name contact_id = id
786 if ($field_name == 'contact_id') {
789 if (isset($table_names[$field_name])) {
790 $table_name = $table_names[$field_name];
792 elseif (strpos($field_name, 'custom_') === 0) {
793 $customField = civicrm_api3('CustomField', 'getsingle', [
794 'id' => substr($field_name, 7),
795 'return' => ['custom_group_id.table_name', 'column_name', 'data_type', 'option_group_id', 'html_type'],
797 $field_name = $customField['column_name'];
798 $table_name = CRM_Utils_String
::munge($customField['custom_group_id.table_name']);
799 $from[$field_name] = "LEFT JOIN `$table_name` ON cc.id = `$table_name`.entity_id";
800 if (CRM_Core_BAO_CustomField
::hasOptions($customField)) {
801 $customOptionsWhere = [];
802 $customFieldOptions = CRM_Contact_BAO_Contact
::buildOptions('custom_' . $customField['id'], 'search');
803 $isMultivalueField = CRM_Core_BAO_CustomField
::isSerialized($customField);
804 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
805 foreach ($customFieldOptions as $optionKey => $optionLabel) {
806 if (mb_stripos($optionLabel, $name) !== FALSE) {
807 $customOptionsWhere[$optionKey] = "$table_name.$field_name " . ($isMultivalueField ?
"LIKE '%{$sep}{$optionKey}{$sep}%'" : "= '$optionKey'");
812 // phone_numeric should be phone
813 $searchField = str_replace('_numeric', '', $field_name);
814 if (!in_array($searchField, $list)) {
815 $list[] = $searchField;
819 // Set field name to first name for exact match checking.
820 $field_name = 'sort_name';
823 $select = $actualSelectElements = array('sort_name');
825 foreach ($list as $value) {
826 $suffix = substr($value, 0, 2) . substr($value, -1);
828 case 'street_address':
831 $selectText = $value;
836 $actualSelectElements[] = $select[] = ($value == 'address') ?
$selectText : $value;
837 if ($value == 'phone') {
838 $actualSelectElements[] = $select[] = 'phone_ext';
840 $from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) ";
844 case 'state_province':
845 $select[] = "{$suffix}.name as {$value}";
846 $actualSelectElements[] = "{$suffix}.name";
847 if (!in_array('address', $from)) {
848 $from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) ';
850 $from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id ) ";
854 if ($value == 'id') {
855 $actualSelectElements[] = 'cc.id';
857 elseif ($value != 'sort_name') {
859 if ($field_name == $value) {
860 $suffix = $table_name;
862 $actualSelectElements[] = $select[] = $suffix . '.' . $value;
868 $config = CRM_Core_Config
::singleton();
870 $select = implode(', ', $select);
871 if (!empty($select)) {
872 $select = ", $select";
874 $actualSelectElements = implode(', ', $actualSelectElements);
875 $from = implode(' ', $from);
876 $limit = (int) CRM_Utils_Array
::value('limit', $params);
877 $limit = $limit > 0 ?
$limit : Civi
::settings()->get('search_autocomplete_count');
879 // add acl clause here
880 list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission
::cacheClause('cc');
883 $where .= " AND $aclWhere ";
885 $isPrependWildcard = \Civi
::settings()->get('includeWildCardInName');
887 if (!empty($params['org'])) {
888 $where .= " AND contact_type = \"Organization\"";
890 // CRM-7157, hack: get current employer details when
891 // employee_id is present.
892 $currEmpDetails = array();
893 if (!empty($params['employee_id'])) {
894 if ($currentEmployer = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
895 (int) $params['employee_id'],
898 if ($isPrependWildcard) {
899 $strSearch = "%$name%";
902 $strSearch = "$name%";
905 // get current employer details
906 $dao = CRM_Core_DAO
::executeQuery("SELECT cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data, sort_name
907 FROM civicrm_contact cc {$from} WHERE cc.contact_type = \"Organization\" AND cc.id = {$currentEmployer} AND cc.sort_name LIKE '$strSearch'");
909 $currEmpDetails = array(
911 'data' => $dao->data
,
918 if (!empty($params['contact_sub_type'])) {
919 $contactSubType = CRM_Utils_Type
::escape($params['contact_sub_type'], 'String');
920 $where .= " AND cc.contact_sub_type = '{$contactSubType}'";
923 if (!empty($params['contact_type'])) {
924 $contactType = CRM_Utils_Type
::escape($params['contact_type'], 'String');
925 $where .= " AND cc.contact_type LIKE '{$contactType}'";
928 // Set default for current_employer or return contact with particular id
929 if (!empty($params['id'])) {
930 $where .= " AND cc.id = " . (int) $params['id'];
933 if (!empty($params['cid'])) {
934 $where .= " AND cc.id <> " . (int) $params['cid'];
937 // Contact's based of relationhip type
939 if (!empty($params['rel'])) {
940 $relation = explode('_', CRM_Utils_Array
::value('rel', $params));
941 $relType = CRM_Utils_Type
::escape($relation[0], 'Integer');
942 $rel = CRM_Utils_Type
::escape($relation[2], 'String');
945 if ($isPrependWildcard) {
946 $strSearch = "%$name%";
949 $strSearch = "$name%";
951 $includeEmailFrom = $includeNickName = '';
952 if ($config->includeNickNameInName
) {
953 $includeNickName = " OR nick_name LIKE '$strSearch'";
956 if (isset($customOptionsWhere)) {
957 $customOptionsWhere = $customOptionsWhere ?
: [0];
958 $whereClause = " WHERE (" . implode(' OR ', $customOptionsWhere) . ") $where";
960 elseif (!empty($params['field_name']) && !empty($params['table_name']) && $params['field_name'] != 'sort_name') {
961 $whereClause = " WHERE ( $table_name.$field_name LIKE '$strSearch') {$where}";
962 // Search by id should be exact
963 if ($field_name == 'id' ||
$field_name == 'external_identifier') {
964 $whereClause = " WHERE ( $table_name.$field_name = '$name') {$where}";
968 $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} ";
969 if ($config->includeEmailInName
) {
970 if (!in_array('email', $list)) {
971 $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )";
973 $emailWhere = " WHERE email LIKE '$strSearch'";
977 $additionalFrom = '';
980 INNER JOIN civicrm_relationship_type r ON (
982 AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL )
983 AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL )
987 // check if only CMS users are requested
988 if (!empty($params['cmsuser'])) {
990 INNER JOIN civicrm_uf_match um ON (um.contact_id=cc.id)
993 $orderBy = _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $field_name);
997 SELECT DISTINCT(id), data, sort_name, exactFirst
999 ( SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',
1000 {$actualSelectElements} )
1003 FROM civicrm_contact cc {$from}
1011 if (!empty($emailWhere)) {
1014 SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',
1015 {$actualSelectElements} )
1018 FROM civicrm_contact cc {$from}
1020 {$additionalFrom} {$includeEmailFrom}
1021 {$emailWhere} AND cc.is_deleted = 0 " . ($aclWhere ?
" AND $aclWhere " : '') . "
1032 // send query to hook to be modified if needed
1033 CRM_Utils_Hook
::contactListQuery($query,
1035 empty($params['context']) ?
NULL : CRM_Utils_Type
::escape($params['context'], 'String'),
1036 empty($params['id']) ?
NULL : $params['id']
1039 $dao = CRM_Core_DAO
::executeQuery($query);
1041 $contactList = array();
1042 $listCurrentEmployer = TRUE;
1043 while ($dao->fetch()) {
1044 $t = array('id' => $dao->id
);
1045 foreach ($as as $k) {
1046 $t[$k] = isset($dao->$k) ?
$dao->$k : '';
1048 $t['data'] = $dao->data
;
1049 // Replace keys with values when displaying fields from an option list
1050 if (!empty($customOptionsWhere)) {
1051 $data = explode(' :: ', $dao->data
);
1052 $pos = count($data) - 1;
1053 $customValue = array_intersect(CRM_Utils_Array
::explodePadded($data[$pos]), array_keys($customOptionsWhere));
1054 $data[$pos] = implode(', ', array_intersect_key($customFieldOptions, array_flip($customValue)));
1055 $t['data'] = implode(' :: ', $data);
1057 $contactList[] = $t;
1058 if (!empty($params['org']) &&
1059 !empty($currEmpDetails) &&
1060 $dao->id
== $currEmpDetails['id']
1062 $listCurrentEmployer = FALSE;
1066 //return organization name if doesn't exist in db
1067 if (empty($contactList)) {
1068 if (!empty($params['org'])) {
1069 if ($listCurrentEmployer && !empty($currEmpDetails)) {
1070 $contactList = array(
1072 'data' => $currEmpDetails['data'],
1073 'id' => $currEmpDetails['id'],
1078 $contactList = array(
1088 return civicrm_api3_create_success($contactList, $params, 'Contact', 'getquick');
1092 * Get the order by string for the quicksearch query.
1094 * Get the order by string. The string might be
1095 * - sort name if there is no search value provided and the site is configured
1096 * to search by sort name
1097 * - empty if there is no search value provided and the site is not configured
1098 * to search by sort name
1099 * - exactFirst and then sort name if a search value is provided and the site is configured
1100 * to search by sort name
1101 * - exactFirst if a search value is provided and the site is not configured
1102 * to search by sort name
1104 * exactFirst means 'yes if the search value exactly matches the searched field. else no'.
1105 * It is intended to prioritise exact matches for the entered string so on a first name search
1106 * for 'kath' contacts with a first name of exactly Kath rise to the top.
1108 * On short strings it is expensive. Per CRM-19547 there is still an open question
1109 * as to whether we should only do exactMatch on a minimum length or on certain fields.
1111 * However, we have mitigated this somewhat by not doing an exact match search on
1112 * empty strings, non-wildcard sort-name searches and email searches where there is
1113 * no @ after the first character.
1115 * For the user it is further mitigated by the fact they just don't know the
1116 * slower queries are firing. If they type 'smit' slowly enough 4 queries will trigger
1117 * but if the first 3 are slow the first result they see may be off the 4th query.
1119 * @param string $name
1120 * @param bool $isPrependWildcard
1121 * @param string $field_name
1125 function _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $field_name) {
1126 $skipExactMatch = ($name === '%');
1127 if ($field_name === 'email' && !strpos('@', $name)) {
1128 $skipExactMatch = TRUE;
1131 if (!\Civi
::settings()->get('includeOrderByClause')) {
1132 return $skipExactMatch ?
'' : "ORDER BY exactFirst";
1134 if ($skipExactMatch ||
(!$isPrependWildcard && $field_name === 'sort_name')) {
1135 // If there is no wildcard then sorting by exactFirst would have the same
1136 // effect as just a sort_name search, but slower.
1137 return "ORDER BY sort_name";
1140 return "ORDER BY exactFirst, sort_name";
1144 * Declare deprecated api functions.
1146 * @deprecated api notice
1148 * Array of deprecated actions
1150 function _civicrm_api3_contact_deprecation() {
1151 return array('getquick' => 'The "getquick" action is deprecated in favor of "getlist".');
1155 * Merges given pair of duplicate contacts.
1157 * @param array $params
1158 * Allowed array keys are:
1159 * -int main_id: main contact id with whom merge has to happen
1160 * -int other_id: duplicate contact which would be deleted after merge operation
1161 * -string mode: "safe" skips the merge if there are no conflicts. Does a force merge otherwise.
1165 * @throws API_Exception
1167 function civicrm_api3_contact_merge($params) {
1168 if (($result = CRM_Dedupe_Merger
::merge(array(
1170 'srcID' => $params['to_remove_id'],
1171 'dstID' => $params['to_keep_id'],
1173 ), array(), $params['mode'])) != FALSE) {
1174 return civicrm_api3_create_success($result, $params);
1176 throw new API_Exception('Merge failed');
1180 * Adjust metadata for contact_merge api function.
1182 * @param array $params
1184 function _civicrm_api3_contact_merge_spec(&$params) {
1185 $params['to_remove_id'] = array(
1186 'title' => 'ID of the contact to merge & remove',
1187 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'),
1188 'api.required' => 1,
1189 'type' => CRM_Utils_Type
::T_INT
,
1190 'api.aliases' => array('main_id'),
1192 $params['to_keep_id'] = array(
1193 'title' => 'ID of the contact to keep',
1194 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'),
1195 'api.required' => 1,
1196 'type' => CRM_Utils_Type
::T_INT
,
1197 'api.aliases' => array('other_id'),
1199 $params['mode'] = array(
1200 // @todo need more detail on what this means.
1201 'title' => 'Dedupe mode',
1202 'api.default' => 'safe',
1207 * Get the ultimate contact a contact was merged to.
1209 * @param array $params
1213 * @throws API_Exception
1215 function civicrm_api3_contact_getmergedto($params) {
1216 $contactID = _civicrm_api3_contact_getmergedto($params);
1218 $values = [$contactID => ['id' => $contactID]];
1223 return civicrm_api3_create_success($values, $params);
1227 * Get the contact our contact was finally merged to.
1229 * If the contact has been merged multiple times the crucial parent activity will have
1230 * wound up on the ultimate contact so we can figure out the final resting place of the
1231 * contact with only 2 activities even if 50 merges took place.
1233 * @param array $params
1237 function _civicrm_api3_contact_getmergedto($params) {
1239 $deleteActivity = civicrm_api3('ActivityContact', 'get', [
1240 'contact_id' => $params['contact_id'],
1241 'activity_id.activity_type_id' => 'Contact Deleted By Merge',
1243 'is_test' => $params['is_test'],
1244 'record_type_id' => 'Activity Targets',
1245 'return' => ['activity_id.parent_id'],
1249 'sort' => 'activity_id.activity_date_time DESC'
1252 if (!empty($deleteActivity)) {
1253 $contactID = civicrm_api3('ActivityContact', 'getvalue', [
1254 'activity_id' => $deleteActivity[0]['activity_id.parent_id'],
1255 'record_type_id' => 'Activity Targets',
1256 'return' => 'contact_id',
1263 * Adjust metadata for contact_merge api function.
1265 * @param array $params
1267 function _civicrm_api3_contact_getmergedto_spec(&$params) {
1268 $params['contact_id'] = [
1269 'title' => ts('ID of contact to find ultimate contact for'),
1270 'type' => CRM_Utils_Type
::T_INT
,
1271 'api.required' => TRUE,
1273 $params['is_test'] = [
1274 'title' => ts('Get test deletions rather than live?'),
1275 'type' => CRM_Utils_Type
::T_BOOLEAN
,
1281 * Get the ultimate contact a contact was merged to.
1283 * @param array $params
1287 * @throws API_Exception
1289 function civicrm_api3_contact_getmergedfrom($params) {
1290 $contacts = _civicrm_api3_contact_getmergedfrom($params);
1291 return civicrm_api3_create_success($contacts, $params);
1295 * Get all the contacts merged into our contact.
1297 * @param array $params
1301 function _civicrm_api3_contact_getmergedfrom($params) {
1303 $deleteActivities = civicrm_api3('ActivityContact', 'get', [
1304 'contact_id' => $params['contact_id'],
1305 'activity_id.activity_type_id' => 'Contact Merged',
1307 'is_test' => $params['is_test'],
1308 'record_type_id' => 'Activity Targets',
1309 'return' => 'activity_id',
1312 foreach ($deleteActivities as $deleteActivity) {
1313 $activities[] = $deleteActivity['activity_id'];
1315 if (empty($activities)) {
1319 $activityContacts = civicrm_api3('ActivityContact', 'get', [
1320 'activity_id.parent_id' => ['IN' => $activities],
1321 'record_type_id' => 'Activity Targets',
1322 'return' => 'contact_id',
1325 foreach ($activityContacts as $activityContact) {
1326 $contacts[$activityContact['contact_id']] = ['id' => $activityContact['contact_id']];
1332 * Adjust metadata for contact_merge api function.
1334 * @param array $params
1336 function _civicrm_api3_contact_getmergedfrom_spec(&$params) {
1337 $params['contact_id'] = [
1338 'title' => ts('ID of contact to find ultimate contact for'),
1339 'type' => CRM_Utils_Type
::T_INT
,
1340 'api.required' => TRUE,
1342 $params['is_test'] = [
1343 'title' => ts('Get test deletions rather than live?'),
1344 'type' => CRM_Utils_Type
::T_BOOLEAN
,
1350 * Adjust metadata for contact_proximity api function.
1352 * @param array $params
1354 function _civicrm_api3_contact_proximity_spec(&$params) {
1355 $params['latitude'] = array(
1356 'title' => 'Latitude',
1357 'api.required' => 1,
1358 'type' => CRM_Utils_Type
::T_STRING
,
1360 $params['longitude'] = array(
1361 'title' => 'Longitude',
1362 'api.required' => 1,
1363 'type' => CRM_Utils_Type
::T_STRING
,
1366 $params['unit'] = array(
1367 'title' => 'Unit of Measurement',
1368 'api.default' => 'meter',
1369 'type' => CRM_Utils_Type
::T_STRING
,
1374 * Get contacts by proximity.
1376 * @param array $params
1381 function civicrm_api3_contact_proximity($params) {
1382 $latitude = CRM_Utils_Array
::value('latitude', $params);
1383 $longitude = CRM_Utils_Array
::value('longitude', $params);
1384 $distance = CRM_Utils_Array
::value('distance', $params);
1386 $unit = CRM_Utils_Array
::value('unit', $params);
1388 // check and ensure that lat/long and distance are floats
1390 !CRM_Utils_Rule
::numeric($latitude) ||
1391 !CRM_Utils_Rule
::numeric($longitude) ||
1392 !CRM_Utils_Rule
::numeric($distance)
1394 throw new Exception(ts('Latitude, Longitude and Distance should exist and be numeric'));
1397 if ($unit == "mile") {
1398 $conversionFactor = 1609.344;
1401 $conversionFactor = 1000;
1403 //Distance in meters
1404 $distance = $distance * $conversionFactor;
1406 $whereClause = CRM_Contact_BAO_ProximityQuery
::where($latitude, $longitude, $distance);
1409 SELECT civicrm_contact.id as contact_id,
1410 civicrm_contact.display_name as display_name
1411 FROM civicrm_contact
1412 LEFT JOIN civicrm_address ON civicrm_contact.id = civicrm_address.contact_id
1416 $dao = CRM_Core_DAO
::executeQuery($query);
1417 $contacts = array();
1418 while ($dao->fetch()) {
1419 $contacts[] = $dao->toArray();
1422 return civicrm_api3_create_success($contacts, $params, 'Contact', 'get_by_location', $dao);
1427 * Get parameters for getlist function.
1429 * @see _civicrm_api3_generic_getlist_params
1431 * @param array $request
1433 function _civicrm_api3_contact_getlist_params(&$request) {
1434 // get the autocomplete options from settings
1435 $acpref = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1436 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
1437 'contact_autocomplete_options'
1441 // get the option values for contact autocomplete
1442 $acOptions = CRM_Core_OptionGroup
::values('contact_autocomplete_options', FALSE, FALSE, FALSE, NULL, 'name');
1445 foreach ($acpref as $value) {
1446 if ($value && !empty($acOptions[$value])) {
1447 $list[] = $acOptions[$value];
1450 // If we are doing quicksearch by a field other than name, make sure that field is added to results
1451 $field_name = CRM_Utils_String
::munge($request['search_field']);
1452 // Unique name contact_id = id
1453 if ($field_name == 'contact_id') {
1456 // phone_numeric should be phone
1457 $searchField = str_replace('_numeric', '', $field_name);
1458 if (!in_array($searchField, $list)) {
1459 $list[] = $searchField;
1461 $request['description_field'] = $list;
1462 $list[] = 'contact_type';
1463 $request['params']['return'] = array_unique(array_merge($list, $request['extra']));
1464 $request['params']['options']['sort'] = 'sort_name';
1465 // Contact api doesn't support array(LIKE => 'foo') syntax
1466 if (!empty($request['input'])) {
1467 $request['params'][$request['search_field']] = $request['input'];
1468 // Temporarily override wildcard setting
1469 if (Civi
::settings()->get('includeWildCardInName') != $request['add_wildcard']) {
1470 Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard'] = !$request['add_wildcard'];
1471 Civi
::settings()->set('includeWildCardInName', $request['add_wildcard']);
1477 * Get output for getlist function.
1479 * @see _civicrm_api3_generic_getlist_output
1481 * @param array $result
1482 * @param array $request
1486 function _civicrm_api3_contact_getlist_output($result, $request) {
1488 if (!empty($result['values'])) {
1489 $addressFields = array_intersect(array(
1495 $request['params']['return']);
1496 foreach ($result['values'] as $row) {
1498 'id' => $row[$request['id_field']],
1499 'label' => $row[$request['label_field']],
1500 'description' => array(),
1502 foreach ($request['description_field'] as $item) {
1503 if (!strpos($item, '_name') && !in_array($item, $addressFields) && !empty($row[$item])) {
1504 $data['description'][] = $row[$item];
1508 foreach ($addressFields as $item) {
1509 if (!empty($row[$item])) {
1510 $address[] = $row[$item];
1514 $data['description'][] = implode(' ', $address);
1516 if (!empty($request['image_field'])) {
1517 $data['image'] = isset($row[$request['image_field']]) ?
$row[$request['image_field']] : '';
1520 $data['icon_class'] = $row['contact_type'];
1525 // Restore wildcard override by _civicrm_api3_contact_getlist_params
1526 if (isset(Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard'])) {
1527 Civi
::settings()->set('includeWildCardInName', Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard']);
1528 unset(Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard']);
1534 * Check for duplicate contacts.
1536 * @param array $params
1537 * Params per getfields metadata.
1540 * API formatted array
1542 function civicrm_api3_contact_duplicatecheck($params) {
1543 $dupes = CRM_Contact_BAO_Contact
::getDuplicateContacts(
1545 $params['match']['contact_type'],
1546 $params['rule_type'],
1547 CRM_Utils_Array
::value('exclude', $params, []),
1548 CRM_Utils_Array
::value('check_permissions', $params),
1549 CRM_Utils_Array
::value('dedupe_rule_id', $params)
1552 if ($dupes && !empty($params['return'])) {
1553 return civicrm_api3('Contact', 'get', array(
1554 'return' => $params['return'],
1555 'id' => array('IN' => $dupes),
1556 'options' => CRM_Utils_Array
::value('options', $params),
1557 'sequential' => CRM_Utils_Array
::value('sequential', $params),
1558 'check_permissions' => CRM_Utils_Array
::value('check_permissions', $params),
1561 foreach ($dupes as $dupe) {
1562 $values[$dupe] = array('id' => $dupe);
1564 return civicrm_api3_create_success($values, $params, 'Contact', 'duplicatecheck');
1568 * Declare metadata for contact dedupe function.
1572 function _civicrm_api3_contact_duplicatecheck_spec(&$params) {
1573 $params['dedupe_rule_id'] = array(
1574 'title' => 'Dedupe Rule ID (optional)',
1575 'description' => 'This will default to the built in unsupervised rule',
1576 'type' => CRM_Utils_Type
::T_INT
,
1578 $params['rule_type'] = array(
1579 'title' => 'Dedupe Rule Type',
1580 'description' => 'If no rule id specified, pass "Unsupervised" or "Supervised"',
1581 'type' => CRM_Utils_Type
::T_STRING
,
1582 'api.default' => 'Unsupervised',
1584 // @todo declare 'match' parameter. We don't have a standard for type = array yet.