3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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['birth_date_low'] = array('name' => 'birth_date_low', 'type' => CRM_Utils_Type
::T_DATE
, 'title' => ts('Birth Date is equal to or greater than'));
379 $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'));
380 $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'));
381 $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'));
385 * Support for historical oddities.
387 * We are supporting 'showAll' = 'all', 'trash' or 'active' for Contact get
389 * - hopefully some day we'll come up with a std syntax for the 3-way-boolean of
392 * We also support 'filter_group_id' & 'filter.group_id'
394 * @param array $params
395 * As passed into api get or getcount function.
396 * @param array $options
397 * Array of options (so we can modify the filter).
399 function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
400 if (isset($params['showAll'])) {
401 if (strtolower($params['showAll']) == "active") {
402 $params['contact_is_deleted'] = 0;
404 if (strtolower($params['showAll']) == "trash") {
405 $params['contact_is_deleted'] = 1;
407 if (strtolower($params['showAll']) == "all" && isset($params['contact_is_deleted'])) {
408 unset($params['contact_is_deleted']);
411 // support for group filters
412 if (array_key_exists('filter_group_id', $params)) {
413 $params['filter.group_id'] = $params['filter_group_id'];
414 unset($params['filter_group_id']);
416 // filter.group_id works both for 1,2,3 and array (1,2,3)
417 if (array_key_exists('filter.group_id', $params)) {
418 if (is_array($params['filter.group_id'])) {
419 $groups = $params['filter.group_id'];
422 $groups = explode(',', $params['filter.group_id']);
424 unset($params['filter.group_id']);
425 $options['input_params']['group'] = $groups;
427 if (isset($params['group'])) {
428 $groups = $params['group'];
429 $allGroups = CRM_Core_PseudoConstant
::group();
430 if (is_array($groups) && in_array(key($groups), CRM_Core_DAO
::acceptedSQLOperators(), TRUE)) {
431 // Get the groups array.
432 $groupsArray = $groups[key($groups)];
433 foreach ($groupsArray as &$group) {
434 if (!is_numeric($group) && array_search($group, $allGroups)) {
435 $group = array_search($group, $allGroups);
438 // Now reset the $groups array with the ids not the titles.
439 $groups[key($groups)] = $groupsArray;
441 // handle format like 'group' => array('title1', 'title2').
442 elseif (is_array($groups)) {
443 foreach ($groups as $k => &$group) {
444 if (!is_numeric($group) && array_search($group, $allGroups)) {
445 $group = array_search($group, $allGroups);
447 if (!is_numeric($k) && array_search($k, $allGroups)) {
449 $groups[array_search($k, $allGroups)] = $group;
453 elseif (!is_numeric($groups) && array_search($groups, $allGroups)) {
454 $groups = array_search($groups, $allGroups);
456 $params['group'] = $groups;
461 * Delete a Contact with given contact_id.
463 * @param array $params
464 * input parameters per getfields
466 * @throws \Civi\API\Exception\UnauthorizedException
470 function civicrm_api3_contact_delete($params) {
471 $contactID = CRM_Utils_Array
::value('id', $params);
473 if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::DELETE
)) {
474 throw new \Civi\API\Exception\
UnauthorizedException('Permission denied to modify contact record');
477 $session = CRM_Core_Session
::singleton();
478 if ($contactID == $session->get('userID')) {
479 return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
481 $restore = !empty($params['restore']) ?
$params['restore'] : FALSE;
482 $skipUndelete = !empty($params['skip_undelete']) ?
$params['skip_undelete'] : FALSE;
485 // restrict permanent delete if a contact has financial trxn associated with it
487 if ($skipUndelete && CRM_Financial_BAO_FinancialItem
::checkContactPresent(array($contactID), $error)) {
488 return civicrm_api3_create_error($error['_qf_default']);
490 if (CRM_Contact_BAO_Contact
::deleteContact($contactID, $restore, $skipUndelete,
491 CRM_Utils_Array
::value('check_permissions', $params))) {
492 return civicrm_api3_create_success();
495 return civicrm_api3_create_error('Could not delete contact');
501 * Check parameters passed in.
503 * This function is on it's way out.
505 * @param array $params
508 * @throws API_Exception
509 * @throws CiviCRM_API3_Exception
511 function _civicrm_api3_contact_check_params(&$params) {
513 switch (strtolower(CRM_Utils_Array
::value('contact_type', $params))) {
515 civicrm_api3_verify_mandatory($params, NULL, array('household_name'));
519 civicrm_api3_verify_mandatory($params, NULL, array('organization_name'));
523 civicrm_api3_verify_one_mandatory($params, NULL, array(
533 if (!empty($params['contact_sub_type']) && !empty($params['contact_type'])) {
534 if (!(CRM_Contact_BAO_ContactType
::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
535 throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $params['contact_sub_type']));
539 // The BAO no longer supports the legacy param "current_employer" so here is a shim for api backward-compatability
540 if (!empty($params['current_employer'])) {
541 $organizationParams = array(
542 'organization_name' => $params['current_employer'],
545 $dupeIds = CRM_Contact_BAO_Contact
::getDuplicateContacts($organizationParams, 'Organization', 'Supervised', array(), FALSE);
547 // check for mismatch employer name and id
548 if (!empty($params['employer_id']) && !in_array($params['employer_id'], $dupeIds)) {
549 throw new API_Exception('Employer name and Employer id Mismatch');
552 // show error if multiple organisation with same name exist
553 if (empty($params['employer_id']) && (count($dupeIds) > 1)) {
554 throw new API_Exception('Found more than one Organisation with same Name.');
558 $params['employer_id'] = $dupeIds[0];
561 $result = civicrm_api3('Contact', 'create', array(
562 'organization_name' => $params['current_employer'],
563 'contact_type' => 'Organization',
565 $params['employer_id'] = $result['id'];
573 * Helper function for Contact create.
575 * @param array $params
576 * (reference ) an assoc array of name/value pairs.
577 * @param int $contactID
578 * If present the contact with that ID is updated.
580 * @return CRM_Contact_BAO_Contact|CRM_Core_Error
582 function _civicrm_api3_contact_update($params, $contactID = NULL) {
583 //@todo - doesn't contact create support 'id' which is already set- check & remove
585 $params['contact_id'] = $contactID;
588 return CRM_Contact_BAO_Contact
::create($params);
592 * Validate the addressee or email or postal greetings.
594 * @param array $params
595 * Array per getfields metadata.
597 * @throws API_Exception
599 function _civicrm_api3_greeting_format_params($params) {
600 $greetingParams = array('', '_id', '_custom');
601 foreach (array('email', 'postal', 'addressee') as $key) {
602 $greeting = '_greeting';
603 if ($key == 'addressee') {
607 $formatParams = FALSE;
608 // Unset display value from params.
609 if (isset($params["{$key}{$greeting}_display"])) {
610 unset($params["{$key}{$greeting}_display"]);
613 // check if greetings are present in present
614 foreach ($greetingParams as $greetingValues) {
615 if (array_key_exists("{$key}{$greeting}{$greetingValues}", $params)) {
616 $formatParams = TRUE;
621 if (!$formatParams) {
627 'greeting_type' => "{$key}{$greeting}",
630 $greetings = CRM_Core_PseudoConstant
::greeting($filter);
631 $greetingId = CRM_Utils_Array
::value("{$key}{$greeting}_id", $params);
632 $greetingVal = CRM_Utils_Array
::value("{$key}{$greeting}", $params);
633 $customGreeting = CRM_Utils_Array
::value("{$key}{$greeting}_custom", $params);
635 if (!$greetingId && $greetingVal) {
636 $params["{$key}{$greeting}_id"] = CRM_Utils_Array
::key($params["{$key}{$greeting}"], $greetings);
639 if ($customGreeting && $greetingId &&
640 ($greetingId != array_search('Customized', $greetings))
642 throw new API_Exception(ts('Provide either %1 greeting id and/or %1 greeting or custom %1 greeting',
647 if ($greetingVal && $greetingId &&
648 ($greetingId != CRM_Utils_Array
::key($greetingVal, $greetings))
650 throw new API_Exception(ts('Mismatch in %1 greeting id and %1 greeting',
656 if (!$customGreeting && ($greetingId == array_search('Customized', $greetings))) {
657 throw new API_Exception(ts('Please provide a custom value for %1 greeting',
662 elseif ($greetingVal) {
664 if (!in_array($greetingVal, $greetings)) {
665 throw new API_Exception(ts('Invalid %1 greeting', array(1 => $key)));
668 $greetingId = CRM_Utils_Array
::key($greetingVal, $greetings);
671 if ($customGreeting) {
672 $greetingId = CRM_Utils_Array
::key('Customized', $greetings);
675 $customValue = isset($params['contact_id']) ? CRM_Core_DAO
::getFieldValue(
676 'CRM_Contact_DAO_Contact',
677 $params['contact_id'],
678 "{$key}{$greeting}_custom"
681 if (array_key_exists("{$key}{$greeting}_id", $params) && empty($params["{$key}{$greeting}_id"])) {
684 elseif (array_key_exists("{$key}{$greeting}", $params) && empty($params["{$key}{$greeting}"])) {
687 elseif ($customValue && array_key_exists("{$key}{$greeting}_custom", $params)
688 && empty($params["{$key}{$greeting}_custom"])
693 $params["{$key}{$greeting}_id"] = $greetingId;
695 if (!$customValue && !$customGreeting && array_key_exists("{$key}{$greeting}_custom", $params)) {
696 unset($params["{$key}{$greeting}_custom"]);
700 $params["{$key}{$greeting}_id"] = '';
701 $params["{$key}{$greeting}_custom"] = '';
704 if (isset($params["{$key}{$greeting}"])) {
705 unset($params["{$key}{$greeting}"]);
711 * Adjust Metadata for Get action.
713 * @param array $params
714 * Array of parameters determined by getfields.
716 function _civicrm_api3_contact_getquick_spec(&$params) {
717 $params['name']['api.required'] = TRUE;
718 $params['name']['title'] = ts('String to search on');
719 $params['name']['type'] = CRM_Utils_Type
::T_STRING
;
720 $params['field']['type'] = CRM_Utils_Type
::T_STRING
;
721 $params['field']['title'] = ts('Field to search on');
722 $params['field']['options'] = array(
726 'external_identifier',
736 $params['table_name']['type'] = CRM_Utils_Type
::T_STRING
;
737 $params['table_name']['title'] = ts('Table alias to search on');
738 $params['table_name']['api.default'] = 'cc';
742 * Old Contact quick search api.
746 * @param array $params
749 * @throws \API_Exception
751 function civicrm_api3_contact_getquick($params) {
752 $name = CRM_Utils_Type
::escape(CRM_Utils_Array
::value('name', $params), 'String');
753 $table_name = CRM_Utils_String
::munge($params['table_name']);
754 // get the autocomplete options from settings
755 $acpref = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
756 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
757 'contact_autocomplete_options'
763 'phone_numeric' => 'phe',
764 'street_address' => 'sts',
766 'postal_code' => 'sts',
769 // get the option values for contact autocomplete
770 $acOptions = CRM_Core_OptionGroup
::values('contact_autocomplete_options', FALSE, FALSE, FALSE, NULL, 'name');
772 $list = $from = array();
773 foreach ($acpref as $value) {
774 if ($value && !empty($acOptions[$value])) {
775 $list[$value] = $acOptions[$value];
778 // If we are doing quicksearch by a field other than name, make sure that field is added to results
779 if (!empty($params['field_name'])) {
780 $field_name = CRM_Utils_String
::munge($params['field_name']);
781 // Unique name contact_id = id
782 if ($field_name == 'contact_id') {
785 if (isset($table_names[$field_name])) {
786 $table_name = $table_names[$field_name];
788 elseif (strpos($field_name, 'custom_') === 0) {
789 $customField = civicrm_api3('CustomField', 'getsingle', [
790 'id' => substr($field_name, 7),
791 'return' => ['custom_group_id.table_name', 'column_name', 'data_type', 'option_group_id', 'html_type'],
793 $field_name = $customField['column_name'];
794 $table_name = CRM_Utils_String
::munge($customField['custom_group_id.table_name']);
795 $from[$field_name] = "LEFT JOIN `$table_name` ON cc.id = `$table_name`.entity_id";
796 if (CRM_Core_BAO_CustomField
::hasOptions($customField)) {
797 $customOptionsWhere = [];
798 $customFieldOptions = CRM_Contact_BAO_Contact
::buildOptions('custom_' . $customField['id'], 'search');
799 $isMultivalueField = CRM_Core_BAO_CustomField
::isSerialized($customField);
800 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
801 foreach ($customFieldOptions as $optionKey => $optionLabel) {
802 if (mb_stripos($optionLabel, $name) !== FALSE) {
803 $customOptionsWhere[$optionKey] = "$table_name.$field_name " . ($isMultivalueField ?
"LIKE '%{$sep}{$optionKey}{$sep}%'" : "= '$optionKey'");
808 // phone_numeric should be phone
809 $searchField = str_replace('_numeric', '', $field_name);
810 if (!in_array($searchField, $list)) {
811 $list[] = $searchField;
815 // Set field name to first name for exact match checking.
816 $field_name = 'sort_name';
819 $select = $actualSelectElements = array('sort_name');
821 foreach ($list as $value) {
822 $suffix = substr($value, 0, 2) . substr($value, -1);
824 case 'street_address':
827 $selectText = $value;
832 $actualSelectElements[] = $select[] = ($value == 'address') ?
$selectText : $value;
833 if ($value == 'phone') {
834 $actualSelectElements[] = $select[] = 'phone_ext';
836 $from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) ";
840 case 'state_province':
841 $select[] = "{$suffix}.name as {$value}";
842 $actualSelectElements[] = "{$suffix}.name";
843 if (!in_array('address', $from)) {
844 $from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) ';
846 $from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id ) ";
850 if ($value == 'id') {
851 $actualSelectElements[] = 'cc.id';
853 elseif ($value != 'sort_name') {
855 if ($field_name == $value) {
856 $suffix = $table_name;
858 $actualSelectElements[] = $select[] = $suffix . '.' . $value;
864 $config = CRM_Core_Config
::singleton();
866 $select = implode(', ', $select);
867 if (!empty($select)) {
868 $select = ", $select";
870 $actualSelectElements = implode(', ', $actualSelectElements);
871 $from = implode(' ', $from);
872 $limit = (int) CRM_Utils_Array
::value('limit', $params);
873 $limit = $limit > 0 ?
$limit : Civi
::settings()->get('search_autocomplete_count');
875 // add acl clause here
876 list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission
::cacheClause('cc');
879 $where .= " AND $aclWhere ";
881 $isPrependWildcard = \Civi
::settings()->get('includeWildCardInName');
883 if (!empty($params['org'])) {
884 $where .= " AND contact_type = \"Organization\"";
886 // CRM-7157, hack: get current employer details when
887 // employee_id is present.
888 $currEmpDetails = array();
889 if (!empty($params['employee_id'])) {
890 if ($currentEmployer = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
891 (int) $params['employee_id'],
894 if ($isPrependWildcard) {
895 $strSearch = "%$name%";
898 $strSearch = "$name%";
901 // get current employer details
902 $dao = CRM_Core_DAO
::executeQuery("SELECT cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data, sort_name
903 FROM civicrm_contact cc {$from} WHERE cc.contact_type = \"Organization\" AND cc.id = {$currentEmployer} AND cc.sort_name LIKE '$strSearch'");
905 $currEmpDetails = array(
907 'data' => $dao->data
,
914 if (!empty($params['contact_sub_type'])) {
915 $contactSubType = CRM_Utils_Type
::escape($params['contact_sub_type'], 'String');
916 $where .= " AND cc.contact_sub_type = '{$contactSubType}'";
919 if (!empty($params['contact_type'])) {
920 $contactType = CRM_Utils_Type
::escape($params['contact_type'], 'String');
921 $where .= " AND cc.contact_type LIKE '{$contactType}'";
924 // Set default for current_employer or return contact with particular id
925 if (!empty($params['id'])) {
926 $where .= " AND cc.id = " . (int) $params['id'];
929 if (!empty($params['cid'])) {
930 $where .= " AND cc.id <> " . (int) $params['cid'];
933 // Contact's based of relationhip type
935 if (!empty($params['rel'])) {
936 $relation = explode('_', CRM_Utils_Array
::value('rel', $params));
937 $relType = CRM_Utils_Type
::escape($relation[0], 'Integer');
938 $rel = CRM_Utils_Type
::escape($relation[2], 'String');
941 if ($isPrependWildcard) {
942 $strSearch = "%$name%";
945 $strSearch = "$name%";
947 $includeEmailFrom = $includeNickName = '';
948 if ($config->includeNickNameInName
) {
949 $includeNickName = " OR nick_name LIKE '$strSearch'";
952 if (isset($customOptionsWhere)) {
953 $customOptionsWhere = $customOptionsWhere ?
: [0];
954 $whereClause = " WHERE (" . implode(' OR ', $customOptionsWhere) . ") $where";
956 elseif (!empty($params['field_name']) && !empty($params['table_name'])) {
957 $whereClause = " WHERE ( $table_name.$field_name LIKE '$strSearch') {$where}";
958 // Search by id should be exact
959 if ($field_name == 'id' ||
$field_name == 'external_identifier') {
960 $whereClause = " WHERE ( $table_name.$field_name = '$name') {$where}";
964 $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} ";
965 if ($config->includeEmailInName
) {
966 if (!in_array('email', $list)) {
967 $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )";
969 $emailWhere = " WHERE email LIKE '$strSearch'";
973 $additionalFrom = '';
976 INNER JOIN civicrm_relationship_type r ON (
978 AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL )
979 AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL )
983 // check if only CMS users are requested
984 if (!empty($params['cmsuser'])) {
986 INNER JOIN civicrm_uf_match um ON (um.contact_id=cc.id)
989 $orderBy = _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $field_name);
993 SELECT DISTINCT(id), data, sort_name, exactFirst
995 ( SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',
996 {$actualSelectElements} )
999 FROM civicrm_contact cc {$from}
1007 if (!empty($emailWhere)) {
1010 SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',
1011 {$actualSelectElements} )
1014 FROM civicrm_contact cc {$from}
1016 {$additionalFrom} {$includeEmailFrom}
1017 {$emailWhere} AND cc.is_deleted = 0 " . ($aclWhere ?
" AND $aclWhere " : '') . "
1028 // send query to hook to be modified if needed
1029 CRM_Utils_Hook
::contactListQuery($query,
1031 empty($params['context']) ?
NULL : CRM_Utils_Type
::escape($params['context'], 'String'),
1032 empty($params['id']) ?
NULL : $params['id']
1035 $dao = CRM_Core_DAO
::executeQuery($query);
1037 $contactList = array();
1038 $listCurrentEmployer = TRUE;
1039 while ($dao->fetch()) {
1040 $t = array('id' => $dao->id
);
1041 foreach ($as as $k) {
1042 $t[$k] = isset($dao->$k) ?
$dao->$k : '';
1044 $t['data'] = $dao->data
;
1045 // Replace keys with values when displaying fields from an option list
1046 if (!empty($customOptionsWhere)) {
1047 $data = explode(' :: ', $dao->data
);
1048 $pos = count($data) - 1;
1049 $customValue = array_intersect(CRM_Utils_Array
::explodePadded($data[$pos]), array_keys($customOptionsWhere));
1050 $data[$pos] = implode(', ', array_intersect_key($customFieldOptions, array_flip($customValue)));
1051 $t['data'] = implode(' :: ', $data);
1053 $contactList[] = $t;
1054 if (!empty($params['org']) &&
1055 !empty($currEmpDetails) &&
1056 $dao->id
== $currEmpDetails['id']
1058 $listCurrentEmployer = FALSE;
1062 //return organization name if doesn't exist in db
1063 if (empty($contactList)) {
1064 if (!empty($params['org'])) {
1065 if ($listCurrentEmployer && !empty($currEmpDetails)) {
1066 $contactList = array(
1068 'data' => $currEmpDetails['data'],
1069 'id' => $currEmpDetails['id'],
1074 $contactList = array(
1084 return civicrm_api3_create_success($contactList, $params, 'Contact', 'getquick');
1088 * Get the order by string for the quicksearch query.
1090 * Get the order by string. The string might be
1091 * - sort name if there is no search value provided and the site is configured
1092 * to search by sort name
1093 * - empty if there is no search value provided and the site is not configured
1094 * to search by sort name
1095 * - exactFirst and then sort name if a search value is provided and the site is configured
1096 * to search by sort name
1097 * - exactFirst if a search value is provided and the site is not configured
1098 * to search by sort name
1100 * exactFirst means 'yes if the search value exactly matches the searched field. else no'.
1101 * It is intended to prioritise exact matches for the entered string so on a first name search
1102 * for 'kath' contacts with a first name of exactly Kath rise to the top.
1104 * On short strings it is expensive. Per CRM-19547 there is still an open question
1105 * as to whether we should only do exactMatch on a minimum length or on certain fields.
1107 * However, we have mitigated this somewhat by not doing an exact match search on
1108 * empty strings, non-wildcard sort-name searches and email searches where there is
1109 * no @ after the first character.
1111 * For the user it is further mitigated by the fact they just don't know the
1112 * slower queries are firing. If they type 'smit' slowly enough 4 queries will trigger
1113 * but if the first 3 are slow the first result they see may be off the 4th query.
1115 * @param string $name
1116 * @param bool $isPrependWildcard
1117 * @param string $field_name
1121 function _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $field_name) {
1122 $skipExactMatch = ($name === '%');
1123 if ($field_name === 'email' && !strpos('@', $name)) {
1124 $skipExactMatch = TRUE;
1127 if (!\Civi
::settings()->get('includeOrderByClause')) {
1128 return $skipExactMatch ?
'' : "ORDER BY exactFirst";
1130 if ($skipExactMatch ||
(!$isPrependWildcard && $field_name === 'sort_name')) {
1131 // If there is no wildcard then sorting by exactFirst would have the same
1132 // effect as just a sort_name search, but slower.
1133 return "ORDER BY sort_name";
1136 return "ORDER BY exactFirst, sort_name";
1140 * Declare deprecated api functions.
1142 * @deprecated api notice
1144 * Array of deprecated actions
1146 function _civicrm_api3_contact_deprecation() {
1147 return array('getquick' => 'The "getquick" action is deprecated in favor of "getlist".');
1151 * Merges given pair of duplicate contacts.
1153 * @param array $params
1154 * Allowed array keys are:
1155 * -int main_id: main contact id with whom merge has to happen
1156 * -int other_id: duplicate contact which would be deleted after merge operation
1157 * -string mode: "safe" skips the merge if there are no conflicts. Does a force merge otherwise.
1161 * @throws API_Exception
1163 function civicrm_api3_contact_merge($params) {
1164 if (($result = CRM_Dedupe_Merger
::merge(array(
1166 'srcID' => $params['to_remove_id'],
1167 'dstID' => $params['to_keep_id'],
1169 ), array(), $params['mode'])) != FALSE) {
1170 return civicrm_api3_create_success($result, $params);
1172 throw new API_Exception('Merge failed');
1176 * Adjust metadata for contact_merge api function.
1178 * @param array $params
1180 function _civicrm_api3_contact_merge_spec(&$params) {
1181 $params['to_remove_id'] = array(
1182 'title' => 'ID of the contact to merge & remove',
1183 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'),
1184 'api.required' => 1,
1185 'type' => CRM_Utils_Type
::T_INT
,
1186 'api.aliases' => array('main_id'),
1188 $params['to_keep_id'] = array(
1189 'title' => 'ID of the contact to keep',
1190 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'),
1191 'api.required' => 1,
1192 'type' => CRM_Utils_Type
::T_INT
,
1193 'api.aliases' => array('other_id'),
1195 $params['mode'] = array(
1196 // @todo need more detail on what this means.
1197 'title' => 'Dedupe mode',
1198 'api.default' => 'safe',
1203 * Get the ultimate contact a contact was merged to.
1205 * @param array $params
1209 * @throws API_Exception
1211 function civicrm_api3_contact_getmergedto($params) {
1212 $contactID = _civicrm_api3_contact_getmergedto($params);
1214 $values = [$contactID => ['id' => $contactID]];
1219 return civicrm_api3_create_success($values, $params);
1223 * Get the contact our contact was finally merged to.
1225 * If the contact has been merged multiple times the crucial parent activity will have
1226 * wound up on the ultimate contact so we can figure out the final resting place of the
1227 * contact with only 2 activities even if 50 merges took place.
1229 * @param array $params
1233 function _civicrm_api3_contact_getmergedto($params) {
1235 $deleteActivity = civicrm_api3('ActivityContact', 'get', [
1236 'contact_id' => $params['contact_id'],
1237 'activity_id.activity_type_id' => 'Contact Deleted By Merge',
1239 'is_test' => $params['is_test'],
1240 'record_type_id' => 'Activity Targets',
1241 'return' => ['activity_id.parent_id'],
1245 'sort' => 'activity_id.activity_date_time DESC'
1248 if (!empty($deleteActivity)) {
1249 $contactID = civicrm_api3('ActivityContact', 'getvalue', [
1250 'activity_id' => $deleteActivity[0]['activity_id.parent_id'],
1251 'record_type_id' => 'Activity Targets',
1252 'return' => 'contact_id',
1259 * Adjust metadata for contact_merge api function.
1261 * @param array $params
1263 function _civicrm_api3_contact_getmergedto_spec(&$params) {
1264 $params['contact_id'] = [
1265 'title' => ts('ID of contact to find ultimate contact for'),
1266 'type' => CRM_Utils_Type
::T_INT
,
1267 'api.required' => TRUE,
1269 $params['is_test'] = [
1270 'title' => ts('Get test deletions rather than live?'),
1271 'type' => CRM_Utils_Type
::T_BOOLEAN
,
1277 * Get the ultimate contact a contact was merged to.
1279 * @param array $params
1283 * @throws API_Exception
1285 function civicrm_api3_contact_getmergedfrom($params) {
1286 $contacts = _civicrm_api3_contact_getmergedfrom($params);
1287 return civicrm_api3_create_success($contacts, $params);
1291 * Get all the contacts merged into our contact.
1293 * @param array $params
1297 function _civicrm_api3_contact_getmergedfrom($params) {
1299 $deleteActivities = civicrm_api3('ActivityContact', 'get', [
1300 'contact_id' => $params['contact_id'],
1301 'activity_id.activity_type_id' => 'Contact Merged',
1303 'is_test' => $params['is_test'],
1304 'record_type_id' => 'Activity Targets',
1305 'return' => 'activity_id',
1308 foreach ($deleteActivities as $deleteActivity) {
1309 $activities[] = $deleteActivity['activity_id'];
1311 if (empty($activities)) {
1315 $activityContacts = civicrm_api3('ActivityContact', 'get', [
1316 'activity_id.parent_id' => ['IN' => $activities],
1317 'record_type_id' => 'Activity Targets',
1318 'return' => 'contact_id',
1321 foreach ($activityContacts as $activityContact) {
1322 $contacts[$activityContact['contact_id']] = ['id' => $activityContact['contact_id']];
1328 * Adjust metadata for contact_merge api function.
1330 * @param array $params
1332 function _civicrm_api3_contact_getmergedfrom_spec(&$params) {
1333 $params['contact_id'] = [
1334 'title' => ts('ID of contact to find ultimate contact for'),
1335 'type' => CRM_Utils_Type
::T_INT
,
1336 'api.required' => TRUE,
1338 $params['is_test'] = [
1339 'title' => ts('Get test deletions rather than live?'),
1340 'type' => CRM_Utils_Type
::T_BOOLEAN
,
1346 * Adjust metadata for contact_proximity api function.
1348 * @param array $params
1350 function _civicrm_api3_contact_proximity_spec(&$params) {
1351 $params['latitude'] = array(
1352 'title' => 'Latitude',
1353 'api.required' => 1,
1354 'type' => CRM_Utils_Type
::T_STRING
,
1356 $params['longitude'] = array(
1357 'title' => 'Longitude',
1358 'api.required' => 1,
1359 'type' => CRM_Utils_Type
::T_STRING
,
1362 $params['unit'] = array(
1363 'title' => 'Unit of Measurement',
1364 'api.default' => 'meter',
1365 'type' => CRM_Utils_Type
::T_STRING
,
1370 * Get contacts by proximity.
1372 * @param array $params
1377 function civicrm_api3_contact_proximity($params) {
1378 $latitude = CRM_Utils_Array
::value('latitude', $params);
1379 $longitude = CRM_Utils_Array
::value('longitude', $params);
1380 $distance = CRM_Utils_Array
::value('distance', $params);
1382 $unit = CRM_Utils_Array
::value('unit', $params);
1384 // check and ensure that lat/long and distance are floats
1386 !CRM_Utils_Rule
::numeric($latitude) ||
1387 !CRM_Utils_Rule
::numeric($longitude) ||
1388 !CRM_Utils_Rule
::numeric($distance)
1390 throw new Exception(ts('Latitude, Longitude and Distance should exist and be numeric'));
1393 if ($unit == "mile") {
1394 $conversionFactor = 1609.344;
1397 $conversionFactor = 1000;
1399 //Distance in meters
1400 $distance = $distance * $conversionFactor;
1402 $whereClause = CRM_Contact_BAO_ProximityQuery
::where($latitude, $longitude, $distance);
1405 SELECT civicrm_contact.id as contact_id,
1406 civicrm_contact.display_name as display_name
1407 FROM civicrm_contact
1408 LEFT JOIN civicrm_address ON civicrm_contact.id = civicrm_address.contact_id
1412 $dao = CRM_Core_DAO
::executeQuery($query);
1413 $contacts = array();
1414 while ($dao->fetch()) {
1415 $contacts[] = $dao->toArray();
1418 return civicrm_api3_create_success($contacts, $params, 'Contact', 'get_by_location', $dao);
1423 * Get parameters for getlist function.
1425 * @see _civicrm_api3_generic_getlist_params
1427 * @param array $request
1429 function _civicrm_api3_contact_getlist_params(&$request) {
1430 // get the autocomplete options from settings
1431 $acpref = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1432 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
1433 'contact_autocomplete_options'
1437 // get the option values for contact autocomplete
1438 $acOptions = CRM_Core_OptionGroup
::values('contact_autocomplete_options', FALSE, FALSE, FALSE, NULL, 'name');
1441 foreach ($acpref as $value) {
1442 if ($value && !empty($acOptions[$value])) {
1443 $list[] = $acOptions[$value];
1446 // If we are doing quicksearch by a field other than name, make sure that field is added to results
1447 $field_name = CRM_Utils_String
::munge($request['search_field']);
1448 // Unique name contact_id = id
1449 if ($field_name == 'contact_id') {
1452 // phone_numeric should be phone
1453 $searchField = str_replace('_numeric', '', $field_name);
1454 if (!in_array($searchField, $list)) {
1455 $list[] = $searchField;
1457 $request['description_field'] = $list;
1458 $list[] = 'contact_type';
1459 $request['params']['return'] = array_unique(array_merge($list, $request['extra']));
1460 $request['params']['options']['sort'] = 'sort_name';
1461 // Contact api doesn't support array(LIKE => 'foo') syntax
1462 if (!empty($request['input'])) {
1463 $request['params'][$request['search_field']] = $request['input'];
1464 // Temporarily override wildcard setting
1465 if (Civi
::settings()->get('includeWildCardInName') != $request['add_wildcard']) {
1466 Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard'] = !$request['add_wildcard'];
1467 Civi
::settings()->set('includeWildCardInName', $request['add_wildcard']);
1473 * Get output for getlist function.
1475 * @see _civicrm_api3_generic_getlist_output
1477 * @param array $result
1478 * @param array $request
1482 function _civicrm_api3_contact_getlist_output($result, $request) {
1484 if (!empty($result['values'])) {
1485 $addressFields = array_intersect(array(
1491 $request['params']['return']);
1492 foreach ($result['values'] as $row) {
1494 'id' => $row[$request['id_field']],
1495 'label' => $row[$request['label_field']],
1496 'description' => array(),
1498 foreach ($request['description_field'] as $item) {
1499 if (!strpos($item, '_name') && !in_array($item, $addressFields) && !empty($row[$item])) {
1500 $data['description'][] = $row[$item];
1504 foreach ($addressFields as $item) {
1505 if (!empty($row[$item])) {
1506 $address[] = $row[$item];
1510 $data['description'][] = implode(' ', $address);
1512 if (!empty($request['image_field'])) {
1513 $data['image'] = isset($row[$request['image_field']]) ?
$row[$request['image_field']] : '';
1516 $data['icon_class'] = $row['contact_type'];
1521 // Restore wildcard override by _civicrm_api3_contact_getlist_params
1522 if (isset(Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard'])) {
1523 Civi
::settings()->set('includeWildCardInName', Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard']);
1524 unset(Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard']);
1530 * Check for duplicate contacts.
1532 * @param array $params
1533 * Params per getfields metadata.
1536 * API formatted array
1538 function civicrm_api3_contact_duplicatecheck($params) {
1539 $dupes = CRM_Contact_BAO_Contact
::getDuplicateContacts(
1541 $params['match']['contact_type'],
1542 $params['rule_type'],
1543 CRM_Utils_Array
::value('exclude', $params, []),
1544 CRM_Utils_Array
::value('check_permissions', $params),
1545 CRM_Utils_Array
::value('dedupe_rule_id', $params)
1548 if ($dupes && !empty($params['return'])) {
1549 return civicrm_api3('Contact', 'get', array(
1550 'return' => $params['return'],
1551 'id' => array('IN' => $dupes),
1552 'options' => CRM_Utils_Array
::value('options', $params),
1553 'sequential' => CRM_Utils_Array
::value('sequential', $params),
1554 'check_permissions' => CRM_Utils_Array
::value('check_permissions', $params),
1557 foreach ($dupes as $dupe) {
1558 $values[$dupe] = array('id' => $dupe);
1560 return civicrm_api3_create_success($values, $params, 'Contact', 'duplicatecheck');
1564 * Declare metadata for contact dedupe function.
1568 function _civicrm_api3_contact_duplicatecheck_spec(&$params) {
1569 $params['dedupe_rule_id'] = array(
1570 'title' => 'Dedupe Rule ID (optional)',
1571 'description' => 'This will default to the built in unsupervised rule',
1572 'type' => CRM_Utils_Type
::T_INT
,
1574 $params['rule_type'] = array(
1575 'title' => 'Dedupe Rule Type',
1576 'description' => 'If no rule id specified, pass "Unsupervised" or "Supervised"',
1577 'type' => CRM_Utils_Type
::T_STRING
,
1578 'api.default' => 'Unsupervised',
1580 // @todo declare 'match' parameter. We don't have a standard for type = array yet.