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', [], $params['check_permission']);
60 if (count($ids) > 0) {
61 throw new API_Exception("Found matching contacts: " . implode(',', $ids), "duplicate", ["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();
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'] = [
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'] = ['contact_id'];
146 $params['current_employer'] = [
147 'title' => 'Current Employer',
148 'description' => 'Name of Current Employer',
149 'type' => CRM_Utils_Type
::T_STRING
,
151 $params['dupe_check'] = [
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'] = [
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'] = [
164 'individual_prefix_id',
166 $params['suffix_id']['api.aliases'] = [
168 'individual_suffix_id',
170 $params['gender_id']['api.aliases'] = ['gender'];
174 * Retrieve one or more contacts, given a set of search params.
176 * @param array $params
181 function civicrm_api3_contact_get($params) {
183 _civicrm_api3_contact_get_supportanomalies($params, $options);
184 $contacts = _civicrm_api3_get_using_query_object('Contact', $params, $options);
185 $contacts = _civicrm_api3_contact_formatResult($params, $contacts);
186 return civicrm_api3_create_success($contacts, $params, 'Contact');
192 * @param array $result
195 * @throws \CRM_Core_Exception
197 function _civicrm_api3_contact_formatResult($params, $result) {
198 $apiKeyPerms = ['edit api keys', 'administer CiviCRM'];
199 $allowApiKey = empty($params['check_permissions']) || CRM_Core_Permission
::check([$apiKeyPerms]);
201 if (is_array($result)) {
202 // Single-value $result
203 if (isset($result['api_key'])) {
204 unset($result['api_key']);
207 // Multi-value $result
208 foreach ($result as $key => $row) {
209 if (is_array($row)) {
210 unset($result[$key]['api_key']);
219 * Get number of contacts matching the supplied criteria.
221 * @param array $params
225 function civicrm_api3_contact_getcount($params) {
227 _civicrm_api3_contact_get_supportanomalies($params, $options);
228 $count = _civicrm_api3_get_using_query_object('Contact', $params, $options, 1);
233 * Adjust Metadata for Get action.
235 * @param array $params
236 * Array of parameters determined by getfields.
238 function _civicrm_api3_contact_get_spec(&$params) {
239 $params['contact_is_deleted']['api.default'] = 0;
241 // We declare all these pseudoFields as there are other undocumented fields accessible
242 // via the api - but if check permissions is set we only allow declared fields
243 $params['address_id'] = [
244 'title' => 'Primary Address ID',
245 'type' => CRM_Utils_Type
::T_INT
,
247 $params['street_address'] = [
248 'title' => 'Primary Address Street Address',
249 'type' => CRM_Utils_Type
::T_STRING
,
251 $params['supplemental_address_1'] = [
252 'title' => 'Primary Address Supplemental Address 1',
253 'type' => CRM_Utils_Type
::T_STRING
,
255 $params['supplemental_address_2'] = [
256 'title' => 'Primary Address Supplemental Address 2',
257 'type' => CRM_Utils_Type
::T_STRING
,
259 $params['supplemental_address_3'] = [
260 'title' => 'Primary Address Supplemental Address 3',
261 'type' => CRM_Utils_Type
::T_STRING
,
263 $params['current_employer'] = [
264 'title' => 'Current Employer',
265 'type' => CRM_Utils_Type
::T_STRING
,
268 'title' => 'Primary Address City',
269 'type' => CRM_Utils_Type
::T_STRING
,
271 $params['postal_code_suffix'] = [
272 'title' => 'Primary Address Post Code Suffix',
273 'type' => CRM_Utils_Type
::T_STRING
,
275 $params['postal_code'] = [
276 'title' => 'Primary Address Post Code',
277 'type' => CRM_Utils_Type
::T_STRING
,
279 $params['geo_code_1'] = [
280 'title' => 'Primary Address Latitude',
281 'type' => CRM_Utils_Type
::T_STRING
,
283 $params['geo_code_2'] = [
284 'title' => 'Primary Address Longitude',
285 'type' => CRM_Utils_Type
::T_STRING
,
287 $params['state_province_id'] = [
288 'title' => 'Primary Address State Province ID',
289 'type' => CRM_Utils_Type
::T_INT
,
290 'pseudoconstant' => [
291 'table' => 'civicrm_state_province',
294 $params['state_province_name'] = [
295 'title' => 'Primary Address State Province Name',
296 'type' => CRM_Utils_Type
::T_STRING
,
297 'pseudoconstant' => [
298 'table' => 'civicrm_state_province',
301 $params['state_province'] = [
302 'title' => 'Primary Address State Province',
303 'type' => CRM_Utils_Type
::T_STRING
,
304 'pseudoconstant' => [
305 'table' => 'civicrm_state_province',
308 $params['country_id'] = [
309 'title' => 'Primary Address Country ID',
310 'type' => CRM_Utils_Type
::T_INT
,
311 'pseudoconstant' => [
312 'table' => 'civicrm_country',
315 $params['country'] = [
316 'title' => 'Primary Address country',
317 'type' => CRM_Utils_Type
::T_STRING
,
318 'pseudoconstant' => [
319 'table' => 'civicrm_country',
322 $params['worldregion_id'] = [
323 'title' => 'Primary Address World Region ID',
324 'type' => CRM_Utils_Type
::T_INT
,
325 'pseudoconstant' => [
326 'table' => 'civicrm_world_region',
329 $params['worldregion'] = [
330 'title' => 'Primary Address World Region',
331 'type' => CRM_Utils_Type
::T_STRING
,
332 'pseudoconstant' => [
333 'table' => 'civicrm_world_region',
336 $params['phone_id'] = [
337 'title' => 'Primary Phone ID',
338 'type' => CRM_Utils_Type
::T_INT
,
341 'title' => 'Primary Phone',
342 'type' => CRM_Utils_Type
::T_STRING
,
344 $params['phone_type_id'] = [
345 'title' => 'Primary Phone Type ID',
346 'type' => CRM_Utils_Type
::T_INT
,
348 $params['provider_id'] = [
349 'title' => 'Primary Phone Provider ID',
350 'type' => CRM_Utils_Type
::T_INT
,
352 $params['email_id'] = [
353 'title' => 'Primary Email ID',
354 'type' => CRM_Utils_Type
::T_INT
,
357 'title' => 'Primary Email',
358 'type' => CRM_Utils_Type
::T_STRING
,
360 $params['on_hold'] = [
361 'title' => 'Primary Email On Hold',
362 'type' => CRM_Utils_Type
::T_BOOLEAN
,
365 'title' => 'Primary Instant Messenger',
366 'type' => CRM_Utils_Type
::T_STRING
,
369 'title' => 'Primary Instant Messenger ID',
370 'type' => CRM_Utils_Type
::T_INT
,
374 'pseudoconstant' => [
375 'table' => 'civicrm_group',
380 'pseudoconstant' => [
381 'table' => 'civicrm_tag',
384 $params['uf_user'] = [
385 'title' => 'CMS User',
386 'type' => CRM_Utils_Type
::T_BOOLEAN
,
388 $params['birth_date_low'] = [
389 'name' => 'birth_date_low',
390 'type' => CRM_Utils_Type
::T_DATE
,
391 'title' => ts('Birth Date is equal to or greater than'),
393 $params['birth_date_high'] = [
394 'name' => 'birth_date_high',
395 'type' => CRM_Utils_Type
::T_DATE
,
396 'title' => ts('Birth Date is equal to or less than'),
398 $params['deceased_date_low'] = [
399 'name' => 'deceased_date_low',
400 'type' => CRM_Utils_Type
::T_DATE
,
401 'title' => ts('Deceased Date is equal to or greater than'),
403 $params['deceased_date_high'] = [
404 'name' => 'deceased_date_high',
405 'type' => CRM_Utils_Type
::T_DATE
,
406 'title' => ts('Deceased Date is equal to or less than'),
411 * Support for historical oddities.
413 * We are supporting 'showAll' = 'all', 'trash' or 'active' for Contact get
415 * - hopefully some day we'll come up with a std syntax for the 3-way-boolean of
418 * We also support 'filter_group_id' & 'filter.group_id'
420 * @param array $params
421 * As passed into api get or getcount function.
422 * @param array $options
423 * Array of options (so we can modify the filter).
425 function _civicrm_api3_contact_get_supportanomalies(&$params, &$options) {
426 if (isset($params['showAll'])) {
427 if (strtolower($params['showAll']) == "active") {
428 $params['contact_is_deleted'] = 0;
430 if (strtolower($params['showAll']) == "trash") {
431 $params['contact_is_deleted'] = 1;
433 if (strtolower($params['showAll']) == "all" && isset($params['contact_is_deleted'])) {
434 unset($params['contact_is_deleted']);
437 // support for group filters
438 if (array_key_exists('filter_group_id', $params)) {
439 $params['filter.group_id'] = $params['filter_group_id'];
440 unset($params['filter_group_id']);
442 // filter.group_id works both for 1,2,3 and array (1,2,3)
443 if (array_key_exists('filter.group_id', $params)) {
444 if (is_array($params['filter.group_id'])) {
445 $groups = $params['filter.group_id'];
448 $groups = explode(',', $params['filter.group_id']);
450 unset($params['filter.group_id']);
451 $options['input_params']['group'] = $groups;
453 if (isset($params['group'])) {
454 $groups = $params['group'];
455 $groupsByTitle = CRM_Core_PseudoConstant
::group();
456 $groupsByName = CRM_Contact_BAO_GroupContact
::buildOptions('group_id', 'validate');
457 $allGroups = array_merge(array_flip($groupsByTitle), array_flip($groupsByName));
458 if (is_array($groups) && in_array(key($groups), CRM_Core_DAO
::acceptedSQLOperators(), TRUE)) {
459 // Get the groups array.
460 $groupsArray = $groups[key($groups)];
461 foreach ($groupsArray as &$group) {
462 if (!is_numeric($group) && !empty($allGroups[$group])) {
463 $group = $allGroups[$group];
466 // Now reset the $groups array with the ids not the titles.
467 $groups[key($groups)] = $groupsArray;
469 // handle format like 'group' => array('title1', 'title2').
470 elseif (is_array($groups)) {
471 foreach ($groups as $k => &$group) {
472 if (!is_numeric($group) && !empty($allGroups[$group])) {
473 $group = $allGroups[$group];
475 if (!is_numeric($k) && !empty($allGroups[$k])) {
477 $groups[$allGroups[$k]] = $group;
481 elseif (!is_numeric($groups) && !empty($allGroups[$groups])) {
482 $groups = $allGroups[$groups];
484 $params['group'] = $groups;
489 * Delete a Contact with given contact_id.
491 * @param array $params
492 * input parameters per getfields
494 * @throws \Civi\API\Exception\UnauthorizedException
498 function civicrm_api3_contact_delete($params) {
499 $contactID = CRM_Utils_Array
::value('id', $params);
501 if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::DELETE
)) {
502 throw new \Civi\API\Exception\
UnauthorizedException('Permission denied to modify contact record');
505 $session = CRM_Core_Session
::singleton();
506 if ($contactID == $session->get('userID')) {
507 return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
509 $restore = !empty($params['restore']) ?
$params['restore'] : FALSE;
510 $skipUndelete = !empty($params['skip_undelete']) ?
$params['skip_undelete'] : FALSE;
513 // restrict permanent delete if a contact has financial trxn associated with it
515 if ($skipUndelete && CRM_Financial_BAO_FinancialItem
::checkContactPresent([$contactID], $error)) {
516 return civicrm_api3_create_error($error['_qf_default']);
518 if (CRM_Contact_BAO_Contact
::deleteContact($contactID, $restore, $skipUndelete,
519 CRM_Utils_Array
::value('check_permissions', $params))) {
520 return civicrm_api3_create_success();
523 return civicrm_api3_create_error('Could not delete contact');
529 * Check parameters passed in.
531 * This function is on it's way out.
533 * @param array $params
536 * @throws API_Exception
537 * @throws CiviCRM_API3_Exception
539 function _civicrm_api3_contact_check_params(&$params) {
541 switch (strtolower(CRM_Utils_Array
::value('contact_type', $params))) {
543 civicrm_api3_verify_mandatory($params, NULL, ['household_name']);
547 civicrm_api3_verify_mandatory($params, NULL, ['organization_name']);
551 civicrm_api3_verify_one_mandatory($params, NULL, [
561 if (!empty($params['contact_sub_type']) && !empty($params['contact_type'])) {
562 if (!(CRM_Contact_BAO_ContactType
::isExtendsContactType($params['contact_sub_type'], $params['contact_type']))) {
563 throw new API_Exception("Invalid or Mismatched Contact Subtype: " . implode(', ', (array) $params['contact_sub_type']));
567 // The BAO no longer supports the legacy param "current_employer" so here is a shim for api backward-compatability
568 if (!empty($params['current_employer'])) {
569 $organizationParams = [
570 'organization_name' => $params['current_employer'],
573 $dupeIds = CRM_Contact_BAO_Contact
::getDuplicateContacts($organizationParams, 'Organization', 'Supervised', [], FALSE);
575 // check for mismatch employer name and id
576 if (!empty($params['employer_id']) && !in_array($params['employer_id'], $dupeIds)) {
577 throw new API_Exception('Employer name and Employer id Mismatch');
580 // show error if multiple organisation with same name exist
581 if (empty($params['employer_id']) && (count($dupeIds) > 1)) {
582 throw new API_Exception('Found more than one Organisation with same Name.');
586 $params['employer_id'] = $dupeIds[0];
589 $result = civicrm_api3('Contact', 'create', [
590 'organization_name' => $params['current_employer'],
591 'contact_type' => 'Organization',
593 $params['employer_id'] = $result['id'];
601 * Helper function for Contact create.
603 * @param array $params
604 * (reference ) an assoc array of name/value pairs.
605 * @param int $contactID
606 * If present the contact with that ID is updated.
608 * @return CRM_Contact_BAO_Contact|CRM_Core_Error
610 function _civicrm_api3_contact_update($params, $contactID = NULL) {
611 //@todo - doesn't contact create support 'id' which is already set- check & remove
613 $params['contact_id'] = $contactID;
616 return CRM_Contact_BAO_Contact
::create($params);
620 * Validate the addressee or email or postal greetings.
622 * @param array $params
623 * Array per getfields metadata.
625 * @throws API_Exception
627 function _civicrm_api3_greeting_format_params($params) {
628 $greetingParams = ['', '_id', '_custom'];
629 foreach (['email', 'postal', 'addressee'] as $key) {
630 $greeting = '_greeting';
631 if ($key == 'addressee') {
635 $formatParams = FALSE;
636 // Unset display value from params.
637 if (isset($params["{$key}{$greeting}_display"])) {
638 unset($params["{$key}{$greeting}_display"]);
641 // check if greetings are present in present
642 foreach ($greetingParams as $greetingValues) {
643 if (array_key_exists("{$key}{$greeting}{$greetingValues}", $params)) {
644 $formatParams = TRUE;
649 if (!$formatParams) {
655 'greeting_type' => "{$key}{$greeting}",
658 $greetings = CRM_Core_PseudoConstant
::greeting($filter);
659 $greetingId = CRM_Utils_Array
::value("{$key}{$greeting}_id", $params);
660 $greetingVal = CRM_Utils_Array
::value("{$key}{$greeting}", $params);
661 $customGreeting = CRM_Utils_Array
::value("{$key}{$greeting}_custom", $params);
663 if (!$greetingId && $greetingVal) {
664 $params["{$key}{$greeting}_id"] = CRM_Utils_Array
::key($params["{$key}{$greeting}"], $greetings);
667 if ($customGreeting && $greetingId &&
668 ($greetingId != array_search('Customized', $greetings))
670 throw new API_Exception(ts('Provide either %1 greeting id and/or %1 greeting or custom %1 greeting',
675 if ($greetingVal && $greetingId &&
676 ($greetingId != CRM_Utils_Array
::key($greetingVal, $greetings))
678 throw new API_Exception(ts('Mismatch in %1 greeting id and %1 greeting',
684 if (!$customGreeting && ($greetingId == array_search('Customized', $greetings))) {
685 throw new API_Exception(ts('Please provide a custom value for %1 greeting',
690 elseif ($greetingVal) {
692 if (!in_array($greetingVal, $greetings)) {
693 throw new API_Exception(ts('Invalid %1 greeting', [1 => $key]));
696 $greetingId = CRM_Utils_Array
::key($greetingVal, $greetings);
699 if ($customGreeting) {
700 $greetingId = CRM_Utils_Array
::key('Customized', $greetings);
703 $customValue = isset($params['contact_id']) ? CRM_Core_DAO
::getFieldValue(
704 'CRM_Contact_DAO_Contact',
705 $params['contact_id'],
706 "{$key}{$greeting}_custom"
709 if (array_key_exists("{$key}{$greeting}_id", $params) && empty($params["{$key}{$greeting}_id"])) {
712 elseif (array_key_exists("{$key}{$greeting}", $params) && empty($params["{$key}{$greeting}"])) {
715 elseif ($customValue && array_key_exists("{$key}{$greeting}_custom", $params)
716 && empty($params["{$key}{$greeting}_custom"])
721 $params["{$key}{$greeting}_id"] = $greetingId;
723 if (!$customValue && !$customGreeting && array_key_exists("{$key}{$greeting}_custom", $params)) {
724 unset($params["{$key}{$greeting}_custom"]);
728 $params["{$key}{$greeting}_id"] = '';
729 $params["{$key}{$greeting}_custom"] = '';
732 if (isset($params["{$key}{$greeting}"])) {
733 unset($params["{$key}{$greeting}"]);
739 * Adjust Metadata for Get action.
741 * @param array $params
742 * Array of parameters determined by getfields.
744 function _civicrm_api3_contact_getquick_spec(&$params) {
745 $params['name']['api.required'] = TRUE;
746 $params['name']['title'] = ts('String to search on');
747 $params['name']['type'] = CRM_Utils_Type
::T_STRING
;
748 $params['field']['type'] = CRM_Utils_Type
::T_STRING
;
749 $params['field']['title'] = ts('Field to search on');
750 $params['field']['options'] = [
754 'external_identifier',
764 $params['table_name']['type'] = CRM_Utils_Type
::T_STRING
;
765 $params['table_name']['title'] = ts('Table alias to search on');
766 $params['table_name']['api.default'] = 'cc';
770 * Old Contact quick search api.
774 * @param array $params
777 * @throws \API_Exception
779 function civicrm_api3_contact_getquick($params) {
780 $name = CRM_Utils_Type
::escape(CRM_Utils_Array
::value('name', $params), 'String');
781 $table_name = CRM_Utils_String
::munge($params['table_name']);
782 // get the autocomplete options from settings
783 $acpref = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
784 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
785 'contact_autocomplete_options'
791 'phone_numeric' => 'phe',
792 'street_address' => 'sts',
794 'postal_code' => 'sts',
797 // get the option values for contact autocomplete
798 $acOptions = CRM_Core_OptionGroup
::values('contact_autocomplete_options', FALSE, FALSE, FALSE, NULL, 'name');
801 foreach ($acpref as $value) {
802 if ($value && !empty($acOptions[$value])) {
803 $list[$value] = $acOptions[$value];
806 // If we are doing quicksearch by a field other than name, make sure that field is added to results
807 if (!empty($params['field_name'])) {
808 $field_name = CRM_Utils_String
::munge($params['field_name']);
809 // Unique name contact_id = id
810 if ($field_name == 'contact_id') {
813 if (isset($table_names[$field_name])) {
814 $table_name = $table_names[$field_name];
816 elseif (strpos($field_name, 'custom_') === 0) {
817 $customField = civicrm_api3('CustomField', 'getsingle', [
818 'id' => substr($field_name, 7),
820 'custom_group_id.table_name',
827 $field_name = $customField['column_name'];
828 $table_name = CRM_Utils_String
::munge($customField['custom_group_id.table_name']);
829 $from[$field_name] = "LEFT JOIN `$table_name` ON cc.id = `$table_name`.entity_id";
830 if (CRM_Core_BAO_CustomField
::hasOptions($customField)) {
831 $customOptionsWhere = [];
832 $customFieldOptions = CRM_Contact_BAO_Contact
::buildOptions('custom_' . $customField['id'], 'search');
833 $isMultivalueField = CRM_Core_BAO_CustomField
::isSerialized($customField);
834 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
835 foreach ($customFieldOptions as $optionKey => $optionLabel) {
836 if (mb_stripos($optionLabel, $name) !== FALSE) {
837 $customOptionsWhere[$optionKey] = "$table_name.$field_name " . ($isMultivalueField ?
"LIKE '%{$sep}{$optionKey}{$sep}%'" : "= '$optionKey'");
842 // phone_numeric should be phone
843 $searchField = str_replace('_numeric', '', $field_name);
844 if (!in_array($searchField, $list)) {
845 $list[] = $searchField;
849 // Set field name to first name for exact match checking.
850 $field_name = 'sort_name';
853 $select = $actualSelectElements = ['sort_name'];
855 foreach ($list as $value) {
856 $suffix = substr($value, 0, 2) . substr($value, -1);
858 case 'street_address':
861 $selectText = $value;
866 $actualSelectElements[] = $select[] = ($value == 'address') ?
$selectText : $value;
867 if ($value == 'phone') {
868 $actualSelectElements[] = $select[] = 'phone_ext';
870 $from[$value] = "LEFT JOIN civicrm_{$value} {$suffix} ON ( cc.id = {$suffix}.contact_id AND {$suffix}.is_primary = 1 ) ";
874 case 'state_province':
875 $select[] = "{$suffix}.name as {$value}";
876 $actualSelectElements[] = "{$suffix}.name";
877 if (!in_array('address', $from)) {
878 $from['address'] = 'LEFT JOIN civicrm_address sts ON ( cc.id = sts.contact_id AND sts.is_primary = 1) ';
880 $from[$value] = " LEFT JOIN civicrm_{$value} {$suffix} ON ( sts.{$value}_id = {$suffix}.id ) ";
884 if ($value == 'id') {
885 $actualSelectElements[] = 'cc.id';
887 elseif ($value != 'sort_name') {
889 if ($field_name == $value) {
890 $suffix = $table_name;
892 $actualSelectElements[] = $select[] = $suffix . '.' . $value;
898 $config = CRM_Core_Config
::singleton();
900 $select = implode(', ', $select);
901 if (!empty($select)) {
902 $select = ", $select";
904 $actualSelectElements = implode(', ', $actualSelectElements);
905 $from = implode(' ', $from);
906 $limit = (int) CRM_Utils_Array
::value('limit', $params);
907 $limit = $limit > 0 ?
$limit : Civi
::settings()->get('search_autocomplete_count');
909 // add acl clause here
910 list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission
::cacheClause('cc');
913 $where .= " AND $aclWhere ";
915 $isPrependWildcard = \Civi
::settings()->get('includeWildCardInName');
917 if (!empty($params['org'])) {
918 $where .= " AND contact_type = \"Organization\"";
920 // CRM-7157, hack: get current employer details when
921 // employee_id is present.
922 $currEmpDetails = [];
923 if (!empty($params['employee_id'])) {
924 if ($currentEmployer = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
925 (int) $params['employee_id'],
928 if ($isPrependWildcard) {
929 $strSearch = "%$name%";
932 $strSearch = "$name%";
935 // get current employer details
936 $dao = CRM_Core_DAO
::executeQuery("SELECT cc.id as id, CONCAT_WS( ' :: ', {$actualSelectElements} ) as data, sort_name
937 FROM civicrm_contact cc {$from} WHERE cc.contact_type = \"Organization\" AND cc.id = {$currentEmployer} AND cc.sort_name LIKE '$strSearch'");
941 'data' => $dao->data
,
948 if (!empty($params['contact_sub_type'])) {
949 $contactSubType = CRM_Utils_Type
::escape($params['contact_sub_type'], 'String');
950 $where .= " AND cc.contact_sub_type = '{$contactSubType}'";
953 if (!empty($params['contact_type'])) {
954 $contactType = CRM_Utils_Type
::escape($params['contact_type'], 'String');
955 $where .= " AND cc.contact_type LIKE '{$contactType}'";
958 // Set default for current_employer or return contact with particular id
959 if (!empty($params['id'])) {
960 $where .= " AND cc.id = " . (int) $params['id'];
963 if (!empty($params['cid'])) {
964 $where .= " AND cc.id <> " . (int) $params['cid'];
967 // Contact's based of relationhip type
969 if (!empty($params['rel'])) {
970 $relation = explode('_', CRM_Utils_Array
::value('rel', $params));
971 $relType = CRM_Utils_Type
::escape($relation[0], 'Integer');
972 $rel = CRM_Utils_Type
::escape($relation[2], 'String');
975 if ($isPrependWildcard) {
976 $strSearch = "%$name%";
979 $strSearch = "$name%";
981 $includeEmailFrom = $includeNickName = '';
982 if ($config->includeNickNameInName
) {
983 $includeNickName = " OR nick_name LIKE '$strSearch'";
986 if (isset($customOptionsWhere)) {
987 $customOptionsWhere = $customOptionsWhere ?
: [0];
988 $whereClause = " WHERE (" . implode(' OR ', $customOptionsWhere) . ") $where";
990 elseif (!empty($params['field_name']) && !empty($params['table_name']) && $params['field_name'] != 'sort_name') {
991 $whereClause = " WHERE ( $table_name.$field_name LIKE '$strSearch') {$where}";
992 // Search by id should be exact
993 if ($field_name == 'id' ||
$field_name == 'external_identifier') {
994 $whereClause = " WHERE ( $table_name.$field_name = '$name') {$where}";
998 $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} ";
999 if ($config->includeEmailInName
) {
1000 if (!in_array('email', $list)) {
1001 $includeEmailFrom = "LEFT JOIN civicrm_email eml ON ( cc.id = eml.contact_id AND eml.is_primary = 1 )";
1003 $emailWhere = " WHERE email LIKE '$strSearch'";
1007 $additionalFrom = '';
1010 INNER JOIN civicrm_relationship_type r ON (
1012 AND ( cc.contact_type = r.contact_type_{$rel} OR r.contact_type_{$rel} IS NULL )
1013 AND ( cc.contact_sub_type = r.contact_sub_type_{$rel} OR r.contact_sub_type_{$rel} IS NULL )
1017 // check if only CMS users are requested
1018 if (!empty($params['cmsuser'])) {
1020 INNER JOIN civicrm_uf_match um ON (um.contact_id=cc.id)
1023 $orderBy = _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $field_name);
1027 SELECT DISTINCT(id), data, sort_name, exactFirst
1029 ( SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',
1030 {$actualSelectElements} )
1033 FROM civicrm_contact cc {$from}
1041 if (!empty($emailWhere)) {
1044 SELECT IF($table_name.$field_name = '{$name}', 0, 1) as exactFirst, cc.id as id, CONCAT_WS( ' :: ',
1045 {$actualSelectElements} )
1048 FROM civicrm_contact cc {$from}
1050 {$additionalFrom} {$includeEmailFrom}
1051 {$emailWhere} AND cc.is_deleted = 0 " . ($aclWhere ?
" AND $aclWhere " : '') . "
1062 // send query to hook to be modified if needed
1063 CRM_Utils_Hook
::contactListQuery($query,
1065 empty($params['context']) ?
NULL : CRM_Utils_Type
::escape($params['context'], 'String'),
1066 empty($params['id']) ?
NULL : $params['id']
1069 $dao = CRM_Core_DAO
::executeQuery($query);
1072 $listCurrentEmployer = TRUE;
1073 while ($dao->fetch()) {
1074 $t = ['id' => $dao->id
];
1075 foreach ($as as $k) {
1076 $t[$k] = isset($dao->$k) ?
$dao->$k : '';
1078 $t['data'] = $dao->data
;
1079 // Replace keys with values when displaying fields from an option list
1080 if (!empty($customOptionsWhere)) {
1081 $data = explode(' :: ', $dao->data
);
1082 $pos = count($data) - 1;
1083 $customValue = array_intersect(CRM_Utils_Array
::explodePadded($data[$pos]), array_keys($customOptionsWhere));
1084 $data[$pos] = implode(', ', array_intersect_key($customFieldOptions, array_flip($customValue)));
1085 $t['data'] = implode(' :: ', $data);
1087 $contactList[] = $t;
1088 if (!empty($params['org']) &&
1089 !empty($currEmpDetails) &&
1090 $dao->id
== $currEmpDetails['id']
1092 $listCurrentEmployer = FALSE;
1096 //return organization name if doesn't exist in db
1097 if (empty($contactList)) {
1098 if (!empty($params['org'])) {
1099 if ($listCurrentEmployer && !empty($currEmpDetails)) {
1102 'data' => $currEmpDetails['data'],
1103 'id' => $currEmpDetails['id'],
1118 return civicrm_api3_create_success($contactList, $params, 'Contact', 'getquick');
1122 * Get the order by string for the quicksearch query.
1124 * Get the order by string. The string might be
1125 * - sort name if there is no search value provided and the site is configured
1126 * to search by sort name
1127 * - empty if there is no search value provided and the site is not configured
1128 * to search by sort name
1129 * - exactFirst and then sort name if a search value is provided and the site is configured
1130 * to search by sort name
1131 * - exactFirst if a search value is provided and the site is not configured
1132 * to search by sort name
1134 * exactFirst means 'yes if the search value exactly matches the searched field. else no'.
1135 * It is intended to prioritise exact matches for the entered string so on a first name search
1136 * for 'kath' contacts with a first name of exactly Kath rise to the top.
1138 * On short strings it is expensive. Per CRM-19547 there is still an open question
1139 * as to whether we should only do exactMatch on a minimum length or on certain fields.
1141 * However, we have mitigated this somewhat by not doing an exact match search on
1142 * empty strings, non-wildcard sort-name searches and email searches where there is
1143 * no @ after the first character.
1145 * For the user it is further mitigated by the fact they just don't know the
1146 * slower queries are firing. If they type 'smit' slowly enough 4 queries will trigger
1147 * but if the first 3 are slow the first result they see may be off the 4th query.
1149 * @param string $name
1150 * @param bool $isPrependWildcard
1151 * @param string $field_name
1155 function _civicrm_api3_quicksearch_get_order_by($name, $isPrependWildcard, $field_name) {
1156 $skipExactMatch = ($name === '%');
1157 if ($field_name === 'email' && !strpos('@', $name)) {
1158 $skipExactMatch = TRUE;
1161 if (!\Civi
::settings()->get('includeOrderByClause')) {
1162 return $skipExactMatch ?
'' : "ORDER BY exactFirst";
1164 if ($skipExactMatch ||
(!$isPrependWildcard && $field_name === 'sort_name')) {
1165 // If there is no wildcard then sorting by exactFirst would have the same
1166 // effect as just a sort_name search, but slower.
1167 return "ORDER BY sort_name";
1170 return "ORDER BY exactFirst, sort_name";
1174 * Declare deprecated api functions.
1176 * @deprecated api notice
1178 * Array of deprecated actions
1180 function _civicrm_api3_contact_deprecation() {
1181 return ['getquick' => 'The "getquick" action is deprecated in favor of "getlist".'];
1185 * Merges given pair of duplicate contacts.
1187 * @param array $params
1188 * Allowed array keys are:
1189 * -int main_id: main contact id with whom merge has to happen
1190 * -int other_id: duplicate contact which would be deleted after merge operation
1191 * -string mode: "safe" skips the merge if there are no conflicts. Does a force merge otherwise.
1195 * @throws API_Exception
1197 function civicrm_api3_contact_merge($params) {
1198 if (($result = CRM_Dedupe_Merger
::merge(
1199 [['srcID' => $params['to_remove_id'], 'dstID' => $params['to_keep_id']]],
1203 CRM_Utils_Array
::value('check_permissions', $params)
1206 return civicrm_api3_create_success($result, $params);
1208 throw new API_Exception('Merge failed');
1212 * Adjust metadata for contact_merge api function.
1214 * @param array $params
1216 function _civicrm_api3_contact_merge_spec(&$params) {
1217 $params['to_remove_id'] = [
1218 'title' => 'ID of the contact to merge & remove',
1219 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'),
1220 'api.required' => 1,
1221 'type' => CRM_Utils_Type
::T_INT
,
1222 'api.aliases' => ['main_id'],
1224 $params['to_keep_id'] = [
1225 'title' => 'ID of the contact to keep',
1226 'description' => ts('Wow - these 2 params are the logical reverse of what I expect - but what to do?'),
1227 'api.required' => 1,
1228 'type' => CRM_Utils_Type
::T_INT
,
1229 'api.aliases' => ['other_id'],
1232 // @todo need more detail on what this means.
1233 'title' => 'Dedupe mode',
1234 'api.default' => 'safe',
1239 * Get the ultimate contact a contact was merged to.
1241 * @param array $params
1245 * @throws API_Exception
1247 function civicrm_api3_contact_getmergedto($params) {
1248 $contactID = _civicrm_api3_contact_getmergedto($params);
1250 $values = [$contactID => ['id' => $contactID]];
1255 return civicrm_api3_create_success($values, $params);
1259 * Get the contact our contact was finally merged to.
1261 * If the contact has been merged multiple times the crucial parent activity will have
1262 * wound up on the ultimate contact so we can figure out the final resting place of the
1263 * contact with only 2 activities even if 50 merges took place.
1265 * @param array $params
1269 function _civicrm_api3_contact_getmergedto($params) {
1271 $deleteActivity = civicrm_api3('ActivityContact', 'get', [
1272 'contact_id' => $params['contact_id'],
1273 'activity_id.activity_type_id' => 'Contact Deleted By Merge',
1275 'is_test' => $params['is_test'],
1276 'record_type_id' => 'Activity Targets',
1277 'return' => ['activity_id.parent_id'],
1281 'sort' => 'activity_id.activity_date_time DESC',
1284 if (!empty($deleteActivity)) {
1285 $contactID = civicrm_api3('ActivityContact', 'getvalue', [
1286 'activity_id' => $deleteActivity[0]['activity_id.parent_id'],
1287 'record_type_id' => 'Activity Targets',
1288 'return' => 'contact_id',
1295 * Adjust metadata for contact_merge api function.
1297 * @param array $params
1299 function _civicrm_api3_contact_getmergedto_spec(&$params) {
1300 $params['contact_id'] = [
1301 'title' => ts('ID of contact to find ultimate contact for'),
1302 'type' => CRM_Utils_Type
::T_INT
,
1303 'api.required' => TRUE,
1305 $params['is_test'] = [
1306 'title' => ts('Get test deletions rather than live?'),
1307 'type' => CRM_Utils_Type
::T_BOOLEAN
,
1313 * Get the ultimate contact a contact was merged to.
1315 * @param array $params
1319 * @throws API_Exception
1321 function civicrm_api3_contact_getmergedfrom($params) {
1322 $contacts = _civicrm_api3_contact_getmergedfrom($params);
1323 return civicrm_api3_create_success($contacts, $params);
1327 * Get all the contacts merged into our contact.
1329 * @param array $params
1333 function _civicrm_api3_contact_getmergedfrom($params) {
1335 $deleteActivities = civicrm_api3('ActivityContact', 'get', [
1336 'contact_id' => $params['contact_id'],
1337 'activity_id.activity_type_id' => 'Contact Merged',
1339 'is_test' => $params['is_test'],
1340 'record_type_id' => 'Activity Targets',
1341 'return' => 'activity_id',
1344 foreach ($deleteActivities as $deleteActivity) {
1345 $activities[] = $deleteActivity['activity_id'];
1347 if (empty($activities)) {
1351 $activityContacts = civicrm_api3('ActivityContact', 'get', [
1352 'activity_id.parent_id' => ['IN' => $activities],
1353 'record_type_id' => 'Activity Targets',
1354 'return' => 'contact_id',
1357 foreach ($activityContacts as $activityContact) {
1358 $contacts[$activityContact['contact_id']] = ['id' => $activityContact['contact_id']];
1364 * Adjust metadata for contact_merge api function.
1366 * @param array $params
1368 function _civicrm_api3_contact_getmergedfrom_spec(&$params) {
1369 $params['contact_id'] = [
1370 'title' => ts('ID of contact to find ultimate contact for'),
1371 'type' => CRM_Utils_Type
::T_INT
,
1372 'api.required' => TRUE,
1374 $params['is_test'] = [
1375 'title' => ts('Get test deletions rather than live?'),
1376 'type' => CRM_Utils_Type
::T_BOOLEAN
,
1382 * Adjust metadata for contact_proximity api function.
1384 * @param array $params
1386 function _civicrm_api3_contact_proximity_spec(&$params) {
1387 $params['latitude'] = [
1388 'title' => 'Latitude',
1389 'api.required' => 1,
1390 'type' => CRM_Utils_Type
::T_STRING
,
1392 $params['longitude'] = [
1393 'title' => 'Longitude',
1394 'api.required' => 1,
1395 'type' => CRM_Utils_Type
::T_STRING
,
1399 'title' => 'Unit of Measurement',
1400 'api.default' => 'meter',
1401 'type' => CRM_Utils_Type
::T_STRING
,
1406 * Get contacts by proximity.
1408 * @param array $params
1413 function civicrm_api3_contact_proximity($params) {
1414 $latitude = CRM_Utils_Array
::value('latitude', $params);
1415 $longitude = CRM_Utils_Array
::value('longitude', $params);
1416 $distance = CRM_Utils_Array
::value('distance', $params);
1418 $unit = CRM_Utils_Array
::value('unit', $params);
1420 // check and ensure that lat/long and distance are floats
1422 !CRM_Utils_Rule
::numeric($latitude) ||
1423 !CRM_Utils_Rule
::numeric($longitude) ||
1424 !CRM_Utils_Rule
::numeric($distance)
1426 throw new Exception(ts('Latitude, Longitude and Distance should exist and be numeric'));
1429 if ($unit == "mile") {
1430 $conversionFactor = 1609.344;
1433 $conversionFactor = 1000;
1435 //Distance in meters
1436 $distance = $distance * $conversionFactor;
1438 $whereClause = CRM_Contact_BAO_ProximityQuery
::where($latitude, $longitude, $distance);
1441 SELECT civicrm_contact.id as contact_id,
1442 civicrm_contact.display_name as display_name
1443 FROM civicrm_contact
1444 LEFT JOIN civicrm_address ON civicrm_contact.id = civicrm_address.contact_id
1448 $dao = CRM_Core_DAO
::executeQuery($query);
1450 while ($dao->fetch()) {
1451 $contacts[] = $dao->toArray();
1454 return civicrm_api3_create_success($contacts, $params, 'Contact', 'get_by_location', $dao);
1459 * Get parameters for getlist function.
1461 * @see _civicrm_api3_generic_getlist_params
1463 * @param array $request
1465 function _civicrm_api3_contact_getlist_params(&$request) {
1466 // get the autocomplete options from settings
1467 $acpref = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1468 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
1469 'contact_autocomplete_options'
1473 // get the option values for contact autocomplete
1474 $acOptions = CRM_Core_OptionGroup
::values('contact_autocomplete_options', FALSE, FALSE, FALSE, NULL, 'name');
1477 foreach ($acpref as $value) {
1478 if ($value && !empty($acOptions[$value])) {
1479 $list[] = $acOptions[$value];
1482 // If we are doing quicksearch by a field other than name, make sure that field is added to results
1483 $field_name = CRM_Utils_String
::munge($request['search_field']);
1484 // Unique name contact_id = id
1485 if ($field_name == 'contact_id') {
1488 // phone_numeric should be phone
1489 $searchField = str_replace('_numeric', '', $field_name);
1490 if (!in_array($searchField, $list)) {
1491 $list[] = $searchField;
1493 $request['description_field'] = $list;
1494 $list[] = 'contact_type';
1495 $request['params']['return'] = array_unique(array_merge($list, $request['extra']));
1496 $request['params']['options']['sort'] = 'sort_name';
1497 // Contact api doesn't support array(LIKE => 'foo') syntax
1498 if (!empty($request['input'])) {
1499 $request['params'][$request['search_field']] = $request['input'];
1500 // Temporarily override wildcard setting
1501 if (Civi
::settings()->get('includeWildCardInName') != $request['add_wildcard']) {
1502 Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard'] = !$request['add_wildcard'];
1503 Civi
::settings()->set('includeWildCardInName', $request['add_wildcard']);
1509 * Get output for getlist function.
1511 * @see _civicrm_api3_generic_getlist_output
1513 * @param array $result
1514 * @param array $request
1518 function _civicrm_api3_contact_getlist_output($result, $request) {
1520 if (!empty($result['values'])) {
1521 $addressFields = array_intersect([
1527 $request['params']['return']);
1528 foreach ($result['values'] as $row) {
1530 'id' => $row[$request['id_field']],
1531 'label' => $row[$request['label_field']],
1532 'description' => [],
1534 foreach ($request['description_field'] as $item) {
1535 if (!strpos($item, '_name') && !in_array($item, $addressFields) && !empty($row[$item])) {
1536 $data['description'][] = $row[$item];
1540 foreach ($addressFields as $item) {
1541 if (!empty($row[$item])) {
1542 $address[] = $row[$item];
1546 $data['description'][] = implode(' ', $address);
1548 if (!empty($request['image_field'])) {
1549 $data['image'] = isset($row[$request['image_field']]) ?
$row[$request['image_field']] : '';
1552 $data['icon_class'] = $row['contact_type'];
1557 // Restore wildcard override by _civicrm_api3_contact_getlist_params
1558 if (isset(Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard'])) {
1559 Civi
::settings()->set('includeWildCardInName', Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard']);
1560 unset(Civi
::$statics['civicrm_api3_contact_getlist']['override_wildcard']);
1566 * Check for duplicate contacts.
1568 * @param array $params
1569 * Params per getfields metadata.
1572 * API formatted array
1574 function civicrm_api3_contact_duplicatecheck($params) {
1575 $dupes = CRM_Contact_BAO_Contact
::getDuplicateContacts(
1577 $params['match']['contact_type'],
1578 $params['rule_type'],
1579 CRM_Utils_Array
::value('exclude', $params, []),
1580 CRM_Utils_Array
::value('check_permissions', $params),
1581 CRM_Utils_Array
::value('dedupe_rule_id', $params)
1584 if ($dupes && !empty($params['return'])) {
1585 return civicrm_api3('Contact', 'get', [
1586 'return' => $params['return'],
1587 'id' => ['IN' => $dupes],
1588 'options' => CRM_Utils_Array
::value('options', $params),
1589 'sequential' => CRM_Utils_Array
::value('sequential', $params),
1590 'check_permissions' => CRM_Utils_Array
::value('check_permissions', $params),
1593 foreach ($dupes as $dupe) {
1594 $values[$dupe] = ['id' => $dupe];
1596 return civicrm_api3_create_success($values, $params, 'Contact', 'duplicatecheck');
1600 * Declare metadata for contact dedupe function.
1604 function _civicrm_api3_contact_duplicatecheck_spec(&$params) {
1605 $params['dedupe_rule_id'] = [
1606 'title' => 'Dedupe Rule ID (optional)',
1607 'description' => 'This will default to the built in unsupervised rule',
1608 'type' => CRM_Utils_Type
::T_INT
,
1610 $params['rule_type'] = [
1611 'title' => 'Dedupe Rule Type',
1612 'description' => 'If no rule id specified, pass "Unsupervised" or "Supervised"',
1613 'type' => CRM_Utils_Type
::T_STRING
,
1614 'api.default' => 'Unsupervised',
1616 // @todo declare 'match' parameter. We don't have a standard for type = array yet.