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 'email_greeting_id' => array(
312 'name' => 'email_greeting_id',
314 'title' => 'Email Greeting ID',
316 'email_greeting_custom' => array(
317 'name' => 'email_greeting_custom',
319 'title' => 'Email Greeting Custom',
323 'where' => 'civicrm_contact.email_greeting_custom',
325 'email_greeting_display' => array(
326 'name' => 'email_greeting_display',
328 'title' => 'Email Greeting',
332 'postal_greeting_id' => array(
333 'name' => 'postal_greeting_id',
335 'title' => 'Postal Greeting ID',
337 'postal_greeting_custom' => array(
338 'name' => 'postal_greeting_custom',
340 'title' => 'Postal Greeting Custom',
344 'where' => 'civicrm_contact.postal_greeting_custom',
346 'postal_greeting_display' => array(
347 'name' => 'postal_greeting_display',
349 'title' => 'Postal Greeting',
353 'addressee_id' => array(
354 'name' => 'addressee_id',
356 'title' => 'Addressee ID',
358 'addressee_custom' => array(
359 'name' => 'addressee_custom',
361 'title' => 'Addressee Custom',
365 'where' => 'civicrm_contact.addressee_custom',
367 'addressee_display' => array(
368 'name' => 'addressee_display',
370 'title' => 'Addressee',
374 'job_title' => array(
375 'name' => 'job_title',
377 'title' => 'Job Title',
381 'where' => 'civicrm_contact.job_title',
382 'headerPattern' => '/^job|(j(ob\s)?title)$/i',
383 'dataPattern' => '//',
386 'gender_id' => array(
387 'name' => 'gender_id',
391 'where' => 'civicrm_contact.gender_id',
392 'headerPattern' => '/^gender$/i',
394 'pseudoconstant' => array(
395 'optionGroupName' => 'gender',
398 'birth_date' => array(
399 'name' => 'birth_date',
401 'title' => 'Birth Date',
403 'where' => 'civicrm_contact.birth_date',
404 'headerPattern' => '/^birth|(b(irth\s)?date)|D(\W*)O(\W*)B(\W*)$/i',
405 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
408 'is_deceased' => array(
409 'name' => 'is_deceased',
411 'title' => 'Is Deceased',
413 'where' => 'civicrm_contact.is_deceased',
414 'headerPattern' => '/i(s\s)?d(eceased)$/i',
417 'deceased_date' => array(
418 'name' => 'deceased_date',
420 'title' => 'Deceased Date',
422 'where' => 'civicrm_contact.deceased_date',
423 'headerPattern' => '/^deceased|(d(eceased\s)?date)$/i',
426 'household_name' => array(
427 'name' => 'household_name',
429 'title' => 'Household Name',
433 'where' => 'civicrm_contact.household_name',
434 'headerPattern' => '/^household|(h(ousehold\s)?name)$/i',
435 'dataPattern' => '/^\w+$/',
438 'primary_contact_id' => array(
439 'name' => 'primary_contact_id',
441 'title' => 'Household Primary Contact ID',
442 'FKClassName' => 'CRM_Contact_DAO_Contact',
444 'organization_name' => array(
445 'name' => 'organization_name',
447 'title' => 'Organization Name',
451 'where' => 'civicrm_contact.organization_name',
452 'headerPattern' => '/^organization|(o(rganization\s)?name)$/i',
453 'dataPattern' => '/^\w+$/',
457 'name' => 'sic_code',
459 'title' => 'Sic Code',
463 'where' => 'civicrm_contact.sic_code',
464 'headerPattern' => '/^sic|(s(ic\s)?code)$/i',
467 'user_unique_id' => array(
468 'name' => 'user_unique_id',
470 'title' => 'Unique ID (OpenID)',
474 'where' => 'civicrm_contact.user_unique_id',
475 'headerPattern' => '/^Open\s?ID|u(niq\w*)?\s?ID/i',
476 'dataPattern' => '/^[\w\/\:\.]+$/',
480 'created_date' => array(
481 'name' => 'created_date',
483 'title' => 'Created Date',
487 'modified_date' => array(
488 'name' => 'modified_date',
490 'title' => 'Modified Date',
492 'default' => 'URRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM',
497 'title' => 'Source of Contact Data',
501 'where' => 'civicrm_contact.source',
502 'headerPattern' => '/(S(ource\s)?o(f\s)?C(ontact\s)?Data)$/i',
504 'uniqueName' => 'contact_source',
506 'prefix_id' => array(
507 'name' => 'prefix_id',
509 'title' => 'Individual Prefix',
511 'where' => 'civicrm_contact.prefix_id',
512 'headerPattern' => '/^(prefix|title)/i',
513 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\.?$/i',
515 'pseudoconstant' => array(
516 'optionGroupName' => 'individual_prefix',
518 'uniqueName' => 'individual_prefix_id',
520 'suffix_id' => array(
521 'name' => 'suffix_id',
523 'title' => 'Individual Suffix',
525 'where' => 'civicrm_contact.suffix_id',
526 'headerPattern' => '/^suffix$/i',
527 'dataPattern' => '/^(sr|jr)\.?|i{2,}$/',
529 'pseudoconstant' => array(
530 'optionGroupName' => 'individual_suffix',
532 'uniqueName' => 'individual_suffix_id',
534 'employer_id' => array(
535 'name' => 'employer_id',
537 'title' => 'Current Employer ID',
539 'where' => 'civicrm_contact.employer_id',
540 'FKClassName' => 'CRM_Contact_DAO_Contact',
541 'uniqueName' => 'current_employer_id',
543 'is_deleted' => array(
544 'name' => 'is_deleted',
546 'title' => 'Contact is in Trash',
549 'where' => 'civicrm_contact.is_deleted',
550 'uniqueName' => 'contact_is_deleted',
553 'label' => 'Our special field',
554 'groupTitle' => 'select_test_g',
555 'data_type' => 'String',
556 'html_type' => 'Select',
558 'options_per_line' => '',
559 'custom_group_id' => '1',
560 'extends' => 'Contact',
561 'is_search_range' => 0,
562 'extends_entity_column_value' => '',
563 'extends_entity_column_id' => '',
566 'option_group_id' => '99',
569 'name' => 'custom_1',
575 'current_employer' => array(
576 'title' => 'Current Employer',
577 'description' => 'Name of Current Employer',
579 'dupe_check' => array(
580 'title' => 'Check for Duplicates',
581 'description' => 'Throw error if contact create matches dedupe rule',
586 return $expectedResult;
591 * This example has been generated from the API test suite. The test that created it is called
593 * testCustomFieldCreateWithOptionValues and can be found in
594 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
596 * You can see the outcome of the API tests at
597 * http://tests.dev.civicrm.org/trunk/results-api_v3
599 * To Learn about the API read
600 * http://book.civicrm.org/developer/current/techniques/api/
602 * and review the wiki at
603 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
605 * Read more about testing here
606 * http://wiki.civicrm.org/confluence/display/CRM/Testing
608 * API Standards documentation:
609 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards