0095c6bc065488bb4f03c3f2e5b159c6d8023421
4 Demonstrate retrieving custom field options
6 function contact_getfields_example(){
9 'get_options' => 'custom_1',
15 $result = civicrm_api( 'contact','GetFields',$params );
21 * Function returns array of result expected from previous function
23 function contact_getfields_expectedresult(){
25 $expectedResult = array(
33 'title' => 'Internal Contact ID',
36 'where' => 'civicrm_contact.id',
37 'headerPattern' => '/internal|contact?|id$/i',
39 'api.aliases' => array(
43 'contact_type' => array(
44 'name' => 'contact_type',
46 'title' => 'Contact Type',
50 'where' => 'civicrm_contact.contact_type',
51 'pseudoconstant' => array(
52 'name' => 'contactType',
53 'table' => 'civicrm_location_type',
54 'keyColumn' => 'name',
55 'labelColumn' => 'label',
59 'Individual' => 'Individual',
60 'Household' => 'Household',
61 'Organization' => 'Organization',
64 'contact_sub_type' => array(
65 'name' => 'contact_sub_type',
67 'title' => 'Contact Subtype',
71 'where' => 'civicrm_contact.contact_sub_type',
72 'headerPattern' => '/C(ontact )?(subtype|sub-type|sub type)/i',
75 'do_not_email' => array(
76 'name' => 'do_not_email',
78 'title' => 'Do Not Email',
80 'where' => 'civicrm_contact.do_not_email',
81 'headerPattern' => '/d(o )?(not )?(email)/i',
82 'dataPattern' => '/^\d{1,}$/',
85 'do_not_phone' => array(
86 'name' => 'do_not_phone',
88 'title' => 'Do Not Phone',
90 'where' => 'civicrm_contact.do_not_phone',
91 'headerPattern' => '/d(o )?(not )?(call|phone)/i',
92 'dataPattern' => '/^\d{1,}$/',
95 'do_not_mail' => array(
96 'name' => 'do_not_mail',
98 'title' => 'Do Not Mail',
100 'where' => 'civicrm_contact.do_not_mail',
101 'headerPattern' => '/^(d(o\s)?n(ot\s)?mail)|(\w*)?bulk\s?(\w*)$/i',
102 'dataPattern' => '/^\d{1,}$/',
105 'do_not_sms' => array(
106 'name' => 'do_not_sms',
108 'title' => 'Do Not Sms',
110 'where' => 'civicrm_contact.do_not_sms',
111 'headerPattern' => '/d(o )?(not )?(sms)/i',
112 'dataPattern' => '/^\d{1,}$/',
115 'do_not_trade' => array(
116 'name' => 'do_not_trade',
118 'title' => 'Do Not Trade',
120 'where' => 'civicrm_contact.do_not_trade',
121 'headerPattern' => '/d(o )?(not )?(trade)/i',
122 'dataPattern' => '/^\d{1,}$/',
125 'is_opt_out' => array(
126 'name' => 'is_opt_out',
128 'title' => 'No Bulk Emails (User Opt Out)',
131 'where' => 'civicrm_contact.is_opt_out',
134 'legal_identifier' => array(
135 'name' => 'legal_identifier',
137 'title' => 'Legal Identifier',
141 'where' => 'civicrm_contact.legal_identifier',
142 'headerPattern' => '/legal\s?id/i',
143 'dataPattern' => '/\w+?\d{5,}/',
146 'external_identifier' => array(
147 'name' => 'external_identifier',
149 'title' => 'External Identifier',
153 'where' => 'civicrm_contact.external_identifier',
154 'headerPattern' => '/external\s?id/i',
155 'dataPattern' => '/^\d{11,}$/',
158 'sort_name' => array(
159 'name' => 'sort_name',
161 'title' => 'Sort Name',
165 'where' => 'civicrm_contact.sort_name',
167 'display_name' => array(
168 'name' => 'display_name',
170 'title' => 'Display Name',
174 'where' => 'civicrm_contact.display_name',
176 'nick_name' => array(
177 'name' => 'nick_name',
179 'title' => 'Nick Name',
183 'where' => 'civicrm_contact.nick_name',
184 'headerPattern' => '/n(ick\s)name|nick$/i',
185 'dataPattern' => '/^\w+$/',
188 'legal_name' => array(
189 'name' => 'legal_name',
191 'title' => 'Legal Name',
195 'where' => 'civicrm_contact.legal_name',
196 'headerPattern' => '/^legal|(l(egal\s)?name)$/i',
199 'image_URL' => array(
200 'name' => 'image_URL',
202 'title' => 'Image Url',
206 'where' => 'civicrm_contact.image_URL',
209 'preferred_communication_method' => array(
210 'name' => 'preferred_communication_method',
212 'title' => 'Preferred Communication Method',
216 'where' => 'civicrm_contact.preferred_communication_method',
217 'headerPattern' => '/^p(ref\w*\s)?c(omm\w*)|( meth\w*)$/i',
218 'dataPattern' => '/^\w+$/',
221 'preferred_language' => array(
222 'name' => 'preferred_language',
224 'title' => 'Preferred Language',
228 'where' => 'civicrm_contact.preferred_language',
229 'headerPattern' => '/^lang/i',
232 'preferred_mail_format' => array(
233 'name' => 'preferred_mail_format',
235 'title' => 'Preferred Mail Format',
237 'where' => 'civicrm_contact.preferred_mail_format',
238 'headerPattern' => '/^p(ref\w*\s)?m(ail\s)?f(orm\w*)$/i',
241 'enumValues' => 'Text, HTML, Both',
251 'title' => 'Contact Hash',
255 'where' => 'civicrm_contact.hash',
260 'title' => 'Api Key',
264 'first_name' => array(
265 'name' => 'first_name',
267 'title' => 'First Name',
271 'where' => 'civicrm_contact.first_name',
272 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
273 'dataPattern' => '/^\w+$/',
276 'middle_name' => array(
277 'name' => 'middle_name',
279 'title' => 'Middle Name',
283 'where' => 'civicrm_contact.middle_name',
284 'headerPattern' => '/^middle|(m(iddle\s)?name)$/i',
285 'dataPattern' => '/^\w+$/',
288 'last_name' => array(
289 'name' => 'last_name',
291 'title' => 'Last Name',
295 'where' => 'civicrm_contact.last_name',
296 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
297 'dataPattern' => '/^\w+(\s\w+)?+$/',
300 'prefix_id' => array(
301 'name' => 'prefix_id',
303 'title' => 'Individual Prefix',
304 'pseudoconstant' => array(
305 'name' => 'individualPrefix',
306 'optionGroupName' => 'individualPrefix',
308 'api.aliases' => array(
318 'suffix_id' => array(
319 'name' => 'suffix_id',
321 'title' => 'Individual Suffix',
322 'pseudoconstant' => array(
323 'name' => 'individualSuffix',
324 'optionGroupName' => 'individualSuffix',
326 'api.aliases' => array(
340 'email_greeting_id' => array(
341 'name' => 'email_greeting_id',
343 'title' => 'Email Greeting ID',
345 'email_greeting_custom' => array(
346 'name' => 'email_greeting_custom',
348 'title' => 'Email Greeting Custom',
352 'where' => 'civicrm_contact.email_greeting_custom',
354 'email_greeting_display' => array(
355 'name' => 'email_greeting_display',
357 'title' => 'Email Greeting',
361 'postal_greeting_id' => array(
362 'name' => 'postal_greeting_id',
364 'title' => 'Postal Greeting ID',
366 'postal_greeting_custom' => array(
367 'name' => 'postal_greeting_custom',
369 'title' => 'Postal Greeting Custom',
373 'where' => 'civicrm_contact.postal_greeting_custom',
375 'postal_greeting_display' => array(
376 'name' => 'postal_greeting_display',
378 'title' => 'Postal Greeting',
382 'addressee_id' => array(
383 'name' => 'addressee_id',
385 'title' => 'Addressee ID',
387 'addressee_custom' => array(
388 'name' => 'addressee_custom',
390 'title' => 'Addressee Custom',
394 'where' => 'civicrm_contact.addressee_custom',
396 'addressee_display' => array(
397 'name' => 'addressee_display',
399 'title' => 'Addressee',
403 'job_title' => array(
404 'name' => 'job_title',
406 'title' => 'Job Title',
410 'where' => 'civicrm_contact.job_title',
411 'headerPattern' => '/^job|(j(ob\s)?title)$/i',
412 'dataPattern' => '//',
415 'gender_id' => array(
416 'name' => 'gender_id',
419 'pseudoconstant' => array(
421 'optionGroupName' => 'gender',
423 'api.aliases' => array(
429 '3' => 'Transgender',
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' => 'URRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM',
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' => 'Country',
560 'groupTitle' => 'select_test_g',
561 'data_type' => 'String',
562 'html_type' => 'Select',
564 'options_per_line' => '',
565 'custom_group_id' => '1',
566 'extends' => 'Contact',
567 'is_search_range' => 0,
568 'extends_entity_column_value' => '',
569 'extends_entity_column_id' => '',
572 'option_group_id' => '86',
580 'current_employer' => array(
581 'title' => 'Current Employer',
582 'description' => 'Name of Current Employer',
587 return $expectedResult ;
592 * This example has been generated from the API test suite. The test that created it is called
594 * testCustomFieldCreateWithOptionValues and can be found in
595 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
597 * You can see the outcome of the API tests at
598 * http://tests.dev.civicrm.org/trunk/results-api_v3
600 * To Learn about the API read
601 * http://book.civicrm.org/developer/current/techniques/api/
603 * and review the wiki at
604 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
606 * Read more about testing here
607 * http://wiki.civicrm.org/confluence/display/CRM/Testing
609 * API Standards documentation:
610 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards