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 'table' => 'civicrm_contact_type',
53 'keyColumn' => 'name',
54 'labelColumn' => 'label',
55 'condition' => 'parent_id IS NULL',
59 'contact_sub_type' => array(
60 'name' => 'contact_sub_type',
62 'title' => 'Contact Subtype',
66 'where' => 'civicrm_contact.contact_sub_type',
67 'headerPattern' => '/C(ontact )?(subtype|sub-type|sub type)/i',
69 'pseudoconstant' => array(
70 'table' => 'civicrm_contact_type',
71 'keyColumn' => 'name',
72 'labelColumn' => 'label',
73 'condition' => 'parent_id IS NOT NULL',
76 'do_not_email' => array(
77 'name' => 'do_not_email',
79 'title' => 'Do Not Email',
81 'where' => 'civicrm_contact.do_not_email',
82 'headerPattern' => '/d(o )?(not )?(email)/i',
83 'dataPattern' => '/^\d{1,}$/',
86 'do_not_phone' => array(
87 'name' => 'do_not_phone',
89 'title' => 'Do Not Phone',
91 'where' => 'civicrm_contact.do_not_phone',
92 'headerPattern' => '/d(o )?(not )?(call|phone)/i',
93 'dataPattern' => '/^\d{1,}$/',
96 'do_not_mail' => array(
97 'name' => 'do_not_mail',
99 'title' => 'Do Not Mail',
101 'where' => 'civicrm_contact.do_not_mail',
102 'headerPattern' => '/^(d(o\s)?n(ot\s)?mail)|(\w*)?bulk\s?(\w*)$/i',
103 'dataPattern' => '/^\d{1,}$/',
106 'do_not_sms' => array(
107 'name' => 'do_not_sms',
109 'title' => 'Do Not Sms',
111 'where' => 'civicrm_contact.do_not_sms',
112 'headerPattern' => '/d(o )?(not )?(sms)/i',
113 'dataPattern' => '/^\d{1,}$/',
116 'do_not_trade' => array(
117 'name' => 'do_not_trade',
119 'title' => 'Do Not Trade',
121 'where' => 'civicrm_contact.do_not_trade',
122 'headerPattern' => '/d(o )?(not )?(trade)/i',
123 'dataPattern' => '/^\d{1,}$/',
126 'is_opt_out' => array(
127 'name' => 'is_opt_out',
129 'title' => 'No Bulk Emails (User Opt Out)',
132 'where' => 'civicrm_contact.is_opt_out',
135 'legal_identifier' => array(
136 'name' => 'legal_identifier',
138 'title' => 'Legal Identifier',
142 'where' => 'civicrm_contact.legal_identifier',
143 'headerPattern' => '/legal\s?id/i',
144 'dataPattern' => '/\w+?\d{5,}/',
147 'external_identifier' => array(
148 'name' => 'external_identifier',
150 'title' => 'External Identifier',
154 'where' => 'civicrm_contact.external_identifier',
155 'headerPattern' => '/external\s?id/i',
156 'dataPattern' => '/^\d{11,}$/',
159 'sort_name' => array(
160 'name' => 'sort_name',
162 'title' => 'Sort Name',
166 'where' => 'civicrm_contact.sort_name',
168 'display_name' => array(
169 'name' => 'display_name',
171 'title' => 'Display Name',
175 'where' => 'civicrm_contact.display_name',
177 'nick_name' => array(
178 'name' => 'nick_name',
180 'title' => 'Nickname',
184 'where' => 'civicrm_contact.nick_name',
185 'headerPattern' => '/n(ick\s)name|nick$/i',
186 'dataPattern' => '/^\w+$/',
189 'legal_name' => array(
190 'name' => 'legal_name',
192 'title' => 'Legal Name',
196 'where' => 'civicrm_contact.legal_name',
197 'headerPattern' => '/^legal|(l(egal\s)?name)$/i',
200 'image_URL' => array(
201 'name' => 'image_URL',
203 'title' => 'Image Url',
207 'where' => 'civicrm_contact.image_URL',
210 'preferred_communication_method' => array(
211 'name' => 'preferred_communication_method',
213 'title' => 'Preferred Communication Method',
217 'where' => 'civicrm_contact.preferred_communication_method',
218 'headerPattern' => '/^p(ref\w*\s)?c(omm\w*)|( meth\w*)$/i',
219 'dataPattern' => '/^\w+$/',
221 'pseudoconstant' => array(
222 'optionGroupName' => 'preferred_communication_method',
225 'preferred_language' => array(
226 'name' => 'preferred_language',
228 'title' => 'Preferred Language',
232 'where' => 'civicrm_contact.preferred_language',
233 'headerPattern' => '/^lang/i',
235 'pseudoconstant' => array(
236 'optionGroupName' => 'languages',
237 'keyColumn' => 'name',
240 'preferred_mail_format' => array(
241 'name' => 'preferred_mail_format',
243 'title' => 'Preferred Mail Format',
245 'where' => 'civicrm_contact.preferred_mail_format',
246 'headerPattern' => '/^p(ref\w*\s)?m(ail\s)?f(orm\w*)$/i',
249 'enumValues' => 'Text, HTML, Both',
259 'title' => 'Contact Hash',
263 'where' => 'civicrm_contact.hash',
268 'title' => 'Api Key',
272 'first_name' => array(
273 'name' => 'first_name',
275 'title' => 'First Name',
279 'where' => 'civicrm_contact.first_name',
280 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
281 'dataPattern' => '/^\w+$/',
284 'middle_name' => array(
285 'name' => 'middle_name',
287 'title' => 'Middle Name',
291 'where' => 'civicrm_contact.middle_name',
292 'headerPattern' => '/^middle|(m(iddle\s)?name)$/i',
293 'dataPattern' => '/^\w+$/',
296 'last_name' => array(
297 'name' => 'last_name',
299 'title' => 'Last Name',
303 'where' => 'civicrm_contact.last_name',
304 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
305 'dataPattern' => '/^\w+(\s\w+)?+$/',
308 'prefix_id' => array(
309 'name' => 'prefix_id',
311 'title' => 'Individual Prefix',
313 'where' => 'civicrm_contact.prefix_id',
314 'headerPattern' => '/^(prefix|title)/i',
315 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\.?$/i',
317 'pseudoconstant' => array(
318 'optionGroupName' => 'individual_prefix',
320 'api.aliases' => array(
324 'suffix_id' => array(
325 'name' => 'suffix_id',
327 'title' => 'Individual Suffix',
329 'where' => 'civicrm_contact.suffix_id',
330 'headerPattern' => '/^suffix$/i',
331 'dataPattern' => '/^(sr|jr)\.?|i{2,}$/',
333 'pseudoconstant' => array(
334 'optionGroupName' => 'individual_suffix',
336 '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',
420 'where' => 'civicrm_contact.gender_id',
421 'headerPattern' => '/^gender$/i',
423 'pseudoconstant' => array(
424 'optionGroupName' => 'gender',
426 'api.aliases' => array(
430 'birth_date' => array(
431 'name' => 'birth_date',
433 'title' => 'Birth Date',
435 'where' => 'civicrm_contact.birth_date',
436 'headerPattern' => '/^birth|(b(irth\s)?date)|D(\W*)O(\W*)B(\W*)$/i',
437 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
440 'is_deceased' => array(
441 'name' => 'is_deceased',
443 'title' => 'Is Deceased',
445 'where' => 'civicrm_contact.is_deceased',
446 'headerPattern' => '/i(s\s)?d(eceased)$/i',
449 'deceased_date' => array(
450 'name' => 'deceased_date',
452 'title' => 'Deceased Date',
454 'where' => 'civicrm_contact.deceased_date',
455 'headerPattern' => '/^deceased|(d(eceased\s)?date)$/i',
458 'household_name' => array(
459 'name' => 'household_name',
461 'title' => 'Household Name',
465 'where' => 'civicrm_contact.household_name',
466 'headerPattern' => '/^household|(h(ousehold\s)?name)$/i',
467 'dataPattern' => '/^\w+$/',
470 'primary_contact_id' => array(
471 'name' => 'primary_contact_id',
473 'title' => 'Household Primary Contact ID',
474 'FKClassName' => 'CRM_Contact_DAO_Contact',
476 'organization_name' => array(
477 'name' => 'organization_name',
479 'title' => 'Organization Name',
483 'where' => 'civicrm_contact.organization_name',
484 'headerPattern' => '/^organization|(o(rganization\s)?name)$/i',
485 'dataPattern' => '/^\w+$/',
489 'name' => 'sic_code',
491 'title' => 'Sic Code',
495 'where' => 'civicrm_contact.sic_code',
496 'headerPattern' => '/^sic|(s(ic\s)?code)$/i',
499 'user_unique_id' => array(
500 'name' => 'user_unique_id',
502 'title' => 'Unique ID (OpenID)',
506 'where' => 'civicrm_contact.user_unique_id',
507 'headerPattern' => '/^Open\s?ID|u(niq\w*)?\s?ID/i',
508 'dataPattern' => '/^[\w\/\:\.]+$/',
512 'created_date' => array(
513 'name' => 'created_date',
515 'title' => 'Created Date',
519 'modified_date' => array(
520 'name' => 'modified_date',
522 'title' => 'Modified Date',
524 'default' => 'URRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM',
529 'title' => 'Source of Contact Data',
533 'where' => 'civicrm_contact.source',
534 'headerPattern' => '/(S(ource\s)?o(f\s)?C(ontact\s)?Data)$/i',
536 'uniqueName' => 'contact_source',
538 'employer_id' => array(
539 'name' => 'employer_id',
541 'title' => 'Current Employer ID',
543 'where' => 'civicrm_contact.employer_id',
544 'FKClassName' => 'CRM_Contact_DAO_Contact',
545 'uniqueName' => 'current_employer_id',
547 'is_deleted' => array(
548 'name' => 'is_deleted',
550 'title' => 'Contact is in Trash',
553 'where' => 'civicrm_contact.is_deleted',
554 'uniqueName' => 'contact_is_deleted',
557 'label' => 'Our special field',
558 'groupTitle' => 'select_test_g',
559 'data_type' => 'String',
560 'html_type' => 'Select',
562 'options_per_line' => '',
563 'custom_group_id' => '1',
564 'extends' => 'Contact',
565 'is_search_range' => 0,
566 'extends_entity_column_value' => '',
567 'extends_entity_column_id' => '',
570 'option_group_id' => '97',
578 'current_employer' => array(
579 'title' => 'Current Employer',
580 'description' => 'Name of Current Employer',
582 'dupe_check' => array(
583 'title' => 'Check for Duplicates',
584 'description' => 'Throw error if contact create matches dedupe rule',
589 return $expectedResult ;
594 * This example has been generated from the API test suite. The test that created it is called
596 * testCustomFieldCreateWithOptionValues and can be found in
597 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
599 * You can see the outcome of the API tests at
600 * http://tests.dev.civicrm.org/trunk/results-api_v3
602 * To Learn about the API read
603 * http://book.civicrm.org/developer/current/techniques/api/
605 * and review the wiki at
606 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
608 * Read more about testing here
609 * http://wiki.civicrm.org/confluence/display/CRM/Testing
611 * API Standards documentation:
612 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards