3 * Test Generated example of using contact GetFields API
4 * Demonstrate retrieving metadata with custom field options *
6 function contact_getfields_example(){
9 'get_options' => 'custom_1',
15 $result = civicrm_api3('contact', 'GetFields', $params);
17 catch (CiviCRM_API3_Exception
$e) {
19 $errorMessage = $e->getMessage();
20 $errorCode = $e->getErrorCode();
21 $errorData = $e->getExtraParams();
22 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
29 * Function returns array of result expected from previous function
31 function contact_getfields_expectedresult(){
33 $expectedResult = array(
41 'title' => 'Internal Contact ID',
44 'where' => 'civicrm_contact.id',
45 'headerPattern' => '/internal|contact?|id$/i',
47 'api.aliases' => array(
51 'contact_type' => array(
52 'name' => 'contact_type',
54 'title' => 'Contact Type',
58 'where' => 'civicrm_contact.contact_type',
59 'pseudoconstant' => array(
60 'table' => 'civicrm_contact_type',
61 'keyColumn' => 'name',
62 'labelColumn' => 'label',
63 'condition' => 'parent_id IS NULL',
67 'contact_sub_type' => array(
68 'name' => 'contact_sub_type',
70 'title' => 'Contact Subtype',
74 'where' => 'civicrm_contact.contact_sub_type',
75 'headerPattern' => '/C(ontact )?(subtype|sub-type|sub type)/i',
77 'pseudoconstant' => array(
78 'table' => 'civicrm_contact_type',
79 'keyColumn' => 'name',
80 'labelColumn' => 'label',
81 'condition' => 'parent_id IS NOT NULL',
84 'do_not_email' => array(
85 'name' => 'do_not_email',
87 'title' => 'Do Not Email',
89 'where' => 'civicrm_contact.do_not_email',
90 'headerPattern' => '/d(o )?(not )?(email)/i',
91 'dataPattern' => '/^\\d{1,}$/',
94 'do_not_phone' => array(
95 'name' => 'do_not_phone',
97 'title' => 'Do Not Phone',
99 'where' => 'civicrm_contact.do_not_phone',
100 'headerPattern' => '/d(o )?(not )?(call|phone)/i',
101 'dataPattern' => '/^\\d{1,}$/',
104 'do_not_mail' => array(
105 'name' => 'do_not_mail',
107 'title' => 'Do Not Mail',
109 'where' => 'civicrm_contact.do_not_mail',
110 'headerPattern' => '/^(d(o\\s)?n(ot\\s)?mail)|(\\w*)?bulk\\s?(\\w*)$/i',
111 'dataPattern' => '/^\\d{1,}$/',
114 'do_not_sms' => array(
115 'name' => 'do_not_sms',
117 'title' => 'Do Not Sms',
119 'where' => 'civicrm_contact.do_not_sms',
120 'headerPattern' => '/d(o )?(not )?(sms)/i',
121 'dataPattern' => '/^\\d{1,}$/',
124 'do_not_trade' => array(
125 'name' => 'do_not_trade',
127 'title' => 'Do Not Trade',
129 'where' => 'civicrm_contact.do_not_trade',
130 'headerPattern' => '/d(o )?(not )?(trade)/i',
131 'dataPattern' => '/^\\d{1,}$/',
134 'is_opt_out' => array(
135 'name' => 'is_opt_out',
137 'title' => 'No Bulk Emails (User Opt Out)',
140 'where' => 'civicrm_contact.is_opt_out',
143 'legal_identifier' => array(
144 'name' => 'legal_identifier',
146 'title' => 'Legal Identifier',
150 'where' => 'civicrm_contact.legal_identifier',
151 'headerPattern' => '/legal\\s?id/i',
152 'dataPattern' => '/\\w+?\\d{5,}/',
155 'external_identifier' => array(
156 'name' => 'external_identifier',
158 'title' => 'External Identifier',
162 'where' => 'civicrm_contact.external_identifier',
163 'headerPattern' => '/external\\s?id/i',
164 'dataPattern' => '/^\\d{11,}$/',
167 'sort_name' => array(
168 'name' => 'sort_name',
170 'title' => 'Sort Name',
174 'where' => 'civicrm_contact.sort_name',
176 'display_name' => array(
177 'name' => 'display_name',
179 'title' => 'Display Name',
183 'where' => 'civicrm_contact.display_name',
185 'nick_name' => array(
186 'name' => 'nick_name',
188 'title' => 'Nickname',
192 'where' => 'civicrm_contact.nick_name',
193 'headerPattern' => '/n(ick\\s)name|nick$/i',
194 'dataPattern' => '/^\\w+$/',
197 'legal_name' => array(
198 'name' => 'legal_name',
200 'title' => 'Legal Name',
204 'where' => 'civicrm_contact.legal_name',
205 'headerPattern' => '/^legal|(l(egal\\s)?name)$/i',
208 'image_URL' => array(
209 'name' => 'image_URL',
211 'title' => 'Image Url',
215 'where' => 'civicrm_contact.image_URL',
218 'preferred_communication_method' => array(
219 'name' => 'preferred_communication_method',
221 'title' => 'Preferred Communication Method',
225 'where' => 'civicrm_contact.preferred_communication_method',
226 'headerPattern' => '/^p(ref\\w*\\s)?c(omm\\w*)|( meth\\w*)$/i',
227 'dataPattern' => '/^\\w+$/',
229 'pseudoconstant' => array(
230 'optionGroupName' => 'preferred_communication_method',
233 'preferred_language' => array(
234 'name' => 'preferred_language',
236 'title' => 'Preferred Language',
240 'where' => 'civicrm_contact.preferred_language',
241 'headerPattern' => '/^lang/i',
243 'pseudoconstant' => array(
244 'optionGroupName' => 'languages',
245 'keyColumn' => 'name',
248 'preferred_mail_format' => array(
249 'name' => 'preferred_mail_format',
251 'title' => 'Preferred Mail Format',
253 'where' => 'civicrm_contact.preferred_mail_format',
254 'headerPattern' => '/^p(ref\\w*\\s)?m(ail\\s)?f(orm\\w*)$/i',
257 'enumValues' => 'Text, HTML, Both',
262 'title' => 'Contact Hash',
266 'where' => 'civicrm_contact.hash',
271 'title' => 'Api Key',
275 'first_name' => array(
276 'name' => 'first_name',
278 'title' => 'First Name',
282 'where' => 'civicrm_contact.first_name',
283 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
284 'dataPattern' => '/^\\w+$/',
287 'middle_name' => array(
288 'name' => 'middle_name',
290 'title' => 'Middle Name',
294 'where' => 'civicrm_contact.middle_name',
295 'headerPattern' => '/^middle|(m(iddle\\s)?name)$/i',
296 'dataPattern' => '/^\\w+$/',
299 'last_name' => array(
300 'name' => 'last_name',
302 'title' => 'Last Name',
306 'where' => 'civicrm_contact.last_name',
307 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
308 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
311 'prefix_id' => array(
312 'name' => 'prefix_id',
314 'title' => 'Individual Prefix',
316 'where' => 'civicrm_contact.prefix_id',
317 'headerPattern' => '/^(prefix|title)/i',
318 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\\.?$/i',
320 'pseudoconstant' => array(
321 'optionGroupName' => 'individual_prefix',
323 'api.aliases' => array(
324 '0' => 'individual_prefix',
325 '1' => 'individual_prefix_id',
328 'suffix_id' => array(
329 'name' => 'suffix_id',
331 'title' => 'Individual Suffix',
333 'where' => 'civicrm_contact.suffix_id',
334 'headerPattern' => '/^suffix$/i',
335 'dataPattern' => '/^(sr|jr)\\.?|i{2,}$/',
337 'pseudoconstant' => array(
338 'optionGroupName' => 'individual_suffix',
340 'api.aliases' => array(
341 '0' => 'individual_suffix',
342 '1' => 'individual_suffix_id',
345 'email_greeting_id' => array(
346 'name' => 'email_greeting_id',
348 'title' => 'Email Greeting ID',
350 'email_greeting_custom' => array(
351 'name' => 'email_greeting_custom',
353 'title' => 'Email Greeting Custom',
357 'where' => 'civicrm_contact.email_greeting_custom',
359 'email_greeting_display' => array(
360 'name' => 'email_greeting_display',
362 'title' => 'Email Greeting',
366 'postal_greeting_id' => array(
367 'name' => 'postal_greeting_id',
369 'title' => 'Postal Greeting ID',
371 'postal_greeting_custom' => array(
372 'name' => 'postal_greeting_custom',
374 'title' => 'Postal Greeting Custom',
378 'where' => 'civicrm_contact.postal_greeting_custom',
380 'postal_greeting_display' => array(
381 'name' => 'postal_greeting_display',
383 'title' => 'Postal Greeting',
387 'addressee_id' => array(
388 'name' => 'addressee_id',
390 'title' => 'Addressee ID',
392 'addressee_custom' => array(
393 'name' => 'addressee_custom',
395 'title' => 'Addressee Custom',
399 'where' => 'civicrm_contact.addressee_custom',
401 'addressee_display' => array(
402 'name' => 'addressee_display',
404 'title' => 'Addressee',
408 'job_title' => array(
409 'name' => 'job_title',
411 'title' => 'Job Title',
415 'where' => 'civicrm_contact.job_title',
416 'headerPattern' => '/^job|(j(ob\\s)?title)$/i',
417 'dataPattern' => '//',
420 'gender_id' => array(
421 'name' => 'gender_id',
425 'where' => 'civicrm_contact.gender_id',
426 'headerPattern' => '/^gender$/i',
428 'pseudoconstant' => array(
429 'optionGroupName' => 'gender',
432 'birth_date' => array(
433 'name' => 'birth_date',
435 'title' => 'Birth Date',
437 'where' => 'civicrm_contact.birth_date',
438 'headerPattern' => '/^birth|(b(irth\\s)?date)|D(\\W*)O(\\W*)B(\\W*)$/i',
439 'dataPattern' => '/\\d{4}-?\\d{2}-?\\d{2}/',
442 'is_deceased' => array(
443 'name' => 'is_deceased',
445 'title' => 'Is Deceased',
447 'where' => 'civicrm_contact.is_deceased',
448 'headerPattern' => '/i(s\\s)?d(eceased)$/i',
451 'deceased_date' => array(
452 'name' => 'deceased_date',
454 'title' => 'Deceased Date',
456 'where' => 'civicrm_contact.deceased_date',
457 'headerPattern' => '/^deceased|(d(eceased\\s)?date)$/i',
460 'household_name' => array(
461 'name' => 'household_name',
463 'title' => 'Household Name',
467 'where' => 'civicrm_contact.household_name',
468 'headerPattern' => '/^household|(h(ousehold\\s)?name)$/i',
469 'dataPattern' => '/^\\w+$/',
472 'primary_contact_id' => array(
473 'name' => 'primary_contact_id',
475 'title' => 'Household Primary Contact ID',
476 'FKClassName' => 'CRM_Contact_DAO_Contact',
478 'organization_name' => array(
479 'name' => 'organization_name',
481 'title' => 'Organization Name',
485 'where' => 'civicrm_contact.organization_name',
486 'headerPattern' => '/^organization|(o(rganization\\s)?name)$/i',
487 'dataPattern' => '/^\\w+$/',
491 'name' => 'sic_code',
493 'title' => 'Sic Code',
497 'where' => 'civicrm_contact.sic_code',
498 'headerPattern' => '/^sic|(s(ic\\s)?code)$/i',
501 'user_unique_id' => array(
502 'name' => 'user_unique_id',
504 'title' => 'Unique ID (OpenID)',
508 'where' => 'civicrm_contact.user_unique_id',
509 'headerPattern' => '/^Open\\s?ID|u(niq\\w*)?\\s?ID/i',
510 'dataPattern' => '/^[\\w\\/\\:\\.]+$/',
514 'created_date' => array(
515 'name' => 'created_date',
517 'title' => 'Created Date',
521 'modified_date' => array(
522 'name' => 'modified_date',
524 'title' => 'Modified Date',
526 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
531 'title' => 'Source of Contact Data',
535 'where' => 'civicrm_contact.source',
536 'headerPattern' => '/(S(ource\\s)?o(f\\s)?C(ontact\\s)?Data)$/i',
538 'uniqueName' => 'contact_source',
540 'employer_id' => array(
541 'name' => 'employer_id',
543 'title' => 'Current Employer ID',
545 'where' => 'civicrm_contact.employer_id',
546 'FKClassName' => 'CRM_Contact_DAO_Contact',
547 'uniqueName' => 'current_employer_id',
549 'is_deleted' => array(
550 'name' => 'is_deleted',
552 'title' => 'Contact is in Trash',
555 'where' => 'civicrm_contact.is_deleted',
556 'uniqueName' => 'contact_is_deleted',
559 'label' => 'Our special field',
560 'groupTitle' => 'select_test_g',
561 'data_type' => 'String',
562 'html_type' => 'Select',
563 'default_value' => '',
565 'options_per_line' => '',
566 'custom_group_id' => '1',
567 'extends' => 'Contact',
568 'is_search_range' => 0,
569 'extends_entity_column_value' => '',
570 'extends_entity_column_id' => '',
573 'option_group_id' => '99',
576 'name' => 'custom_1',
583 'current_employer' => array(
584 'title' => 'Current Employer',
585 'description' => 'Name of Current Employer',
588 'dupe_check' => array(
589 'title' => 'Check for Duplicates',
590 'description' => 'Throw error if contact create matches dedupe rule',
595 return $expectedResult;
600 * This example has been generated from the API test suite. The test that created it is called
602 * testCustomFieldCreateWithOptionValues and can be found in
603 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
605 * You can see the outcome of the API tests at
606 * https://test.civicrm.org/job/CiviCRM-master-git/
608 * To Learn about the API read
609 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
611 * Browse the api on your own site with the api explorer
612 * http://MYSITE.ORG/path/to/civicrm/api/explorer
614 * Read more about testing here
615 * http://wiki.civicrm.org/confluence/display/CRM/Testing
617 * API Standards documentation:
618 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards